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 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 Details

  • Constructor Details

    • NodeApplication

      public NodeApplication(PastryNodeImpl node)
      create a pastry application for the given node
      Parameters:
      node - A node to wrap around
  • Method Details

    • registerAgentTopic

      public void registerAgentTopic(MessageReceiver receiver)
      register this node to the topic related to the given message receiver
      Parameters:
      receiver - A message receiver
    • unregisterAgentTopic

      public void unregisterAgentTopic(String id) throws AgentNotRegisteredException
      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

      public void unregisterTopic(long id) throws NodeException
      Throws:
      NodeException
    • getNodeInformation

      public NodeInformation getNodeInformation(rice.p2p.commonapi.NodeHandle nodeHandle) throws NodeNotFoundException
      get 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 interface rice.p2p.commonapi.Application
    • forward

      public boolean forward(rice.p2p.commonapi.RouteMessage pastMessage)
      Specified by:
      forward in interface rice.p2p.commonapi.Application
    • update

      public void update(rice.p2p.commonapi.NodeHandle nh, boolean arg1)
      Specified by:
      update in interface rice.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 MalformedXMLException
      send a message to the given node handle
      Parameters:
      m - A message to send
      to - 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 send
      to - A target node handle
    • sendMessage

      public void sendMessage(Message l2pMessage)
      broadcast a Message 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 interface rice.p2p.scribe.ScribeClient
      Specified by:
      childAdded in interface rice.p2p.scribe.ScribeMultiClient
    • childRemoved

      public void childRemoved(rice.p2p.scribe.Topic topic, rice.p2p.commonapi.NodeHandle nh)
      Specified by:
      childRemoved in interface rice.p2p.scribe.ScribeClient
      Specified by:
      childRemoved in interface rice.p2p.scribe.ScribeMultiClient
    • searchAgent

      public Collection<rice.p2p.commonapi.NodeHandle> searchAgent(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 for
      expectedAnswers - Amount of expected answers
      Returns:
      a collections of node handles where the requested agent is registered to
    • searchAgent

      public Collection<rice.p2p.commonapi.NodeHandle> searchAgent(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 interface rice.p2p.scribe.ScribeClient
      Specified by:
      deliver in interface rice.p2p.scribe.ScribeMultiClient
    • subscribeFailed

      public void subscribeFailed(rice.p2p.scribe.Topic topic)
      Specified by:
      subscribeFailed in interface rice.p2p.scribe.ScribeClient
      Specified by:
      subscribeFailed in interface rice.p2p.scribe.ScribeMultiClient
    • subscribeFailed

      public void subscribeFailed(Collection<rice.p2p.scribe.Topic> topics)
      Specified by:
      subscribeFailed in interface rice.p2p.scribe.ScribeMultiClient
    • subscribeSuccess

      public void subscribeSuccess(Collection<rice.p2p.scribe.Topic> topics)
      Specified by:
      subscribeSuccess in interface rice.p2p.scribe.ScribeMultiClient
    • getAgentTopicId

      public static String getAgentTopicId(AgentImpl agent)
      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 String getAgentTopicId(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 interface rice.p2p.scribe.ScribeClient
      Specified by:
      anycast in interface rice.p2p.scribe.ScribeMultiClient