p2pMapReduce.impl.networkModule.jxta
Class JxtaNetworkModule

java.lang.Object
  extended by p2pMapReduce.impl.networkModule.jxta.JxtaNetworkModule
All Implemented Interfaces:
java.util.EventListener, net.jxta.rendezvous.RendezvousListener, NetworkModuleIF
Direct Known Subclasses:
NetworkModulePrototipe

public class JxtaNetworkModule
extends java.lang.Object
implements NetworkModuleIF, net.jxta.rendezvous.RendezvousListener


Field Summary
static long ADV_EXPIRATION_TIME
          Limited adv expiration time to automatically remove older version on remote node cache Note:The #PUBLISH_TIMEOUT must be less than this value to allow others node to discovery and update ADV before they expired
static java.lang.String ADV_EXPIRATION_TIME_ATTR
          Key for ADV_EXPIRATION_TIME
static long ADV_LIFE_TIME
          Limited adv life time in local cache to automatically remove older version.
static java.lang.String ADV_LIFE_TIME_ATTR
          Key for ADV_LIFE_TIME
static java.lang.String ADV_LIFETIME_ATTR
          Key for ADV_LIFE_TIME
static java.lang.String DEFAULT_PEER_NAME
          Default peer name
static long DIRECT_FIND_WAITING_TIME
          Time to wait before terminate a direct ADV discovery
static java.lang.String DIRECT_FIND_WAITING_TIME_ATTR
          Key for DIRECT_FIND_WAITING_TIME
static long GROUP_FIND_WAITING_TIME
          Time to wait for group discovery
static java.lang.String GROUP_FIND_WAITING_TIME_ATTR
          Key for GROUP_FIND_WAITING_TIME
static java.lang.String GROUP_ID
          Pre-set P2PMapReduce group ID
static java.lang.String IS_GATEWAY_ATTR
          Key for is.gateway attribute of the NetworkConfiguration
static java.lang.String JXTA_HOME_ATTR
          Key for JXTA home directory attribute in NetworkConfiguration
static java.lang.String JXTA_PEER_MODE_ATTR
          Key for JXTA peer mode attribute in NetworkConfiguration
static java.lang.String P2P_MAPREDUCE_GROUP_NAME
          P2PMapReduce group name
static long PERIODIC_FIND_TIMEOUT
          Deprecated.  
static java.lang.String PERIODIC_FIND_TIMEOUT_ATTR
          Deprecated.  
static long PERIODIC_PUBLISH_TIMEOUT
          The time period to publish a new ADV for this node
static java.lang.String PERIODIC_PUBLISH_TIMEOUT_ATTR
          Key for #PUBLISH_TIMEOUT
static java.lang.String RDV_AUTO_START
          Key for rdv.autoStart attribute of the NetworkConfiguration
static java.lang.String RDV_SEEDS_ATTR
          Key for rdv.seeds attribute of the NetworkConfiguration
static long RDV_WAITING_TIME
          Time to wait for RDV connection
static java.lang.String RDV_WAITING_TIME_ATTR
          Key for RDV_WAITING_TIME
 
Constructor Summary
JxtaNetworkModule(NetworkConfiguration networkConfiguration)
           
 
Method Summary
 void addEventListener(EventListener eventListener)
          Used to add a EventListener to which forward all the MessageEvent received by the network connections
 void becomeMaster()
          Invoked by the node module to notify that the node has changed its role from Slave to Master
 void becomeSlave()
          Invoked by the node module to notify that the node has changed its role from Master to Slave
 boolean connectedOrRDV(net.jxta.peergroup.PeerGroup pg)
           
protected  void connectionClosed(NodeInfo connectionEndPoint)
           
 NodeInfo find(java.lang.String nodeID)
          Search the network to find the NodeAdvertisement of the node identified by nodeID
 java.util.Collection<JxtaBidiPipeConnection> getActiveConnection()
           
protected  java.util.Set<NodeInfo> getAllAvailableNodes(java.util.Set<net.jxta.document.Advertisement> resp)
           
 java.util.Set<NodeInfo> getAllAvailableNodesFromLocalCache()
          TODO public for testing purpose. to make not public
 java.util.Set<NodeInfo> getAllAvailableNodesFromLocalCache(int nodeType)
          Returns the set of all available node info for those nodes which role is nodeType.
 java.util.Set<NodeInfo> getAllMasters()
          Return all the visible master nodes in the network by this network module at the moment
 java.util.Set<NodeInfo> getAllNodes()
          Retrieves all the node adv on the network and for each peer keeps only the node adv with higher version //XXX for now we see in the local cache becouse if this is a rdv
protected  java.util.Set<NodeInfo> getAllNodesFromLocalCache()
          Deprecated. use getAllAvailableNodesFromLocalCache() instead
 java.util.Set<NodeInfo> getAllSlaves()
          Return all the visible slave nodes in the network by this network module at the moment
 JxtaNodeInfo getAvailableNodeFromLocalCache(java.lang.String nodeID)
          Try to find the most recent available version of the node info for the node which id is nodeID.
 ConnectionIF getConnection(NodeInfo connectionEndPoint)
          Returns a connection between this network module and the network module relative to the node described by the NodeInfo connectionEndPoint
 ConnectionIF getConnection(java.lang.String nodeID)
          Returns a connection between this network module and the network module relative to the node identified by nodeID.
 FTPManager getFtpManager()
          Return an FTPManager for this node
 net.jxta.peergroup.PeerGroup getNetPeerGroup()
           
 net.jxta.platform.NetworkManager getNetworkManager()
           
 NodeInfo getNodeInfo()
          Return the same instance of NodeInfo returned by the joinNetwork() method.
 NodeModuleIF getNodeModule()
          Returns the NodeModuleIF associated to this network module
 int getNumMasters()
          Returns the number of all the visible master nodes from this network module at the moment
 int getNumNodes()
          Returns the number of all the visible nodes from this network module at the moment
 int getNumSlaves()
          Returns the number of all the visible slave nodes from this network module at the moment
 java.util.Set<NodeInfo> getOtherMasters()
          Return all the visible slaves nodes in the network by this network module at the moment, except this node if it is a master
 java.util.Set<NodeInfo> getOtherSlaves()
          Return all the visible slaves nodes in the network by this network module at the moment, except this node if it is a slave
 net.jxta.peergroup.PeerGroup getP2pMapReduceGroup()
           
 boolean isAlive(java.lang.String nodeID)
          Indicate if a node is alive.
 NodeInfo joinNetwork()
          Call this method once to enter the P2PMapReduce network.
protected  void nodeFailure(NodeInfo failedNodeInfo)
           
 void publish()
          Used to send the information of the NodeInfo instance associated to this network module across the P2PMapReduce network.
protected  void putConnection(java.lang.String nodeID, JxtaBidiPipeConnection conn)
           
protected  JxtaBidiPipeConnection removeConnection(java.lang.String nodeID)
           
 void rendezvousEvent(net.jxta.rendezvous.RendezvousEvent event)
           
 void send(NodeInfo endPoint, java.io.Serializable o)
          Send the object msg to the node specified by endPoint If no connection is already available to this node, try to create a new one using the provided NodeInfo
 void send(java.lang.String senderID, java.io.Serializable msg)
          Send the object msg to the node identified by destID.
 void setNodeModule(NodeModuleIF nodeModule)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

GROUP_ID

public static final java.lang.String GROUP_ID
Pre-set P2PMapReduce group ID

See Also:
Constant Field Values

P2P_MAPREDUCE_GROUP_NAME

public static final java.lang.String P2P_MAPREDUCE_GROUP_NAME
P2PMapReduce group name

See Also:
Constant Field Values

DEFAULT_PEER_NAME

public static final java.lang.String DEFAULT_PEER_NAME
Default peer name

See Also:
Constant Field Values

JXTA_HOME_ATTR

public static final java.lang.String JXTA_HOME_ATTR
Key for JXTA home directory attribute in NetworkConfiguration

See Also:
Constant Field Values

JXTA_PEER_MODE_ATTR

public static final java.lang.String JXTA_PEER_MODE_ATTR
Key for JXTA peer mode attribute in NetworkConfiguration

See Also:
Constant Field Values

GROUP_FIND_WAITING_TIME_ATTR

public static final java.lang.String GROUP_FIND_WAITING_TIME_ATTR
Key for GROUP_FIND_WAITING_TIME

See Also:
Constant Field Values

GROUP_FIND_WAITING_TIME

public static final long GROUP_FIND_WAITING_TIME
Time to wait for group discovery


ADV_LIFETIME_ATTR

public static final java.lang.String ADV_LIFETIME_ATTR
Key for ADV_LIFE_TIME

See Also:
Constant Field Values

ADV_LIFE_TIME

public static final long ADV_LIFE_TIME
Limited adv life time in local cache to automatically remove older version. Note:The #PUBLISH_TIMEOUT must be less than this value to allow others node to discovery and update ADV before they expired


ADV_LIFE_TIME_ATTR

public static final java.lang.String ADV_LIFE_TIME_ATTR
Key for ADV_LIFE_TIME

See Also:
Constant Field Values

ADV_EXPIRATION_TIME_ATTR

public static final java.lang.String ADV_EXPIRATION_TIME_ATTR
Key for ADV_EXPIRATION_TIME

See Also:
Constant Field Values

ADV_EXPIRATION_TIME

public static final long ADV_EXPIRATION_TIME
Limited adv expiration time to automatically remove older version on remote node cache Note:The #PUBLISH_TIMEOUT must be less than this value to allow others node to discovery and update ADV before they expired


PERIODIC_PUBLISH_TIMEOUT_ATTR

public static final java.lang.String PERIODIC_PUBLISH_TIMEOUT_ATTR
Key for #PUBLISH_TIMEOUT

See Also:
Constant Field Values

PERIODIC_PUBLISH_TIMEOUT

public static final long PERIODIC_PUBLISH_TIMEOUT
The time period to publish a new ADV for this node


PERIODIC_FIND_TIMEOUT_ATTR

public static final java.lang.String PERIODIC_FIND_TIMEOUT_ATTR
Deprecated. 
Key for PERIODIC_FIND_TIMEOUT

See Also:
Constant Field Values

PERIODIC_FIND_TIMEOUT

public static final long PERIODIC_FIND_TIMEOUT
Deprecated. 
Time period to discover ADV on the net


DIRECT_FIND_WAITING_TIME_ATTR

public static final java.lang.String DIRECT_FIND_WAITING_TIME_ATTR
Key for DIRECT_FIND_WAITING_TIME

See Also:
Constant Field Values

DIRECT_FIND_WAITING_TIME

public static final long DIRECT_FIND_WAITING_TIME
Time to wait before terminate a direct ADV discovery


RDV_WAITING_TIME_ATTR

public static final java.lang.String RDV_WAITING_TIME_ATTR
Key for RDV_WAITING_TIME

See Also:
Constant Field Values

RDV_WAITING_TIME

public static final long RDV_WAITING_TIME
Time to wait for RDV connection


IS_GATEWAY_ATTR

public static final java.lang.String IS_GATEWAY_ATTR
Key for is.gateway attribute of the NetworkConfiguration

See Also:
Constant Field Values

RDV_SEEDS_ATTR

public static final java.lang.String RDV_SEEDS_ATTR
Key for rdv.seeds attribute of the NetworkConfiguration

See Also:
Constant Field Values

RDV_AUTO_START

public static final java.lang.String RDV_AUTO_START
Key for rdv.autoStart attribute of the NetworkConfiguration

See Also:
Constant Field Values
Constructor Detail

JxtaNetworkModule

public JxtaNetworkModule(NetworkConfiguration networkConfiguration)
Method Detail

joinNetwork

public NodeInfo joinNetwork()
Description copied from interface: NetworkModuleIF
Call this method once to enter the P2PMapReduce network. The method returns an instance of NodeInfo containing all the information about the node associated to this network module. A reference to this NodeInfo instance will be maintained from this module and can be retrieved in the future by calling NetworkModuleIF.getNodeInfo(). All the updates to the node information will affect this NodeInfo instance. It also: - publishes this NodeInfo by calling publish() - make this NetworkModule capable to receive remote connection from other nodes. - starts an FTP server

Specified by:
joinNetwork in interface NetworkModuleIF
Returns:

getFtpManager

public FTPManager getFtpManager()
Description copied from interface: NetworkModuleIF
Return an FTPManager for this node

Specified by:
getFtpManager in interface NetworkModuleIF
Returns:

becomeSlave

public void becomeSlave()
Description copied from interface: NetworkModuleIF
Invoked by the node module to notify that the node has changed its role from Master to Slave

Specified by:
becomeSlave in interface NetworkModuleIF

becomeMaster

public void becomeMaster()
Description copied from interface: NetworkModuleIF
Invoked by the node module to notify that the node has changed its role from Slave to Master

Specified by:
becomeMaster in interface NetworkModuleIF

publish

public void publish()
Description copied from interface: NetworkModuleIF
Used to send the information of the NodeInfo instance associated to this network module across the P2PMapReduce network. It must be called after every update to the NodeInfo of this network module in order to make all node known about .

Specified by:
publish in interface NetworkModuleIF

getNodeInfo

public NodeInfo getNodeInfo()
Description copied from interface: NetworkModuleIF
Return the same instance of NodeInfo returned by the joinNetwork() method.

Specified by:
getNodeInfo in interface NetworkModuleIF
Returns:
the same instance of NodeInfo returned by joinNetwork() or null if joinNetwork() has never be executed with success.

getNodeModule

public NodeModuleIF getNodeModule()
Description copied from interface: NetworkModuleIF
Returns the NodeModuleIF associated to this network module

Specified by:
getNodeModule in interface NetworkModuleIF
Returns:

setNodeModule

public void setNodeModule(NodeModuleIF nodeModule)
Specified by:
setNodeModule in interface NetworkModuleIF

addEventListener

public void addEventListener(EventListener eventListener)
Description copied from interface: NetworkModuleIF
Used to add a EventListener to which forward all the MessageEvent received by the network connections

Specified by:
addEventListener in interface NetworkModuleIF

find

public NodeInfo find(java.lang.String nodeID)
Search the network to find the NodeAdvertisement of the node identified by nodeID

Specified by:
find in interface NetworkModuleIF
Parameters:
nodeID -
Returns:
The most recently founded NodeInfo of the specified node or null if no NodeAdvertisement have been founded

isAlive

public boolean isAlive(java.lang.String nodeID)
Indicate if a node is alive. Check if a node info is available directly from the local cache //FIXME it has to return true if the node is really available or if //the node adv is founded?

Specified by:
isAlive in interface NetworkModuleIF
Parameters:
nodeID -
Returns:
See Also:
NetworkModuleIF.find(String)

getNumMasters

public int getNumMasters()
Description copied from interface: NetworkModuleIF
Returns the number of all the visible master nodes from this network module at the moment

Specified by:
getNumMasters in interface NetworkModuleIF
Returns:

getNumSlaves

public int getNumSlaves()
Description copied from interface: NetworkModuleIF
Returns the number of all the visible slave nodes from this network module at the moment

Specified by:
getNumSlaves in interface NetworkModuleIF
Returns:

getNumNodes

public int getNumNodes()
Description copied from interface: NetworkModuleIF
Returns the number of all the visible nodes from this network module at the moment

Specified by:
getNumNodes in interface NetworkModuleIF
Returns:

getAllSlaves

public java.util.Set<NodeInfo> getAllSlaves()
Description copied from interface: NetworkModuleIF
Return all the visible slave nodes in the network by this network module at the moment

Specified by:
getAllSlaves in interface NetworkModuleIF
Returns:

getAllMasters

public java.util.Set<NodeInfo> getAllMasters()
Description copied from interface: NetworkModuleIF
Return all the visible master nodes in the network by this network module at the moment

Specified by:
getAllMasters in interface NetworkModuleIF
Returns:

getAllNodes

public java.util.Set<NodeInfo> getAllNodes()
Retrieves all the node adv on the network and for each peer keeps only the node adv with higher version //XXX for now we see in the local cache becouse if this is a rdv

Specified by:
getAllNodes in interface NetworkModuleIF
Returns:

getOtherSlaves

public java.util.Set<NodeInfo> getOtherSlaves()
Description copied from interface: NetworkModuleIF
Return all the visible slaves nodes in the network by this network module at the moment, except this node if it is a slave

Specified by:
getOtherSlaves in interface NetworkModuleIF
Returns:

getOtherMasters

public java.util.Set<NodeInfo> getOtherMasters()
Description copied from interface: NetworkModuleIF
Return all the visible slaves nodes in the network by this network module at the moment, except this node if it is a master

Specified by:
getOtherMasters in interface NetworkModuleIF
Returns:

getNetworkManager

public net.jxta.platform.NetworkManager getNetworkManager()

getNetPeerGroup

public net.jxta.peergroup.PeerGroup getNetPeerGroup()

getP2pMapReduceGroup

public net.jxta.peergroup.PeerGroup getP2pMapReduceGroup()

getActiveConnection

public java.util.Collection<JxtaBidiPipeConnection> getActiveConnection()

getAllNodesFromLocalCache

protected java.util.Set<NodeInfo> getAllNodesFromLocalCache()
Deprecated. use getAllAvailableNodesFromLocalCache() instead

Returns:

getAllAvailableNodesFromLocalCache

public java.util.Set<NodeInfo> getAllAvailableNodesFromLocalCache()
TODO public for testing purpose. to make not public

Returns:

getAllAvailableNodesFromLocalCache

public java.util.Set<NodeInfo> getAllAvailableNodesFromLocalCache(int nodeType)
Returns the set of all available node info for those nodes which role is nodeType. XXX In order to avoid the possibility of collect obsolete node info, a preliminary search of all node info is done to collect the most recent node info for a node. After only the node info of the specified type are returned

Parameters:
nodeType -
Returns:

getAllAvailableNodes

protected java.util.Set<NodeInfo> getAllAvailableNodes(java.util.Set<net.jxta.document.Advertisement> resp)

getAvailableNodeFromLocalCache

public JxtaNodeInfo getAvailableNodeFromLocalCache(java.lang.String nodeID)
Try to find the most recent available version of the node info for the node which id is nodeID.

Parameters:
nodeID -
Returns:
null if the node is not available or the most recent node info for that node

send

public void send(NodeInfo endPoint,
                 java.io.Serializable o)
          throws java.io.IOException
Description copied from interface: NetworkModuleIF
Send the object msg to the node specified by endPoint If no connection is already available to this node, try to create a new one using the provided NodeInfo

Specified by:
send in interface NetworkModuleIF
Throws:
java.io.IOException

send

public void send(java.lang.String senderID,
                 java.io.Serializable msg)
          throws java.io.IOException
Description copied from interface: NetworkModuleIF
Send the object msg to the node identified by destID. If no connection is already available to this node, try to retrieve the NodeInfo for this node and to create a new connection.

Specified by:
send in interface NetworkModuleIF
Throws:
java.io.IOException

getConnection

public ConnectionIF getConnection(NodeInfo connectionEndPoint)
                           throws java.io.IOException
Description copied from interface: NetworkModuleIF
Returns a connection between this network module and the network module relative to the node described by the NodeInfo connectionEndPoint

Specified by:
getConnection in interface NetworkModuleIF
Returns:
Throws:
java.io.IOException

getConnection

public ConnectionIF getConnection(java.lang.String nodeID)
                           throws java.io.IOException
Description copied from interface: NetworkModuleIF
Returns a connection between this network module and the network module relative to the node identified by nodeID. If no connection is already available to this node try to retrieve the NodeInfo for this node and to create a new connection. IOException is thrown instead or in consequence of errors.

Specified by:
getConnection in interface NetworkModuleIF
Returns:
Throws:
java.io.IOException

putConnection

protected void putConnection(java.lang.String nodeID,
                             JxtaBidiPipeConnection conn)

removeConnection

protected JxtaBidiPipeConnection removeConnection(java.lang.String nodeID)

nodeFailure

protected void nodeFailure(NodeInfo failedNodeInfo)

connectionClosed

protected void connectionClosed(NodeInfo connectionEndPoint)

rendezvousEvent

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

connectedOrRDV

public boolean connectedOrRDV(net.jxta.peergroup.PeerGroup pg)