示例#1
0
        /**
         * Creates a new client end of a NetBarrier connected to the barrier with the given index on the given Node
         *
         * @param addr
         *            NodeAddres of the Node that the barrier is located
         * @param vbn
         *            Index of the barrier to connect to
         * @param enrolled
         *            The number of locally enrolled processes
         * @return A new client end of a NetBarrier
         * @//throws JCSPNetworkException
         *             Thrown if something goes wrong in the underlying architecture
         * @//throws ArgumentException
         *             Thrown if the number of enrolled processes is outside the defined range.
         */
        public static NetBarrier netBarrier(NodeAddress addr, int vbn, int enrolled)
        {
            // Get the Link with the given address
            Link link = LinkFactory.getLink(addr);

            NetBarrier barrierToReturn = null;

            try
            {
                barrierToReturn = NetBarrier.create(new NetBarrierLocation(link.remoteID, vbn), enrolled);
            }
            catch (ArgumentException e)
            {
                Console.WriteLine(e);
            }
            catch (JCSPNetworkException e)
            {
                Console.WriteLine(e);
            }

            return(barrierToReturn);


            // Create a new NetBarrier
            //return NetBarrier.create(new NetBarrierLocation(link.remoteID, vbn), enrolled);
        }
示例#2
0
        /**
         * Creates a new NetSharedChannelOutput connected to the channel with the given vcn on the given Node which uses the
         * given filter to encode outgoing messages
         *
         * @param nodeAddr
         *            The NodeAddress of the Node to connect to
         * @param vcn
         *            The Virtual Channel Number of the input channel
         * @param filter
         *            The immunity to poison that the channel has
         * @return A new NetSharedChannelOutput
         * @//throws JCSPNetworkException
         *             Thrown if something goes wrong in the underlying architecture
         */
        public NetSharedChannelOutput any2net(NodeAddress nodeAddr, int vcn, NetworkMessageFilter.FilterTx filter)
        //throws JCSPNetworkException
        {
            NodeID             remoteNode = LinkFactory.getLink(nodeAddr).remoteID;
            NetChannelLocation loc        = new NetChannelLocation(remoteNode, vcn);

            return(Any2NetChannel.create(loc, Int32.MaxValue, filter));
        }
示例#3
0
        /**
         * Creates a new NetChannelOutput connected to the channel with the given vcn on the given Node
         *
         * @param nodeAddr
         *            The NodeAddress of the Node to connect to
         * @param vcn
         *            The Virtual Channel Number of the input channel
         * @return A new NetChannelOutput
         * @//throws JCSPNetworkException
         *             Thrown if something goes wrong in the underlying architecture
         */
        public NetChannelOutput one2net(NodeAddress nodeAddr, int vcn)
        //throws JCSPNetworkException
        {
            NodeID             remoteNode = LinkFactory.getLink(nodeAddr).remoteID;
            NetChannelLocation loc        = new NetChannelLocation(remoteNode, vcn);

            return(One2NetChannel.create(loc, Int32.MaxValue, new ObjectNetworkMessageFilter.FilterTX()));
        }
示例#4
0
        /**
         * Creates a new NetSharedChannelOutput connected to the channel with the given vcn on the given Node which has the
         * given poison immunity
         *
         * @param nodeAddr
         *            The NodeAddress of the Node to connect to
         * @param vcn
         *            The Virtual Channel Number of the input channel
         * @param immunityLevel
         *            The immunity to poison that the channel has
         * @return A new NetSharedChannelOutput
         * @//throws JCSPNetworkException
         *             Thrown if something goes wrong in the underlying architecture
         */
        public NetSharedChannelOutput any2net(NodeAddress nodeAddr, int vcn, int immunityLevel)
        //throws JCSPNetworkException
        {
            NodeID             remoteNode = LinkFactory.getLink(nodeAddr).remoteID;
            NetChannelLocation loc        = new NetChannelLocation(remoteNode, vcn);

            return(Any2NetChannel.create(loc, immunityLevel, new ObjectNetworkMessageFilter.FilterTX()));
        }
示例#5
0
        /**
         * Creates a new NetChannelOutput connected to the channel with the given vcn on the given Node which has the given
         * poison immunity and uses the given filter to encode outgoing messages
         *
         * @param nodeAddr
         *            The NodeAddress of the Node to connect to
         * @param vcn
         *            The Virtual Channel Number of the input channel
         * @param immunityLevel
         *            The immunity to poison that the channel has
         * @param filter
         *            The filter used to encode outgoing messages
         * @return A new NetChannelOutput
         * @//throws JCSPNetworkException
         *             Thrown if something goes wrong in the underlying architecture
         */
        public NetChannelOutput one2net(NodeAddress nodeAddr, int vcn, int immunityLevel,
                                        NetworkMessageFilter.FilterTx filter)
        //throws JCSPNetworkException
        {
            NodeID             remoteNode = LinkFactory.getLink(nodeAddr).remoteID;
            NetChannelLocation loc        = new NetChannelLocation(remoteNode, vcn);

            return(One2NetChannel.create(loc, immunityLevel, filter));
        }
示例#6
0
        /**
         * Creates a new One2NetChannel by connecting to an already created NetChannelInput
         *
         * @param loc
         *            The location of the NetChannelInput
         * @param immunity
         *            The immunity level of the channel
         * @param filter
         *            The filter used to encode outgoing messages
         * @return A new One2NetChannel
         * @//throws JCSPNetworkException
         *             Thrown if the connection to the remote Node fails
         */
        internal static One2NetChannel create(NetChannelLocation loc, int immunity,
                                              NetworkMessageFilter.FilterTx filter)
        ////throws JCSPNetworkException
        {
            // Create the channel data structure
            ChannelData data = new ChannelData();

            // Create the channel linking this to the Link level. This channel is the one used to receive acknowledgement
            // messages
            One2OneChannel chan = Channel.one2one(new InfiniteBuffer());

            data.toChannel = chan.Out();

            // Set state of channel
            data.state = ChannelDataState.OK_OUTPUT;

            // Register channel
            ChannelManager.getInstance().create(data);

            // We now need to create the connection to the input end of the channel
            ChannelOutput toLink;

            // Check if this is a local link, and if so connect directly to the input channel
            if (loc.getNodeID().equals(Node.getInstance().getNodeID()))
            {
                toLink = ChannelManager.getInstance().getChannel(loc.getVCN()).toChannel;
                return(new One2NetChannel(chan.In(), toLink, null, data, loc, immunity, filter));
            }

            // Connect to remote node if necessary
            Link link = LinkManager.getInstance().requestLink(loc.getNodeID());

            // Check if an existing connection exists
            if (link == null)
            {
                // We are not connected. Connect to remote Node.
                link = LinkFactory.getLink(loc.getNodeID());
            }

            // Get the connection to the Link.
            toLink = link.getTxChannel();

            // Return new channel
            return(new One2NetChannel(chan.In(), toLink, link, data, loc, immunity, filter));
        }
示例#7
0
        /**
         * @param factory
         * @return NodeKey for this Node
         * @//throws JCSPNetworkException
         */
        public NodeKey init(NodeFactory factory)
        ////throws JCSPNetworkException
        {
            Node.log.log(this.GetType(), "Node initialisation begun");
            if (this.initialized)
            {
                throw new JCSPNetworkException("Node already initialised");
            }
            NodeAddress localAddr = factory.initNode(this);

            this.nodeID      = new NodeID("", localAddr);
            this.initialized = true;
            this.nk          = new NodeKey();
            Link toServer = LinkFactory.getLink(factory.cnsAddress);

            CNS.CNS.initialise(toServer.remoteID);
            BNS.BNS.initialise(toServer.remoteID);
            return(this.nk);
        }
示例#8
0
        /**
         * Initialises the connection to the BNS
         *
         * @param bnsNode
         *            The NodeAddress of the BNS Node
         * @//throws JCSPNetworkException
         *             Thrown if something goes wrong in the underlying architecture
         */
        public static void initialise(NodeAddress bnsNode)
        ////throws JCSPNetworkException
        {
            // First check that we are not already initialised
            if (BNS.initialised)
            {
                throw new JCSPNetworkException("The BNS is already initialised");
            }

            // We are initialised. Attempt to do so.
            // First, we need to connect to the BNS Node
            Link link = LinkFactory.getLink(bnsNode);

            // Now create the BNSService
            BNS.service = new BNSService(link.getRemoteNodeID());

            // Now set initialised to true
            BNS.initialised = true;

            // We are now connected
        }
示例#9
0
        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));
        }
示例#10
0
        /**
         * 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));
        }