コード例 #1
0
ファイル: BNSService.cs プロジェクト: PasierbKarol/CSPsharp
 /**
  * Registers a Server end of a NetBarrier with the BNS
  *
  * @param name
  *            Name to register with BNS
  * @param bar
  *            Barrier to register
  * @return True if the name was registered successfully, false otherwise
  */
 public Boolean register(String name, NetBarrier bar)
 {
     // Ensure only one registration can happen at a time
     lock (this)
     {
         // Create a new registration message
         BNSMessage message = new BNSMessage();
         message.type            = BNSMessageProtocol.REGISTER_REQUEST;
         message.name            = name;
         message.serviceLocation = (NetChannelLocation)this.fromBNS.getLocation();
         message.location        = (NetBarrierLocation)bar.getLocation();
         // Write registration message to the BNS
         this.toBNS.write(message);
         // Read in reply
         BNSMessage reply = (BNSMessage)this.fromBNS.read();
         return(reply.success);
     }
 }
コード例 #2
0
ファイル: BNS.cs プロジェクト: PasierbKarol/CSPsharp
        /**
         * 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");
        }