예제 #1
0
        /**
         * Private constructor for creating a One2NetChannel. This is called by the create method.
         *
         * @param ackChannel
         *            The channel used to receive acknowledgements from Links
         * @param toLink
         *            The channel used to send messages to the input end
         * @param link
         *            The Link that this channel is connected to
         * @param chanData
         *            The structure used to store the state of the channel
         * @param loc
         *            The location of the input end that this channel is connected to
         * @param immunity
         *            The poison immunity level of the channel
         * @param filter
         *            Filter used to encode outgoing messages
         */
        private One2NetChannel(AltingChannelInput ackChannel, ChannelOutput toLink, Link link, ChannelData chanData,
                               NetChannelLocation loc, int immunity, NetworkMessageFilter.FilterTx filter)
        {
            // Set all the object properties for the channel
            this.toLinkTx           = toLink;
            this.theAckChannel      = ackChannel;
            this.data               = chanData;
            this.remoteLocation     = loc;
            this.localLocation      = new NetChannelLocation(Node.getInstance().getNodeID(), chanData.vcn);
            this.data.immunityLevel = immunity;
            this.messageFilter      = filter;

            // We now must either register with the Link connecting us to the input end, or we connect directly to the
            // channel if it is local
            if (link != null)
            {
                // We are connected to a remote Node. Register with Link
                this.linkConnectedTo = link;
                this.linkConnectedTo.registerChannel(this.data);

                // Set the localised parameters accordingly
                this.isLocal      = false;
                this.localChannel = null;
            }
            else
            {
                // We are connected to an input end on this Node. Set the localised parameters
                this.isLocal = true;
                // Get hold of the local channel data structure
                this.localChannel = ChannelManager.getInstance().getChannel(this.remoteLocation.getVCN());

                // Set the Link connected to to null
                this.linkConnectedTo = null;
            }
        }
예제 #2
0
        /**
         * Private constructor for creating a new instance of a Net2OneChannel. This is called by the create method to
         * create the channel.
         *
         * @param input
         *            The input channel connecting to the networked channel.
         * @param chanData
         *            The ChannelData object representing the networked channel.
         * @param filter
         *            The filter used to convert the incoming byte array to an object
         * @//throws JCSPNetworkException
         */
        private Net2OneChannel(AltingChannelInput input, ChannelData chanData, NetworkMessageFilter.FilterRx filter) :
            base(input)
            //throws JCSPNetworkException
        {
            // Set the wrapper's alting channel input so the channel can be used as a guard

            // Set the various properties
            this.In            = input;
            this.data          = chanData;
            this.data.state    = ChannelDataState.OK_INPUT;
            this.location      = new NetChannelLocation(Node.getInstance().getNodeID(), this.data.vcn);
            this.messageFilter = filter;
        }
예제 #3
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));
        }
예제 #4
0
    /**
     * Stores a channel in the given index in the table.
     * 
     * @param idx
     *            The index to use for the channel
     * @param cd
     *            The ChannelData for the channel
     * @//throws ArgumentException 
     *             If a channel of the given index already exists.
     */
    /*synchronized*/ internal void create(int idx, ChannelData cd)
        //throws ArgumentException 
    {
        // First check that a channel of the given index does not exist. If it does, throw an exception
        int objIndex = idx;
        if (this.channels[objIndex] != null)
            throw new ArgumentException ("Channel of given number already exists.");

        // Set the index of the channel data
        cd.vcn = idx;

        // Now add the channel to the channels table
        this.channels.Add(objIndex, cd);

        // Update the index if necessary
        if (idx == ChannelManager.index)
            ChannelManager.index++;
    }
예제 #5
0
    /**
     * Allocates a new number to the channel, and stores it in the table.
     * 
     * @param cd
     *            The ChannelData for the channel
     */
    /*synchronized*/ internal void create(ChannelData cd)
    {
        // First allocate a new number for the channel
        int objIndex = index;
        while (this.channels[objIndex] != null)
        {
            //objIndex = new Integer(++index);
            ++index;
        }

        // Set the index of the ChannelData
        cd.vcn = index;

        // Now put the channel in the channel Hashtable
        this.channels.Add(objIndex, cd);

        // Finally increment the index for the next channel to be created
        index++;
    }
예제 #6
0
        /**
         * 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));
        }
예제 #7
0
 /**
  * Removes a channel from the table.
  * 
  * @param data
  *            ChannelData for channel to remove
  */
 internal void removeChannel(ChannelData data)
 {
     int objIndex = data.vcn;
     this.channels.Remove(objIndex);
 }