示例#1
0
        /**
         * Creates a new client end of a NetBarrier
         *
         * @param name
         *            The name to resolve with the BNS
         * @param enrolled
         *            The number of locally enrolled processes
         * @return A new NetBarrier client end with the number of enrolled processes
         * @//throws JCSPNetworkException
         *             Thrown if something goes wrong in the underlying architecture
         * @//throws ArgumentException
         *             Thrown if the number of of local enrolled is outside the defined range
         * @//throws InvalidOperationException
         *             Thrown if the connection to the BNS has not been initialised
         */
        public static NetBarrier netBarrier(String name, int enrolled)
        // //throws ArgumentException , InvalidOperationException, JCSPNetworkException
        {
            // Check if the BNS connection is initialised
            if (!BNS.initialised)
            {
                throw new InvalidOperationException("The connection to the BNS has not been initialised");
            }

            // Resolve the location of the barrier
            NetBarrierLocation loc = BNS.service.resolve(name);

            // Return a new NetBarrier
            return(NetBarrierEnd.netBarrier(loc, enrolled));
        }
示例#2
0
        /**
         * Creates a new server end of a NetBarrier with a given index and name
         *
         * @param name
         *            Name to register with the BNS
         * @param index
         *            The index to create the NetBarrier with
         * @param localEnrolled
         *            The number of locally enrolled processes
         * @param netEnrolled
         *            The number of remote enrollments to wait for
         * @return A new NetBarrier
         * @//throws ArgumentException
         *             Thrown if the parameters are outside the defined ranges
         * @//throws InvalidOperationException
         *             Thrown if the connection to the BNS has not been initialised
         */
        public static NetBarrier numberedNetBarrier(String name, int index, int localEnrolled, int netEnrolled)
        ////throws ArgumentException , InvalidOperationException
        {
            // Check if the BNS connection is initialised
            if (!BNS.initialised)
            {
                throw new InvalidOperationException("The connection to the BNS has not been initialised");
            }

            // Create a new NetBarrier
            NetBarrier toReturn = NetBarrierEnd.numberedNetBarrier(index, localEnrolled, netEnrolled);

            // Attempt to register
            if (BNS.service.register(name, toReturn))
            {
                return(toReturn);
            }

            // Registration failed. Destroy and throw exception
            toReturn.destroy();
            throw new ArgumentException("Failed to register " + name + " with the BNS");
        }