Package i5.las2peer.p2p.pastry
Class NodeApplication
java.lang.Object
i5.las2peer.p2p.pastry.NodeApplication
- All Implemented Interfaces:
rice.p2p.commonapi.Application
,rice.p2p.scribe.ScribeClient
,rice.p2p.scribe.ScribeMultiClient
public class NodeApplication
extends java.lang.Object
implements rice.p2p.commonapi.Application, rice.p2p.scribe.ScribeMultiClient
The NodeApplication implements the interface for message based interaction with the pastry p2p network.
In particular, message sending and retrieval, artifact storage via past and publish/subscribe via scribe are used to
provide the las2peer node (and agent) communication.
-
Field Summary
Fields Modifier and Type Field Description protected rice.p2p.commonapi.Endpoint
endpoint
static java.lang.String
FREEPASTRY_APPLICATION_CODE
static java.lang.String
SCRIBE_APPLICATION_CODE
static int
SEARCH_SLEEP_TIME
static long
SEARCH_TIMEOUT
-
Constructor Summary
Constructors Constructor Description NodeApplication(PastryNodeImpl node)
create a pastry application for the given node -
Method Summary
Modifier and Type Method Description boolean
anycast(rice.p2p.scribe.Topic topic, rice.p2p.scribe.ScribeContent content)
void
childAdded(rice.p2p.scribe.Topic topic, rice.p2p.commonapi.NodeHandle nh)
void
childRemoved(rice.p2p.scribe.Topic topic, rice.p2p.commonapi.NodeHandle nh)
void
deliver(rice.p2p.commonapi.Id id, rice.p2p.commonapi.Message pastMessage)
void
deliver(rice.p2p.scribe.Topic topic, rice.p2p.scribe.ScribeContent content)
boolean
forward(rice.p2p.commonapi.RouteMessage pastMessage)
static java.lang.String
getAgentTopicId(AgentImpl agent)
generate an id string for topic corresponding to a l2p agentstatic java.lang.String
getAgentTopicId(java.lang.String id)
generate an id string for topic corresponding to a l2p agentNodeInformation
getNodeInformation(rice.p2p.commonapi.NodeHandle nodeHandle)
get information about a foreign nodevoid
registerAgentTopic(MessageReceiver receiver)
register this node to the topic related to the given message receivervoid
registerTopic(long id)
void
routeMyMsg(rice.p2p.commonapi.Id id)
Called to route a message to the idvoid
routeMyMsgDirect(rice.p2p.commonapi.NodeHandle nh)
Called to directly send a message to the nhjava.util.Collection<rice.p2p.commonapi.NodeHandle>
searchAgent(java.lang.String agentId)
look for a running/registered version of an agent in the p2p netjava.util.Collection<rice.p2p.commonapi.NodeHandle>
searchAgent(java.lang.String agentId, int expectedAnswers)
look for an agent in the p2p net This method broadcasts a search message for the given agent and collects all answers.void
sendMessage(Message l2pMessage)
broadcast aMessage
to all running instances of its recipient agentvoid
sendMessage(MessageEnvelope m, rice.p2p.commonapi.NodeHandle to)
send a message to the given node handlevoid
sendMessageDirectly(rice.p2p.commonapi.Message m, rice.p2p.commonapi.NodeHandle to)
send a pastry message to the given nodevoid
subscribeFailed(java.util.Collection<rice.p2p.scribe.Topic> topics)
void
subscribeFailed(rice.p2p.scribe.Topic topic)
void
subscribeSuccess(java.util.Collection<rice.p2p.scribe.Topic> topics)
void
unregisterAgentTopic(java.lang.String id)
unregister an agent from its subscriptionvoid
unregisterTopic(long id)
void
update(rice.p2p.commonapi.NodeHandle nh, boolean arg1)
-
Field Details
-
FREEPASTRY_APPLICATION_CODE
public static final java.lang.String FREEPASTRY_APPLICATION_CODE- See Also:
- Constant Field Values
-
SCRIBE_APPLICATION_CODE
public static final java.lang.String SCRIBE_APPLICATION_CODE- See Also:
- Constant Field Values
-
SEARCH_SLEEP_TIME
public static final int SEARCH_SLEEP_TIME- See Also:
- Constant Field Values
-
SEARCH_TIMEOUT
public static final long SEARCH_TIMEOUT- See Also:
- Constant Field Values
-
endpoint
protected rice.p2p.commonapi.Endpoint endpoint
-
-
Constructor Details
-
NodeApplication
create a pastry application for the given node- Parameters:
node
- A node to wrap around
-
-
Method Details
-
registerAgentTopic
register this node to the topic related to the given message receiver- Parameters:
receiver
- A message receiver
-
unregisterAgentTopic
unregister an agent from its subscription- Parameters:
id
- A topic id- Throws:
AgentNotRegisteredException
- If the agent was not registered for this topic
-
registerTopic
public void registerTopic(long id) -
unregisterTopic
- Throws:
NodeException
-
getNodeInformation
public NodeInformation getNodeInformation(rice.p2p.commonapi.NodeHandle nodeHandle) throws NodeNotFoundExceptionget information about a foreign node- Parameters:
nodeHandle
- A node handle- Returns:
- node information
- Throws:
NodeNotFoundException
- If the node was not found
-
deliver
public void deliver(rice.p2p.commonapi.Id id, rice.p2p.commonapi.Message pastMessage)- Specified by:
deliver
in interfacerice.p2p.commonapi.Application
-
forward
public boolean forward(rice.p2p.commonapi.RouteMessage pastMessage)- Specified by:
forward
in interfacerice.p2p.commonapi.Application
-
update
public void update(rice.p2p.commonapi.NodeHandle nh, boolean arg1)- Specified by:
update
in interfacerice.p2p.commonapi.Application
-
routeMyMsg
public void routeMyMsg(rice.p2p.commonapi.Id id)Called to route a message to the id- Parameters:
id
- A target id to route to
-
routeMyMsgDirect
public void routeMyMsgDirect(rice.p2p.commonapi.NodeHandle nh)Called to directly send a message to the nh- Parameters:
nh
- A target node handle to route to
-
sendMessage
public void sendMessage(MessageEnvelope m, rice.p2p.commonapi.NodeHandle to) throws MalformedXMLExceptionsend a message to the given node handle- Parameters:
m
- A message to sendto
- A target node handle- Throws:
MalformedXMLException
- If the XML data string is malformed
-
sendMessageDirectly
public void sendMessageDirectly(rice.p2p.commonapi.Message m, rice.p2p.commonapi.NodeHandle to)send a pastry message to the given node- Parameters:
m
- A message to sendto
- A target node handle
-
sendMessage
broadcast aMessage
to all running instances of its recipient agent- Parameters:
l2pMessage
- A message to send
-
childAdded
public void childAdded(rice.p2p.scribe.Topic topic, rice.p2p.commonapi.NodeHandle nh)- Specified by:
childAdded
in interfacerice.p2p.scribe.ScribeClient
- Specified by:
childAdded
in interfacerice.p2p.scribe.ScribeMultiClient
-
childRemoved
public void childRemoved(rice.p2p.scribe.Topic topic, rice.p2p.commonapi.NodeHandle nh)- Specified by:
childRemoved
in interfacerice.p2p.scribe.ScribeClient
- Specified by:
childRemoved
in interfacerice.p2p.scribe.ScribeMultiClient
-
searchAgent
public java.util.Collection<rice.p2p.commonapi.NodeHandle> searchAgent(java.lang.String agentId, int expectedAnswers)look for an agent in the p2p net This method broadcasts a search message for the given agent and collects all answers. It tries to wait for expectedAnswers nodes to respond to the search. However the search will be aborted after SEARCH_TIMEOUT milliseconds.- Parameters:
agentId
- An agent id to search forexpectedAnswers
- Amount of expected answers- Returns:
- a collections of node handles where the requested agent is registered to
-
searchAgent
public java.util.Collection<rice.p2p.commonapi.NodeHandle> searchAgent(java.lang.String agentId)look for a running/registered version of an agent in the p2p net- Parameters:
agentId
- An agent id to search for- Returns:
- a collection of node handles running the requested agent
-
deliver
public void deliver(rice.p2p.scribe.Topic topic, rice.p2p.scribe.ScribeContent content)- Specified by:
deliver
in interfacerice.p2p.scribe.ScribeClient
- Specified by:
deliver
in interfacerice.p2p.scribe.ScribeMultiClient
-
subscribeFailed
public void subscribeFailed(rice.p2p.scribe.Topic topic)- Specified by:
subscribeFailed
in interfacerice.p2p.scribe.ScribeClient
- Specified by:
subscribeFailed
in interfacerice.p2p.scribe.ScribeMultiClient
-
subscribeFailed
public void subscribeFailed(java.util.Collection<rice.p2p.scribe.Topic> topics)- Specified by:
subscribeFailed
in interfacerice.p2p.scribe.ScribeMultiClient
-
subscribeSuccess
public void subscribeSuccess(java.util.Collection<rice.p2p.scribe.Topic> topics)- Specified by:
subscribeSuccess
in interfacerice.p2p.scribe.ScribeMultiClient
-
getAgentTopicId
generate an id string for topic corresponding to a l2p agent- Parameters:
agent
- An agent to generate topic id- Returns:
- a topic identifier for the agent to subscribe to
-
getAgentTopicId
public static java.lang.String getAgentTopicId(java.lang.String id)generate an id string for topic corresponding to a l2p agent- Parameters:
id
- An agent id to generate topic id- Returns:
- a topic identifier for the agent to subscribe to
-
anycast
public boolean anycast(rice.p2p.scribe.Topic topic, rice.p2p.scribe.ScribeContent content)- Specified by:
anycast
in interfacerice.p2p.scribe.ScribeClient
- Specified by:
anycast
in interfacerice.p2p.scribe.ScribeMultiClient
-