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.Endpointendpointstatic java.lang.StringFREEPASTRY_APPLICATION_CODEstatic java.lang.StringSCRIBE_APPLICATION_CODEstatic intSEARCH_SLEEP_TIMEstatic longSEARCH_TIMEOUT -
Constructor Summary
Constructors Constructor Description NodeApplication(PastryNodeImpl node)create a pastry application for the given node -
Method Summary
Modifier and Type Method Description booleananycast(rice.p2p.scribe.Topic topic, rice.p2p.scribe.ScribeContent content)voidchildAdded(rice.p2p.scribe.Topic topic, rice.p2p.commonapi.NodeHandle nh)voidchildRemoved(rice.p2p.scribe.Topic topic, rice.p2p.commonapi.NodeHandle nh)voiddeliver(rice.p2p.commonapi.Id id, rice.p2p.commonapi.Message pastMessage)voiddeliver(rice.p2p.scribe.Topic topic, rice.p2p.scribe.ScribeContent content)booleanforward(rice.p2p.commonapi.RouteMessage pastMessage)static java.lang.StringgetAgentTopicId(AgentImpl agent)generate an id string for topic corresponding to a l2p agentstatic java.lang.StringgetAgentTopicId(java.lang.String id)generate an id string for topic corresponding to a l2p agentNodeInformationgetNodeInformation(rice.p2p.commonapi.NodeHandle nodeHandle)get information about a foreign nodevoidregisterAgentTopic(MessageReceiver receiver)register this node to the topic related to the given message receivervoidregisterTopic(long id)voidrouteMyMsg(rice.p2p.commonapi.Id id)Called to route a message to the idvoidrouteMyMsgDirect(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.voidsendMessage(Message l2pMessage)broadcast aMessageto all running instances of its recipient agentvoidsendMessage(MessageEnvelope m, rice.p2p.commonapi.NodeHandle to)send a message to the given node handlevoidsendMessageDirectly(rice.p2p.commonapi.Message m, rice.p2p.commonapi.NodeHandle to)send a pastry message to the given nodevoidsubscribeFailed(java.util.Collection<rice.p2p.scribe.Topic> topics)voidsubscribeFailed(rice.p2p.scribe.Topic topic)voidsubscribeSuccess(java.util.Collection<rice.p2p.scribe.Topic> topics)voidunregisterAgentTopic(java.lang.String id)unregister an agent from its subscriptionvoidunregisterTopic(long id)voidupdate(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:
deliverin interfacerice.p2p.commonapi.Application
-
forward
public boolean forward(rice.p2p.commonapi.RouteMessage pastMessage)- Specified by:
forwardin interfacerice.p2p.commonapi.Application
-
update
public void update(rice.p2p.commonapi.NodeHandle nh, boolean arg1)- Specified by:
updatein 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 aMessageto 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:
childAddedin interfacerice.p2p.scribe.ScribeClient- Specified by:
childAddedin interfacerice.p2p.scribe.ScribeMultiClient
-
childRemoved
public void childRemoved(rice.p2p.scribe.Topic topic, rice.p2p.commonapi.NodeHandle nh)- Specified by:
childRemovedin interfacerice.p2p.scribe.ScribeClient- Specified by:
childRemovedin 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:
deliverin interfacerice.p2p.scribe.ScribeClient- Specified by:
deliverin interfacerice.p2p.scribe.ScribeMultiClient
-
subscribeFailed
public void subscribeFailed(rice.p2p.scribe.Topic topic)- Specified by:
subscribeFailedin interfacerice.p2p.scribe.ScribeClient- Specified by:
subscribeFailedin interfacerice.p2p.scribe.ScribeMultiClient
-
subscribeFailed
public void subscribeFailed(java.util.Collection<rice.p2p.scribe.Topic> topics)- Specified by:
subscribeFailedin interfacerice.p2p.scribe.ScribeMultiClient
-
subscribeSuccess
public void subscribeSuccess(java.util.Collection<rice.p2p.scribe.Topic> topics)- Specified by:
subscribeSuccessin 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:
anycastin interfacerice.p2p.scribe.ScribeClient- Specified by:
anycastin interfacerice.p2p.scribe.ScribeMultiClient
-