Class BNS

  • All Implemented Interfaces:
    CSProcess

    public class BNS
    extends java.lang.Object
    implements CSProcess
    This is the main process for the Barrier Name Server. For a more in depth discussion of name servers, see CNS.
    See Also:
    CNS, BNSService, Node
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.HashMap barrierRegister
      Map of barriers registered to a Node; NodeID->
      private static boolean initialised
      Flag used to denote if the connection to the BNS has been initialised
      private static BNS instance
      Singleton instance of the BNS.
      private java.util.HashMap loggedClients
      Map of currently logged clients; NodeID->reply-channel
      private AltingChannelInput lostLink
      A channel used to receive incoming link lost notifications
      private java.util.HashMap registeredBarriers
      Map of registered barriers; name->location
      private static BNSService service
      The internal service.
      private java.util.HashMap waitingResolves
      Map of currently waiting resolves; name->reply-location
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private BNS()
      Private empty constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static BNS getInstance()
      Gets the singleton instance of the BNS
      static void initialise​(NodeAddress bnsNode)
      Initialises the connection to the BNS
      static void initialise​(NodeID bnsNode)
      Initialises the connection to the BNS
      static NetBarrier netBarrier​(java.lang.String name, int enrolled)
      Creates a new client end of a NetBarrier
      static NetBarrier netBarrier​(java.lang.String name, int localEnrolled, int netEnrolled)
      Creates a new server end of a NetBarrier with the given name
      static NetBarrier numberedNetBarrier​(java.lang.String name, int index, int localEnrolled, int netEnrolled)
      Creates a new server end of a NetBarrier with a given index and name
      void run()
      The run method for the BNS process
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • service

        private static BNSService service
        The internal service. This is used by the factory methods.
      • initialised

        private static boolean initialised
        Flag used to denote if the connection to the BNS has been initialised
      • instance

        private static final BNS instance
        Singleton instance of the BNS. Only one may be created on a Node
      • registeredBarriers

        private final java.util.HashMap registeredBarriers
        Map of registered barriers; name->location
      • barrierRegister

        private final java.util.HashMap barrierRegister
        Map of barriers registered to a Node; NodeID->
      • waitingResolves

        private final java.util.HashMap waitingResolves
        Map of currently waiting resolves; name->reply-location
      • loggedClients

        private final java.util.HashMap loggedClients
        Map of currently logged clients; NodeID->reply-channel
      • lostLink

        private final AltingChannelInput lostLink
        A channel used to receive incoming link lost notifications
    • Constructor Detail

      • BNS

        private BNS()
        Private empty constructor
    • Method Detail

      • getInstance

        public static BNS getInstance()
        Gets the singleton instance of the BNS
        Returns:
        The singleton instance of the BNS
      • initialise

        public static void initialise​(NodeID bnsNode)
                               throws JCSPNetworkException
        Initialises the connection to the BNS
        Parameters:
        bnsNode - The NodeID of the BNS Node
        Throws:
        JCSPNetworkException - Thrown if something goes wrong in the underlying architecture
      • initialise

        public static void initialise​(NodeAddress bnsNode)
                               throws JCSPNetworkException
        Initialises the connection to the BNS
        Parameters:
        bnsNode - The NodeAddress of the BNS Node
        Throws:
        JCSPNetworkException - Thrown if something goes wrong in the underlying architecture
      • run

        public void run()
        The run method for the BNS process
        Specified by:
        run in interface CSProcess
      • netBarrier

        public static NetBarrier netBarrier​(java.lang.String name,
                                            int localEnrolled,
                                            int netEnrolled)
                                     throws java.lang.IllegalArgumentException,
                                            java.lang.IllegalStateException
        Creates a new server end of a NetBarrier with the given name
        Parameters:
        name - The name to register with the BNS
        localEnrolled - The number of locally enrolled processes
        netEnrolled - The number of net enrolled processes to expect
        Returns:
        A new NetBarrier server end with the number of enrolled processes
        Throws:
        java.lang.IllegalArgumentException - Thrown if the parameters are outside the defined ranges
        java.lang.IllegalStateException - Thrown if the BNS connection has not been initialised
      • numberedNetBarrier

        public static NetBarrier numberedNetBarrier​(java.lang.String name,
                                                    int index,
                                                    int localEnrolled,
                                                    int netEnrolled)
                                             throws java.lang.IllegalArgumentException,
                                                    java.lang.IllegalStateException
        Creates a new server end of a NetBarrier with a given index and name
        Parameters:
        name - Name to register with the BNS
        index - The index to create the NetBarrier with
        localEnrolled - The number of locally enrolled processes
        netEnrolled - The number of remote enrollments to wait for
        Returns:
        A new NetBarrier
        Throws:
        java.lang.IllegalArgumentException - Thrown if the parameters are outside the defined ranges
        java.lang.IllegalStateException - Thrown if the connection to the BNS has not been initialised
      • netBarrier

        public static NetBarrier netBarrier​(java.lang.String name,
                                            int enrolled)
                                     throws java.lang.IllegalArgumentException,
                                            java.lang.IllegalStateException,
                                            JCSPNetworkException
        Creates a new client end of a NetBarrier
        Parameters:
        name - The name to resolve with the BNS
        enrolled - The number of locally enrolled processes
        Returns:
        A new NetBarrier client end with the number of enrolled processes
        Throws:
        JCSPNetworkException - Thrown if something goes wrong in the underlying architecture
        java.lang.IllegalArgumentException - Thrown if the number of of local enrolled is outside the defined range
        java.lang.IllegalStateException - Thrown if the connection to the BNS has not been initialised