Class JxtaNetworkManager
- java.lang.Object
-
- com.sun.enterprise.mgmt.transport.AbstractNetworkManager
-
- com.sun.enterprise.mgmt.transport.jxta.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?
-
-
Field Summary
-
Fields inherited from class com.sun.enterprise.mgmt.transport.AbstractNetworkManager
localPeerID
-
Fields inherited from interface com.sun.enterprise.mgmt.transport.ShoalMessageSender
TCP_TRANSPORT, UDP_TRANSPORT
-
-
Constructor Summary
Constructors Constructor Description JxtaNetworkManager()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddRemotePeer(PeerID id)Add thepeerIDto this network managerprotected voidafterDispatchingMessage(MessageEvent messageEvent, java.util.Map piggyback)After executingMessageListener.receiveMessageEvent(MessageEvent)} callback, this method will be calledprotected voidbeforeDispatchingMessage(MessageEvent messageEvent, java.util.Map piggyback)Before executingMessageListener.receiveMessageEvent(MessageEvent)} callback, this method will be calledbooleanbroadcast(Message message)Broadcasts or Multicasts the givenMessageto all membersvoidcacheRoute(net.jxta.protocol.RouteAdvertisement route)Caches a route for an instancenet.jxta.pipe.PipeIDgetAppServicePipeID()Returns the Pipe ID that will be used for application layer to send and receive messages.net.jxta.protocol.RouteAdvertisementgetCachedRoute(net.jxta.peer.PeerID peerid)returns the cached route if any, null otherwisenet.jxta.pipe.PipeIDgetHealthPipeID()Returns the HealthMonitor PipeID, used for health monitoring purposes.java.io.FilegetHome()Returns the home directory.net.jxta.peergroup.PeerGroupIDgetInfraPeerGroupID()Contructs and returns the Infrastructure PeerGroupID for the ClusterManager.java.lang.StringgetInstanceName()Returns this instance name.net.jxta.peer.PeerIDgetJxtaPeerID(java.lang.String instanceName)net.jxta.pipe.PipeIDgetMasterPipeID()Returns the MasterNode protocol PipeID.MessageSendergetMessageSender(int transport)Returns aMessageSendercorresponding with transport typeMulticastMessageSendergetMulticastMessageSender()Returns aMulticastMessageSendernet.jxta.peergroup.PeerGroupgetNetPeerGroup()Returns the netPeerGroup instance for this Cluster.net.jxta.peergroup.PeerGroupIDgetPeerGroupID(java.lang.String groupName)Given a instance name, it returns a name encoded PeerID to for binding to specific instance.net.jxta.peer.PeerIDgetPeerID()Gets this instance's PeerIDPeerIDgetPeerID(java.lang.String instanceName)Given a instance name, it returns a name encoded PeerID to for binding to specific instance.net.jxta.protocol.PipeAdvertisementgetPipeAdvertisement(java.lang.String instanceName)Creates a JxtaBiDiPipe pipe advertisement with a SHA1 encoded instance name pipe ID.net.jxta.pipe.PipeIDgetPipeID()Returns this instance name encoded PipeID.net.jxta.pipe.PipeIDgetPipeID(java.lang.String instanceName)Given a instance name, it returns a name encoded PipeID to for binding JxtaBiDiPipes.net.jxta.pipe.PipeIDgetSessionQueryPipeID()Returns the SessionQeuryPipe ID.net.jxta.protocol.PipeAdvertisementgetSocketAdvertisement(java.lang.String instanceName)Creates a JxtaSocket pipe advertisement with a SHA1 encoded instance name pipe ID.net.jxta.pipe.PipeIDgetSocketID(java.lang.String instanceName)Given a instance name, it returns a name encoded PipeID to for binding JxtaSockets.voidinitialize(java.lang.String groupName, java.lang.String instanceName, java.util.Map properties)NetworkManager provides a simple interface to configuring and managing the lifecycle of the JXTA platform.booleanisConnected(PeerID peerID)Check whether the suspicious peer is alive or not This API is mainly used inHealthMonitorin order to determine the failure membervoidremovePeerID(PeerID peerID)Removes thepeerIDfrom this network managervoidrendezvousEvent(net.jxta.rendezvous.RendezvousEvent event)booleansend(PeerID peerID, Message message)Sends the givenMessageto the destinationvoidstart()Creates and starts the JXTA NetPeerGroup using a platform configuration template.voidstop()Stops the NetworkManager and the JXTA platform.booleanwaitForRendezvousConnection(long timeout)Blocks until a connection to rendezvous node occurs.-
Methods inherited from class com.sun.enterprise.mgmt.transport.AbstractNetworkManager
addMessageListener, getInstance, getLocalPeerID, getLogger, receiveMessage, removeMessageListener
-
-
-
-
Method Detail
-
initialize
public void initialize(java.lang.String groupName, java.lang.String instanceName, java.util.Map properties) throws java.io.IOExceptionNetworkManager 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:
initializein interfaceNetworkManager- Overrides:
initializein classAbstractNetworkManager- 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:
getPeerIDin interfaceNetworkManager- Parameters:
instanceName- instance name value- Returns:
- The peerID value
-
removePeerID
public void removePeerID(PeerID peerID)
Description copied from interface:NetworkManagerRemoves thepeerIDfrom this network manager- Specified by:
removePeerIDin interfaceNetworkManager- Parameters:
peerID- the peer Id
-
isConnected
public boolean isConnected(PeerID peerID)
Description copied from interface:NetworkManagerCheck whether the suspicious peer is alive or not This API is mainly used inHealthMonitorin order to determine the failure member- Specified by:
isConnectedin interfaceNetworkManager- 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.IOExceptionCreates and starts the JXTA NetPeerGroup using a platform configuration template. This class also registers a listener for rendezvous events- Specified by:
startin interfaceNetworkManager- Specified by:
startin interfaceShoalMessageSender- Overrides:
startin classAbstractNetworkManager- Throws:
java.io.IOException- if an io error occurs during creation of the cache directory
-
stop
public void stop()
Stops the NetworkManager and the JXTA platform.- Specified by:
stopin interfaceNetworkManager- Specified by:
stopin interfaceShoalMessageSender- Overrides:
stopin classAbstractNetworkManager
-
send
public boolean send(PeerID peerID, Message message) throws java.io.IOException
Description copied from interface:MessageSenderSends the givenMessageto the destination- Specified by:
sendin interfaceMessageSender- Parameters:
peerID- the destinationPeerID.nullis not allowedmessage- 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:MulticastMessageSenderBroadcasts or Multicasts the givenMessageto all members- Specified by:
broadcastin interfaceMulticastMessageSender- 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
-
beforeDispatchingMessage
protected void beforeDispatchingMessage(MessageEvent messageEvent, java.util.Map piggyback)
Description copied from class:AbstractNetworkManagerBefore executingMessageListener.receiveMessageEvent(MessageEvent)} callback, this method will be called- Specified by:
beforeDispatchingMessagein classAbstractNetworkManager- Parameters:
messageEvent- a receivedMessageEventpiggyback- piggyback
-
afterDispatchingMessage
protected void afterDispatchingMessage(MessageEvent messageEvent, java.util.Map piggyback)
Description copied from class:AbstractNetworkManagerAfter executingMessageListener.receiveMessageEvent(MessageEvent)} callback, this method will be called- Specified by:
afterDispatchingMessagein classAbstractNetworkManager- Parameters:
messageEvent- a receivedMessageEventpiggyback- piggyback
-
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:
rendezvousEventin interfacenet.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
-
getMessageSender
public MessageSender getMessageSender(int transport)
Description copied from interface:NetworkManagerReturns aMessageSendercorresponding with transport type- Specified by:
getMessageSenderin interfaceNetworkManager- Parameters:
transport- transport type.ShoalMessageSender.TCP_TRANSPORTorShoalMessageSender.UDP_TRANSPORT's integer value- Returns:
- a
MessageSender's instance which this network manager contains
-
getMulticastMessageSender
public MulticastMessageSender getMulticastMessageSender()
Description copied from interface:NetworkManagerReturns aMulticastMessageSender- Specified by:
getMulticastMessageSenderin interfaceNetworkManager- Returns:
- a
MulticastMessageSender's instance which this network manager contains
-
addRemotePeer
public void addRemotePeer(PeerID id)
Description copied from interface:NetworkManagerAdd thepeerIDto this network manager- Specified by:
addRemotePeerin interfaceNetworkManager- Parameters:
id- the peer Id
-
-