static void Main(string[] args) { Console.WriteLine("How many Philosophers?\t"); int philosophers = Int32.Parse(Console.ReadLine()); Any2OneChannel service = Channel.any2one(); One2AnyChannel deliver = Channel.one2any(); One2OneChannel supply = Channel.one2one(); List <IamCSProcess> network = new List <IamCSProcess>(); Philosopher[] philosopherList = new Philosopher[philosophers]; for (int i = 0; i < philosophers; i++) { philosopherList.SetValue(new Philosopher(philosopherId: i, service: service.Out(), deliver: deliver.In()), i); network.Add(philosopherList[i]); } network.Add(new QueuingServery(service: service.In(), deliver: deliver.Out(), supply: supply.In())); network.Add(new Kitchen(supply: supply.Out())); new CSPParallel(network.ToArray()).run(); }
/** * Static factory method for creating a new NetBarrier with a given index * * @param localEnroll * The number of locally enrolled processes * @param remoteEnroll * The number of remote processes to wait for enrolls from * @param barrierIndex * The index to create the barrier with * @return A new NetBarrier * @//throws ArgumentException * Thrown if the any of the arguments are outside the desired ranges. */ internal static NetBarrier create(int localEnroll, int remoteEnroll, int barrierIndex) ////throws ArgumentException { // First, the sanity checks. if (localEnroll < 1) { throw new ArgumentException( "Tried to create a NetBarrier with fewer than one locally enrolled process"); } if (remoteEnroll < 0) { throw new ArgumentException("Tried to create a NetBarrier with negative remote enrollments"); } // Now create the BarrierData structure BarrierData data = new BarrierData(); // Set state to OK_SERVER data.state = BarrierDataState.OK_SERVER; // Create the connecting channel Any2OneChannel chan = Channel.any2one(new InfiniteBuffer()); // Add the output end to the structure data.toBarrier = chan.Out(); // Initialise the structure with the BarrierManager, using the given index BarrierManager.getInstance().create(barrierIndex, data); // Return a new NetBarrier return(new NetBarrier(data, localEnroll, remoteEnroll, null, chan.In(), null)); }
/** * Returns a <code>SharedConnectionServer</code> object for this * connection. This method can be called multiple times to return a new * <code>SharedConnectionServer</code> object each time. Any object * created can only be used by one process at a time but the set of * objects constructed can be used concurrently. * * @return a new <code>SharedConnectionServer</code> object. */ public SharedConnectionServer server() { return(new SharedConnectionServerImpl( chanToServer.In(), chanToServer.In(), chanServerSynch.In(), chanServerSynch.Out(), this)); }
/** * Returns the <code>AltingConnectionClient</code> that can * be used by a single process at any instance. * * @return the <code>AltingConnectionClient</code> object. */ public SharedAltingConnectionClient client() { return(new SharedAltingConnectionClient(chanFromServer.In(), chanSynch.In(), chanToServer.Out(), chanToServer.Out(), chanSynch.Out(), chanFromServer.Out(), this)); }
static NetAltingConnectionServer create(NetworkMessageFilter.FilterRx filterRX, NetworkMessageFilter.FilterTx filterTX) { ConnectionData data = new ConnectionData(); Any2OneChannel requestChan = Channel.any2one(new InfiniteBuffer()); Any2OneChannel openChan = Channel.any2one(new InfiniteBuffer()); data.toConnection = requestChan.Out(); data.openServer = openChan.Out(); data.state = ConnectionDataState.SERVER_STATE_CLOSED; ConnectionManager.getInstance().create(data); return(new NetAltingConnectionServer(openChan.In(), requestChan.In(), data, filterRX, filterTX)); }
static NetAltingConnectionClient create(NetConnectionLocation loc, NetworkMessageFilter.FilterTx filterTX, NetworkMessageFilter.FilterRx filterRX) ////throws JCSPNetworkException { // Create the connection data structure ConnectionData data = new ConnectionData(); // Create channel linking this to the Link level. This channel is used to receive response and // acknowledgement messages Any2OneChannel chan = Channel.any2one(new InfiniteBuffer()); data.toConnection = chan.Out(); // Set state of connection data.state = ConnectionDataState.CLIENT_STATE_CLOSED; ConnectionManager.getInstance().create(data); ChannelOutput toLink; if (loc.getNodeID().equals(Node.getInstance().getNodeID())) { toLink = ConnectionManager.getInstance().getConnection(loc.getVConnN()).toConnection; return(new NetAltingConnectionClient(chan.In(), toLink, null, data, loc, filterTX, filterRX)); } Link link = LinkManager.getInstance().requestLink(loc.getNodeID()); if (link == null) { link = LinkFactory.getLink(loc.getNodeID()); } toLink = link.getTxChannel(); return(new NetAltingConnectionClient(chan.In(), toLink, link, data, loc, filterTX, filterRX)); }
public void run() { Any2OneChannel console = Channel.any2one(); Clock clock = new Clock(toConsole: console.Out()); QueuingCanteen servery = new QueuingCanteen(service: service, deliver: deliver, supply: supply, toConsole: console.Out()); GConsole serveryConsole = new GConsole(toConsole: console.In(), frameLabel: "Clocked Queuing Servery"); IamCSProcess[] network = { servery, serveryConsole, clock }; new CSPParallel(network).run(); }
/** * Static factory method used to create a new Net2OneChannel. Used internally within the architecture. * * @param poisonImmunity * The immunity level of the channel * @param filter * The filter on the channel used to convert read bytes into an object * @return A new Net2OneChannel */ public static Net2OneChannel create(int poisonImmunity, NetworkMessageFilter.FilterRx filter) { // Create a new ChannelData object ChannelData data = new ChannelData(); // Create a new infinitely buffered any2one channel connecting the Links to the channel object Any2OneChannel chan = Channel.any2one(new InfiniteBuffer()); // Add the output end to the ChannelData object data.toChannel = chan.Out(); // Set the immunity level data.immunityLevel = poisonImmunity; // Initialise the ChannelData object with the ChannelManager ChannelManager.getInstance().create(data); // Return a new Net2OneChannel return(new Net2OneChannel(chan.In(), data, filter)); }
static void Main(string[] args) { int n_philosophers = 5; Any2OneChannel service = Channel.any2one(); One2OneChannel deliver = Channel.one2one(); One2OneChannel supply = Channel.one2one(); Philosopher[] philosopher = new Philosopher[n_philosophers]; for (int i = 0; i < n_philosophers; i++) { philosopher[i] = new Philosopher(i, service.Out(), deliver.In()); } IamCSProcess[] network = { new Clock(), new Canteen(service.In(),supply.In(), deliver.Out()), new Chef(supply.Out()), new CSPParallel(philosopher) }; new CSPParallel(network).run(); }
/** * Static factory method for creating a client end of a NetBarrier * * @param loc * The location of the server end of the connection * @param localEnroll * The number of locally enrolled processes * @return A new NetBarrier client end * @//throws JCSPNetworkException * Thrown if something goes wrong in the underlying architecture * @//throws ArgumentException * Thrown if local enrolled is less than 1 */ internal static NetBarrier create(NetBarrierLocation loc, int localEnroll) ////throws JCSPNetworkException, ArgumentException { // First, the sanity check. if (localEnroll < 1) { throw new ArgumentException( "Tried to create a NetBarrier with fewer than one locally enrolled process"); } // Next, create the BarrierData structure BarrierData data = new BarrierData(); // Set the state to OK_CLIENT data.state = BarrierDataState.OK_CLIENT; // Create the connecting channel between this object and the Links Any2OneChannel chan = Channel.any2one(new InfiniteBuffer()); // Attach the output end to the structure data.toBarrier = chan.Out(); // Initialise the barrier with the BarrierManager BarrierManager.getInstance().create(data); // Now check if this is a locally connected barrier if (loc.getNodeID().equals(Node.getInstance().getNodeID())) { // We are locally connected, so create a new NetBarrier. The constructor will connect to the Barrier server // end for us. return(new NetBarrier(data, localEnroll, 0, loc, chan.In(), null)); } // We are not locally connected. Continue. // This is the channel we will pass to the NetBarrier ChannelOutput toLink; // First, check if the LinkManager has a connection for us. Link link = LinkManager.getInstance().requestLink(loc.getNodeID()); // The previous operation returns null if no connection exists. if (link == null) { // No connection to the Link exists. Use the factory to get one. link = LinkFactory.getLink(loc.getNodeID()); // The LinkFactory will have created and started the Link for us, if it could connect. We can continue } // Retrieve the channel connecting to the TX process toLink = link.getTxChannel(); // We now need to enroll with the server end. Send the enroll message NetworkMessage msg = new NetworkMessage(); msg.type = NetworkProtocol.ENROLL; // Destination is the VBN of the location msg.attr1 = loc.getVBN(); // Attribute 2 is not used msg.attr2 = -1; // Write the message to the Link toLink.write(msg); // Register with the Link link.registerBarrier(data); // Return a new NetBarrier return(new NetBarrier(data, localEnroll, 0, loc, chan.In(), toLink)); }
static void Main(string[] args) { // synchronisation components AltingBarrier[] stable = AltingBarrier.create(10); var elfGroups = Bucket.create(4); // Santa to Vestibule Channels One2OneChannel openForBusiness = Channel.createOne2One(); One2OneChannel consultationOver = Channel.createOne2One(); //reindeer channels Any2OneChannel harness = Channel.createAny2One(); One2AnyChannel harnessed = Channel.createOne2Any(); One2AnyChannel returned = Channel.createOne2Any(); One2OneChannel[] unharness = Channel.createOne2One(9); ChannelOutputList unharnessList = new ChannelOutputList(unharness); // elf channels, including Vestibule channels Any2OneChannel needToConsult = Channel.createAny2One(); One2AnyChannel joinGroup = Channel.createOne2Any(); Any2OneChannel consult = Channel.createAny2One(); Any2OneChannel negotiating = Channel.createAny2One(); One2OneChannel[] consulting = Channel.createOne2One(10); One2OneChannel[] consulted = Channel.createOne2One(10); ChannelOutputList consultingList = new ChannelOutputList(consulting); ChannelOutputList consultedList = new ChannelOutputList(consulted); List <IamCSProcess> grottoList = new List <IamCSProcess>(); Reindeer[] herd = new Reindeer[9]; for (int i = 0; i < 9; i++) { herd[i] = new Reindeer(number: i, stable: stable[i], harness: harness.Out(), harnessed: harnessed.In(), returned: returned.In(), unharness: unharness[i].In(), holidayTime: 15000 ); grottoList.Add(herd[i]); } Elf[] elves = new Elf[9]; IamCSProcess[] elvesNetwork = new IamCSProcess[8]; for (int i = 0; i < 9; i++) { elves[i] = new Elf(number: i, groups: elfGroups, needToConsult: needToConsult.Out(), joinGroup: joinGroup.In(), consult: consult.Out(), consulting: consulting[i].In(), negotiating: negotiating.Out(), consulted: consulted[i].In(), workingTime: 1000 ); grottoList.Add(elves[i]); } Santa santa = new Santa(openForBusiness: openForBusiness.Out(), consultationOver: consultationOver.Out(), harness: harness.In(), harnessed: harnessed.Out(), returned: returned.Out(), unharnessList: unharnessList, stable: stable[9], consult: consult.In(), consulting: consultingList, negotiating: negotiating.In(), consulted: consultedList, deliveryTime: 1000, consultationTime: 1000 ); Vestibule vestibule = new Vestibule(groups: elfGroups, needToConsult: needToConsult.In(), joinGroup: joinGroup.Out(), openForBusiness: openForBusiness.In(), consultationOver: consultationOver.In() ); grottoList.Add(santa); grottoList.Add(vestibule); IamCSProcess[] grotto = grottoList.ToArray(); new CSPParallel(grotto).run(); }
/** * Constructs a new filtered channel over the top of an existing channel. */ public FilteredAny2OneChannelImpl(Any2OneChannel chan) { _In = new FilteredAltingChannelInput(chan.In()); _Out = new FilteredSharedChannelOutputWrapper(chan.Out()); }