Class JxtaNetworkManager

  • All Implemented Interfaces:
    MessageSender, MulticastMessageSender, NetworkManager, ShoalMessageSender, java.util.EventListener, net.jxta.rendezvous.RendezvousListener

    public class JxtaNetworkManager
    extends AbstractNetworkManager
    implements net.jxta.rendezvous.RendezvousListener
    NetworkManager wraps the JXTA plaform lifecycle into a single object. Using the instance name, it encodes a node Peer ID, and provides utilities to derive Peer ID's from an instance name. Given an instance name, this allows any node to independently interpolate a Peer ID.

    TODO:REVISIT FOR REFACTORING AND ADDED REQUIRMENTS. TODO: WHEN SPECIFYING INSTANCENAME IN EACH METHOD, IS IT THE INTENTION THAT THE CONSUMING APP COULD POTENTIALLY TODO: PROVIDE DIFFERENT INSTANCE NAMES AT DIFFERENT TIMES DURING A GIVEN LIFETIME OF THE APP? WHAT IMPACT WOULD THERE TODO:BE IF WE REMOVE INSTANCENAME FROM THE PARAMETERS OF THESE METHODS AND BASE INSTANCE NAME FROM THE CONSTRUCTOR'S TODO: CONSTRUCTION FROM PROPERTIES OBJECT?

    • Constructor Detail

      • JxtaNetworkManager

        public JxtaNetworkManager()
    • Method Detail

      • initialize

        public void initialize​(java.lang.String groupName,
                               java.lang.String instanceName,
                               java.util.Map properties)
                        throws java.io.IOException
        NetworkManager provides a simple interface to configuring and managing the lifecycle of the JXTA platform. In addition, it provides logical addressing by means of name encoded PeerID, and communication channels. This allows the application to utilize simple addressing. Therefore it is key that these names are chosen carefully to avoid collision.
        Specified by:
        initialize in interface NetworkManager
        Overrides:
        initialize in class AbstractNetworkManager
        Parameters:
        groupName - Group Name, a logical group name that this peer is part of.
        instanceName - Instance Name, a logical name for this peer.
        properties - a Properties object that would contain every configuration element that the employing application wants to specify values for. The keys in this object must correspond to the constants specified in the JxtaConfigConstants enum.
        Throws:
        java.io.IOException - if an unexpected error occurs
      • getPipeID

        public net.jxta.pipe.PipeID getPipeID​(java.lang.String instanceName)
        Given a instance name, it returns a name encoded PipeID to for binding JxtaBiDiPipes.
        Parameters:
        instanceName - instance name
        Returns:
        The pipeID value
      • getSocketID

        public net.jxta.pipe.PipeID getSocketID​(java.lang.String instanceName)
        Given a instance name, it returns a name encoded PipeID to for binding JxtaSockets.
        Parameters:
        instanceName - instance name value
        Returns:
        The scoket PipeID value
      • getPeerID

        public PeerID getPeerID​(java.lang.String instanceName)
        Given a instance name, it returns a name encoded PeerID to for binding to specific instance.
        Specified by:
        getPeerID in interface NetworkManager
        Parameters:
        instanceName - instance name value
        Returns:
        The peerID value
      • removePeerID

        public void removePeerID​(PeerID peerID)
        Description copied from interface: NetworkManager
        Removes the peerID from this network manager
        Specified by:
        removePeerID in interface NetworkManager
        Parameters:
        peerID - the peer Id
      • isConnected

        public boolean isConnected​(PeerID peerID)
        Description copied from interface: NetworkManager
        Check whether the suspicious peer is alive or not This API is mainly used in HealthMonitor in order to determine the failure member
        Specified by:
        isConnected in interface NetworkManager
        Parameters:
        peerID - peer id
        Returns:
        true if the peer is still alive, otherwise false
      • getJxtaPeerID

        public net.jxta.peer.PeerID getJxtaPeerID​(java.lang.String instanceName)
      • getPeerGroupID

        public net.jxta.peergroup.PeerGroupID getPeerGroupID​(java.lang.String groupName)
        Given a instance name, it returns a name encoded PeerID to for binding to specific instance.
        Parameters:
        groupName - instance name value
        Returns:
        The peerID value
      • getHealthPipeID

        public net.jxta.pipe.PipeID getHealthPipeID()
        Returns the HealthMonitor PipeID, used for health monitoring purposes.
        Returns:
        The HealthPipe Pipe ID
      • getMasterPipeID

        public net.jxta.pipe.PipeID getMasterPipeID()
        Returns the MasterNode protocol PipeID. used for dynamic organization of nodes.
        Returns:
        The MasterPipe PipeID
      • getSessionQueryPipeID

        public net.jxta.pipe.PipeID getSessionQueryPipeID()
        Returns the SessionQeuryPipe ID. Used to query for a session replication
        Returns:
        The SessionQuery PipeID
      • getAppServicePipeID

        public net.jxta.pipe.PipeID getAppServicePipeID()
        Returns the Pipe ID that will be used for application layer to send and receive messages.
        Returns:
        The Application Service Pipe ID
      • getSocketAdvertisement

        public net.jxta.protocol.PipeAdvertisement getSocketAdvertisement​(java.lang.String instanceName)
        Creates a JxtaSocket pipe advertisement with a SHA1 encoded instance name pipe ID.
        Parameters:
        instanceName - instance name
        Returns:
        a JxtaSocket Pipe Advertisement
      • getPipeAdvertisement

        public net.jxta.protocol.PipeAdvertisement getPipeAdvertisement​(java.lang.String instanceName)
        Creates a JxtaBiDiPipe pipe advertisement with a SHA1 encoded instance name pipe ID.
        Parameters:
        instanceName - instance name
        Returns:
        PipeAdvertisement a JxtaBiDiPipe Pipe Advertisement
      • getInfraPeerGroupID

        public net.jxta.peergroup.PeerGroupID getInfraPeerGroupID()
        Contructs and returns the Infrastructure PeerGroupID for the ClusterManager. This ensures scoping and isolation of ClusterManager deployments.
        Returns:
        The infraPeerGroupID PeerGroupID
      • start

        public void start()
                   throws java.io.IOException
        Creates and starts the JXTA NetPeerGroup using a platform configuration template. This class also registers a listener for rendezvous events
        Specified by:
        start in interface NetworkManager
        Specified by:
        start in interface ShoalMessageSender
        Overrides:
        start in class AbstractNetworkManager
        Throws:
        java.io.IOException - if an io error occurs during creation of the cache directory
      • send

        public boolean send​(PeerID peerID,
                            Message message)
                     throws java.io.IOException
        Description copied from interface: MessageSender
        Sends the given Message to the destination
        Specified by:
        send in interface MessageSender
        Parameters:
        peerID - the destination PeerID. null is not allowed
        message - a message which is sent to the peer
        Returns:
        true if the message is sent to the destination successfully, otherwise false
        Throws:
        java.io.IOException - if I/O error occurs or given parameters are not valid
      • broadcast

        public boolean broadcast​(Message message)
                          throws java.io.IOException
        Description copied from interface: MulticastMessageSender
        Broadcasts or Multicasts the given Message to all members
        Specified by:
        broadcast in interface MulticastMessageSender
        Parameters:
        message - a message which is sent to all members
        Returns:
        true if the message is sent to all members successfully, otherwise false
        Throws:
        java.io.IOException - if I/O error occurs or given parameters are not valid
      • getNetPeerGroup

        public net.jxta.peergroup.PeerGroup getNetPeerGroup()
        Returns the netPeerGroup instance for this Cluster.
        Returns:
        The netPeerGroup value
      • waitForRendezvousConnection

        public boolean waitForRendezvousConnection​(long timeout)
        Blocks until a connection to rendezvous node occurs. Returns immediately if a connection is already established. This is useful to ensure the widest network exposure.
        Parameters:
        timeout - timeout in milliseconds
        Returns:
        connection state
      • rendezvousEvent

        public void rendezvousEvent​(net.jxta.rendezvous.RendezvousEvent event)
        Specified by:
        rendezvousEvent in interface net.jxta.rendezvous.RendezvousListener
      • getPeerID

        public net.jxta.peer.PeerID getPeerID()
        Gets this instance's PeerID
        Returns:
        The peerID value
      • getPipeID

        public net.jxta.pipe.PipeID getPipeID()
        Returns this instance name encoded PipeID.
        Returns:
        The pipeID value
      • getInstanceName

        public java.lang.String getInstanceName()
        Returns this instance name.
        Returns:
        The instance name value
      • getHome

        public java.io.File getHome()
        Returns the home directory. An instance home directory is used to persists an instance configuration and cache.
        Returns:
        The instance name value
      • cacheRoute

        public void cacheRoute​(net.jxta.protocol.RouteAdvertisement route)
        Caches a route for an instance
        Parameters:
        route - the route advertisement
      • getCachedRoute

        public net.jxta.protocol.RouteAdvertisement getCachedRoute​(net.jxta.peer.PeerID peerid)
        returns the cached route if any, null otherwise
        Parameters:
        peerid - the instance id
        Returns:
        the cached route if any, null otherwise
      • addRemotePeer

        public void addRemotePeer​(PeerID id)
        Description copied from interface: NetworkManager
        Add the peerID to this network manager
        Specified by:
        addRemotePeer in interface NetworkManager
        Parameters:
        id - the peer Id