1
//////////////////////////////////////////////////////////////////////
3
// JCSP ("CSP for Java") Libraries //
4
// Copyright (C) 1996-2008 Peter Welch and Paul Austin. //
5
// 2001-2004 Quickstone Technologies Limited. //
7
// This library is free software; you can redistribute it and/or //
8
// modify it under the terms of the GNU Lesser General Public //
9
// License as published by the Free Software Foundation; either //
10
// version 2.1 of the License, or (at your option) any later //
13
// This library is distributed in the hope that it will be //
14
// useful, but WITHOUT ANY WARRANTY; without even the implied //
15
// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR //
16
// PURPOSE. See the GNU Lesser General Public License for more //
19
// You should have received a copy of the GNU Lesser General //
20
// Public License along with this library; if not, write to the //
21
// Free Software Foundation, Inc., 59 Temple Place, Suite 330, //
22
// Boston, MA 02111-1307, USA. //
24
// Author contact: P.H.Welch@kent.ac.uk //
27
//////////////////////////////////////////////////////////////////////
30
import org.jcsp.lang.*;
31
import org.jcsp.demos.util.*;
36
public class BucketExample1 {
38
public static final String TITLE = "Bucket Example 1";
39
public static final String DESCR =
40
"Shows the use of a single bucket to control a group of worker processes. A worker process will take " +
41
"action for some time and then fall into the bucket. Another process will periodically flush the " +
42
"bucket, setting any workers in it working again. Such a system can be used to simulate actions which " +
43
"must start on a clock cycle (ie when the bucket is flushed). An individual action from a worker may " +
44
"take any length of time but the next action will not start until the next clock cycle.";
46
public static void main (String[] args) {
48
Ask.app (TITLE, DESCR);
52
final int nWorkers = 10;
54
final int second = 1000; // JCSP timer units are milliseconds
55
final int interval = 5*second;
56
final int maxWork = 10*second;
58
final long seed = new CSTimer ().read ();
60
final Bucket bucket = new Bucket ();
62
final Flusher flusher = new Flusher (interval, bucket);
64
final Worker[] workers = new Worker[nWorkers];
65
for (int i = 0; i < workers.length; i++) {
66
workers[i] = new Worker (i, i + seed, maxWork, bucket);
69
System.out.println ("*** Flusher: interval = " + interval + " milliseconds");
74
new Parallel (workers)