Class Node

All Implemented Interfaces:
L2pStorageInterface, NodeStorageInterface, AgentStorage
Direct Known Subclasses:
LocalNode, PastryNodeImpl

public abstract class Node extends Configurable implements AgentStorage, NodeStorageInterface
Base class for nodes in the las2peer environment. A Node represents one enclosed unit in the network hosting an arbitrary number of agents willing to participate in the P2P networking.
  • Field Details

    • DEFAULT_CPU_LOAD_TRESHOLD

      public static final double DEFAULT_CPU_LOAD_TRESHOLD
      See Also:
    • DEFAULT_NODE_SERVICE_CACHE_LIFETIME

      public static final int DEFAULT_NODE_SERVICE_CACHE_LIFETIME
      See Also:
    • DEFAULT_NODE_SERVICE_CACHE_RESULT_COUNT

      public static final int DEFAULT_NODE_SERVICE_CACHE_RESULT_COUNT
      See Also:
    • DEFAULT_TIDY_UP_TIMER_INTERVAL

      public static final int DEFAULT_TIDY_UP_TIMER_INTERVAL
      See Also:
    • DEFAULT_AGENT_CONTEXT_LIFETIME

      public static final int DEFAULT_AGENT_CONTEXT_LIFETIME
      See Also:
    • DEFAULT_INVOCATION_RETRY_COUNT

      public static final int DEFAULT_INVOCATION_RETRY_COUNT
      See Also:
  • Constructor Details

    • Node

      public Node(boolean standardObserver)
      Creates a new node, if the standardObserver flag is true, an observer logging all events to a simple plain text log file will be generated. If not, no observer will be used at startup.
      Parameters:
      standardObserver - If true, the node uses the default logger.
    • Node

      public Node()
      Creates a new node with a standard plain text log file observer.
    • Node

      public Node(ClassManager classManager)
      Parameters:
      classManager - A default class loader used by this node.
    • Node

      public Node(ClassManager classManager, boolean standardObserver)
      Parameters:
      classManager - A default class loader used by this node.
      standardObserver - If true, the node uses the default logger.
    • Node

      public Node(ClassManager classManager, boolean standardObserver, boolean monitoringObserver)
      Generates a new Node with the given baseClassLoader. The Observer-flags determine, which observers will be registered at startup.
      Parameters:
      classManager - A default class loader used by this node.
      standardObserver - If true, the node uses the default logger.
      monitoringObserver - If true, the monitoring is enabled for this node.
  • Method Details

    • addObserver

      public void addObserver(NodeObserver observer)
      Adds an observer to this node.
      Parameters:
      observer - The observer that should be notified.
    • removeObserver

      public void removeObserver(NodeObserver observer)
      Removes an observer from this node.
      Parameters:
      observer - The observer that should be removed.
    • setServiceMonitoring

      public void setServiceMonitoring(ServiceAgentImpl service)
      Enables the service monitoring for the requested Service.
      Parameters:
      service - The service that should be monitored.
    • observerNotice

      public void observerNotice(MonitoringEvent event, String remarks)
      Logs an event to all observers.
      Parameters:
      event - The event for this notification.
      remarks - Some free text note or description about this event.
    • observerNotice

      public void observerNotice(MonitoringEvent event, Object sourceNode, String remarks)
      Logs an event to all observers.
      Parameters:
      event - The event for this notification.
      sourceNode - A source node for this event
      remarks - Some free text note or description about this event.
    • observerNotice

      public void observerNotice(MonitoringEvent event, Object sourceNode, String sourceAgentId, String remarks)
      Logs an event to all observers.
      Parameters:
      event - The event for this notification.
      sourceNode - A source node for this event
      sourceAgentId - A source agent id for this event
      remarks - Some free text note or description about this event.
    • observerNotice

      public void observerNotice(MonitoringEvent event, Object sourceNode, MessageReceiver sourceAgent, String remarks)
      Logs an event to all observers.
      Parameters:
      event - The event for this notification.
      sourceNode - A source node for this event
      sourceAgent - A source agent for this event
      remarks - Some free text note or description about this event.
    • observerNotice

      public void observerNotice(MonitoringEvent event, Object sourceNode, Agent sourceAgent, Object destinationNode, Agent destinationAgent, String remarks)
      Logs an event to all observers.
      Parameters:
      event - The event for this notification.
      sourceNode - A source node for this event
      sourceAgent - A source agent for this event
      destinationNode - A destination node for this event
      destinationAgent - A destination agent for this event
      remarks - Some free text note or description about this event.
    • observerNotice

      public void observerNotice(MonitoringEvent event, Object sourceNode, String sourceAgentId, Object destinationNode, String destinationAgentId, String remarks)
      Logs an event to all observers.
      Parameters:
      event - The event for this notification.
      sourceNode - A source node for this event
      sourceAgentId - A source agent id for this event
      destinationNode - A destination node for this event
      destinationAgentId - A destination agent id for this event
      remarks - Some free text note or description about this event.
    • observerNotice

      public void observerNotice(MonitoringEvent event, Object sourceNode, String sourceAgentId, Object destinationNode, String destinationAgentId, String remarks, String caseId, String activityName, String resourceId, String resourceType)
      Logs an event to all observers.
      Parameters:
      event - The event for this notification.
      sourceNode - A source node for this event
      sourceAgentId - A source agent id for this event
      destinationNode - A destination node for this event
      destinationAgentId - A destination agent id for this event
      remarks - Some free text note or description about this event.
      caseId - caseId of the event
      activityName - activityName of the event
      resourceId - resourceId of the event
      resourceType - resourceType of the event
    • observerNotice

      public void observerNotice(MonitoringEvent event, Object sourceNode, String sourceAgentId, Object destinationNode, String destinationAgentId, String remarks, String caseId, String activityName, String resourceId, String resourceType, String lifecyclePhase, Long timeOfEvent)
      Logs an event to all observers.
      Parameters:
      event - The event for this notification.
      sourceNode - A source node for this event
      sourceAgentId - A source agent id for this event
      destinationNode - A destination node for this event
      destinationAgentId - A destination agent id for this event
      remarks - Some free text note or description about this event.
      caseId - caseId of the event
      activityName - activityName of the event
      resourceId - resourceId of the event
      resourceType - resourceType of the event
    • getNodeRepresentation

      protected String getNodeRepresentation(Object node)
      Derive a String representation for a node from the given identifier object. The type of the object depends on the setting of the current node. Tries to specify an ip address and a port for an actual p2p node (PastryNodeImpl or NodeHandle).
      Parameters:
      node - The node that should be represented.
      Returns:
      string representation for the given node object
    • getStatus

      public Node.NodeStatus getStatus()
      Gets the status of this node.
      Returns:
      status of this node
    • getNodeId

      public abstract Serializable getNodeId()
      Gets some kind of node identifier.
      Returns:
      id of this node
    • getBaseClassLoader

      public ClassManager getBaseClassLoader()
      Gets the class loader, this node is bound to. In a real las2peer environment, this should refer to a ClassManager Otherwise, the class loader of this Node class is used.
      Returns:
      a class loader
    • setStatus

      protected void setStatus(Node.NodeStatus newstatus)
      Sets the status of this node.
      Parameters:
      newstatus - The new status for this node.
    • getInformationFilename

      public String getInformationFilename()
      Gets the filename of the current information file for this node. The file should be an XML file representation of a NodeInformation.
      Returns:
      filename
    • setInformationFilename

      public void setInformationFilename(String filename)
      Sets the nodes information filename.
      Parameters:
      filename - The filename for the information file.
    • getNodeInformation

      public NodeInformation getNodeInformation() throws CryptoException
      Gets information about this node including all registered service classes.
      Returns:
      node information
      Throws:
      CryptoException - If an issue occurs with the given key or selected algorithm.
    • getNodeInformation

      public abstract NodeInformation getNodeInformation(Object nodeId) throws NodeNotFoundException
      Gets information about a distant node.
      Parameters:
      nodeId - A node id to query
      Returns:
      information about the node
      Throws:
      NodeNotFoundException - If the node was not found
    • getOtherKnownNodes

      public abstract Object[] getOtherKnownNodes()
      Gets an array with identifiers of other (locally known) nodes in this network.
      Returns:
      array with handles of other (known) p2p network nodes
    • launchSub

      protected abstract void launchSub() throws NodeException
      Starts this node.
      Throws:
      NodeException - If launching the node fails
    • launch

      public final void launch() throws NodeException
      Starts this node.
      Throws:
      NodeException - If launching the node fails
    • shutDown

      public void shutDown()
      Stops the node.
    • registerReceiver

      public void registerReceiver(MessageReceiver receiver) throws AgentAlreadyRegisteredException, AgentException
      Registers a (local) Agent for usage through this node. The Agent has to be unlocked before registration.
      Parameters:
      receiver - A message receiver to register
      Throws:
      AgentAlreadyRegisteredException - the given agent is already registered to this node
      AgentLockedException - the agent is not unlocked
      AgentException - any problem with the agent itself (probably on calling AgentImpl.notifyRegistrationTo(i5.las2peer.p2p.Node)
    • unregisterReceiver

      public void unregisterReceiver(MessageReceiver receiver) throws AgentNotRegisteredException, NodeException
      Unregisters a MessageReceiver from this node.
      Parameters:
      receiver - the receiver to unregister
      Throws:
      AgentNotRegisteredException - The given MessageReceiver is not registered to this node
      NodeException - error in underlying layer
    • registerReceiverToTopic

      public void registerReceiverToTopic(MessageReceiver receiver, long topic) throws AgentNotRegisteredException
      register a receiver to a topic
      Parameters:
      receiver - the MessageReceiver
      topic - the topic id
      Throws:
      AgentNotRegisteredException - The given MessageReceiver is not registered to this node
    • unregisterReceiverFromTopic

      public void unregisterReceiverFromTopic(MessageReceiver receiver, long topic) throws NodeException
      unregister a receiver from a topic
      Parameters:
      receiver - the receiver
      topic - the topic id
      Throws:
      NodeException - If unregistering fails
    • hasTopic

      protected boolean hasTopic(long topic)
      checks if a receiver is registered to the topic
      Parameters:
      topic - topic id
      Returns:
      true if someone is registered to the topic
    • hasLocalAgent

      public boolean hasLocalAgent(AgentImpl agent)
      Is an instance of the given agent running at this node?
      Parameters:
      agent - An agent to check for
      Returns:
      true, if the given agent is running at this node
    • hasLocalAgent

      public boolean hasLocalAgent(String agentId)
      Is an instance of the given agent running at this node?
      Parameters:
      agentId - An agent id to check for
      Returns:
      true, if the given agent is registered here
    • startService

      public ServiceAgentImpl startService(ServiceNameVersion nameVersion, String passphrase) throws CryptoException, AgentException
      Starts a new instance of the given service on this node. This creates, stores and registers a new service agent.
      Parameters:
      nameVersion - A service name and version to identify the service
      passphrase - A passphrase to secure this instance
      Returns:
      Returns the local service agent instance
      Throws:
      CryptoException
      AgentException
    • stopService

      Stops the local service instance.
      Parameters:
      nameVersion - A service name and version to identify the service
      Throws:
      AgentNotRegisteredException - If the service is not registered locally
      ServiceNotFoundException - If the service is not known locally
      NodeException
    • stopService

      public void stopService(ServiceAgentImpl serviceAgent) throws AgentNotRegisteredException, NodeException
      Stops the local service instance.
      Parameters:
      serviceAgent -
      Throws:
      AgentNotRegisteredException - If the service is not registered locally
      NodeException
    • sendMessage

      public void sendMessage(Message message, MessageResultListener listener)
      Sends a message, recipient and sender are stated in the message. The node tries to find a node hosting the recipient and sends the message there.
      Parameters:
      message - the message to send
      listener - a listener for getting the result separately
    • sendMessage

      public abstract void sendMessage(Message message, MessageResultListener listener, Node.SendMode mode)
      Sends a message, recipient and sender are stated in the message. Depending on the mode, either all nodes running the given agent will be notified of this message, or only a random one. NOTE: Pastry nodes will always use broadcast at the moment!
      Parameters:
      message - the message to send
      listener - a listener for getting the result separately
      mode - is it a broadcast or an any-cast message?
    • sendMessage

      public abstract void sendMessage(Message message, Object atNodeId, MessageResultListener listener) throws NodeNotFoundException
      Sends a message to the agent residing at the given node.
      Parameters:
      message - A message to send
      atNodeId - A node id to send from
      listener - a listener for getting the result separately
      Throws:
      NodeNotFoundException - If the node was not found
    • sendResponse

      public void sendResponse(Message message, Object atNodeId) throws NodeNotFoundException
      Sends the given response message to the given node.
      Parameters:
      message - A message to send
      atNodeId - A node id to send from
      Throws:
      NodeNotFoundException - If the node was not found
    • receiveMessage

      public void receiveMessage(Message message) throws AgentNotRegisteredException, AgentException, MessageException
      For external access to this node. Will be called by the (P2P) network library, when a new message has been received via the network and could not be handled otherwise.
      Parameters:
      message - A message that is received
      Throws:
      AgentNotRegisteredException - If the designated recipient is not known at this node
      AgentException - If any other issue with the agent occurs, e. g. XML not readable
      MessageException - If handling the message fails
    • fetchArtifact

      @Deprecated public abstract EnvelopeVersion fetchArtifact(long id) throws EnvelopeNotFoundException, EnvelopeException
      Deprecated.
      Use NodeStorageInterface.fetchEnvelope(String) instead Gets an artifact from the p2p storage.
      Parameters:
      id - An id to identify the envelope
      Returns:
      the envelope containing the requested artifact
      Throws:
      EnvelopeNotFoundException - If the envelope was not found
      EnvelopeException - If an issue with the envelope occurred
    • fetchArtifact

      @Deprecated public abstract EnvelopeVersion fetchArtifact(String identifier) throws EnvelopeNotFoundException, EnvelopeException
      Deprecated.
      Use NodeStorageInterface.fetchEnvelope(String) instead Gets an artifact from the p2p storage.
      Parameters:
      identifier - An identifier for the envelope
      Returns:
      the envelope containing the requested artifact
      Throws:
      EnvelopeNotFoundException - If the envelope was not found
      EnvelopeException - If an issue with the envelope occurred
    • storeArtifact

      @Deprecated public abstract void storeArtifact(EnvelopeVersion envelope) throws EnvelopeAlreadyExistsException, EnvelopeException
      Deprecated.
      Use NodeStorageInterface.storeEnvelope(EnvelopeVersion, AgentImpl) instead Stores an artifact to the p2p storage.
      Parameters:
      envelope - An envelope to store
      Throws:
      EnvelopeAlreadyExistsException - If the envelope already exists
      EnvelopeException - If an issue with the envelope occurred
    • removeArtifact

      @Deprecated public abstract void removeArtifact(long id, byte[] signature) throws EnvelopeNotFoundException, EnvelopeException
      Deprecated.
      Use L2pStorageInterface.removeEnvelope(String) instead Removes an artifact from the p2p storage. NOTE: This is not possible with a FreePastry backend!
      Parameters:
      id - An identifier for the artifact
      signature - A signature to use
      Throws:
      EnvelopeNotFoundException - If the envelope was not found
      EnvelopeException - If an issue with the envelope occurred
    • findRegisteredAgent

      public abstract Object[] findRegisteredAgent(String agentId, int hintOfExpectedCount) throws AgentNotRegisteredException
      Searches the nodes for registered Versions of the given Agent. Returns an array of objects identifying the nodes the given agent is registered to.
      Parameters:
      agentId - id of the agent to look for
      hintOfExpectedCount - a hint for the expected number of results (e.g. to wait for)
      Returns:
      array with the IDs of nodes, where the given agent is registered
      Throws:
      AgentNotRegisteredException - If the agent is not registered at this node
    • findRegisteredAgent

      public Object[] findRegisteredAgent(AgentImpl agent) throws AgentNotRegisteredException
      Search the nodes for registered versions of the given agent. Returns an array of objects identifying the nodes the given agent is registered to.
      Parameters:
      agent - An agent to find
      Returns:
      array with the IDs of nodes, where the given agent is registered
      Throws:
      AgentNotRegisteredException - If the agent is not registered at this node
    • findRegisteredAgent

      public Object[] findRegisteredAgent(String agentId) throws AgentNotRegisteredException
      Searches the nodes for registered versions of the given agentId. Returns an array of objects identifying the nodes the given agent is registered to.
      Parameters:
      agentId - id of the agent to look for
      Returns:
      array with the IDs of nodes, where the given agent is registered
      Throws:
      AgentNotRegisteredException - If the agent is not registered at this node
    • findRegisteredAgent

      public Object[] findRegisteredAgent(AgentImpl agent, int hintOfExpectedCount) throws AgentNotRegisteredException
      searches the nodes for registered versions of the given agent. Returns an array of objects identifying the nodes the given agent is registered to.
      Parameters:
      agent - An agent to look for
      hintOfExpectedCount - a hint for the expected number of results (e.g. to wait for)
      Returns:
      array with the IDs of nodes, where the given agent is registered
      Throws:
      AgentNotRegisteredException - If the agent is not registered at this node
    • getAgent

      public abstract AgentImpl getAgent(String id) throws AgentNotFoundException, AgentException
      Gets an agent description from the net. make sure, always to return fresh versions of the requested agent, so that no thread can unlock the private key for another one!
      Specified by:
      getAgent in interface AgentStorage
      Parameters:
      id - An agent id
      Returns:
      the requested agent
      Throws:
      AgentNotFoundException - If the agent is not found
      AgentException - If any other issue with the agent occurs, e. g. XML not readable
    • hasAgent

      public boolean hasAgent(String id) throws AgentException
      Description copied from interface: AgentStorage
      does this storage know the requested agent? Does not refer to the backup storage if applicable
      Specified by:
      hasAgent in interface AgentStorage
      Returns:
      true, if this storage knows an agent of the given id
      Throws:
      AgentException - AgentException If any issue with the agent occurs, e. g. XML not readable
    • getLocalAgent

      public AgentImpl getLocalAgent(String id) throws AgentNotRegisteredException
      Gets a local registered agent by its id.
      Parameters:
      id - An agent id
      Returns:
      the agent registered to this node
      Throws:
      AgentNotRegisteredException - If the agent is not found at this node
    • getRegisteredAgents

      public UserAgentImpl[] getRegisteredAgents()
      Gets an array with all UserAgentImpls registered at this node.
      Returns:
      all local registered UserAgents
    • getRegisteredServices

      public ServiceAgentImpl[] getRegisteredServices()
      Gets an array with all ServiceAgentImpls registered at this node.
      Returns:
      all local registered ServiceAgents
    • createMediatorForAgent

      public Mediator createMediatorForAgent(AgentImpl agent) throws AgentLockedException, AgentAlreadyRegisteredException
      Gets a local registered mediator for the given agent id. If no mediator exists, registers a new one to this node.
      Parameters:
      agent - An agent to mediate
      Returns:
      the mediator for the given agent
      Throws:
      AgentLockedException - If the agent is locked.
      AgentAlreadyRegisteredException - If the agent is already directly registered at this node
    • storeAgent

      public abstract void storeAgent(AgentImpl agent) throws AgentException
      Stores a new Agent to the network.
      Parameters:
      agent - An agent to store
      Throws:
      AgentException - If any issue with the agent occurs
    • updateAgent

      @Deprecated public abstract void updateAgent(AgentImpl agent) throws AgentException
      Deprecated.
      Updates an existing agent of the network.
      Parameters:
      agent - An agent to update
      Throws:
      AgentException - If any issue with the agent occurs
    • getUserManager

      public UserAgentManager getUserManager()
      returns the manager responsible for user management
      Returns:
      this node's user manager
    • getAgentIdForLogin

      public String getAgentIdForLogin(String login) throws AgentNotFoundException, AgentOperationFailedException
      Gets an id for the user for the given login name.
      Parameters:
      login - A login name to identify agent
      Returns:
      agent id
      Throws:
      AgentNotFoundException - If no agent for the given login is found
      AgentOperationFailedException - If any other issue with the agent occurs, e. g. XML not readable
    • getAgentIdForEmail

      public String getAgentIdForEmail(String email) throws AgentNotFoundException, AgentOperationFailedException
      Gets an id for the user for the given email address.
      Parameters:
      email - An email address to identify agent
      Returns:
      agent id
      Throws:
      AgentNotFoundException - If no agent for the given email is found
      AgentOperationFailedException - If any other issue with the agent occurs, e. g. XML not readable
    • getAgentIdForGroupName

      public String getAgentIdForGroupName(String groupName) throws AgentNotFoundException, AgentOperationFailedException
      Gets an id for the group for the given group name.
      Parameters:
      groupName - The name of the group
      Returns:
      agent id
      Throws:
      AgentNotFoundException - If no agent for the given name is found
      AgentOperationFailedException - If any other issue with the agent occurs, e. g. XML not readable
    • getServiceAliasManager

      public ServiceAliasManager getServiceAliasManager()
      get the manager responsible for the mapping from service alias to service names
      Returns:
      Returns the ServiceAliasManager instance of this node
    • getServiceAgent

      public ServiceAgentImpl getServiceAgent(ServiceNameVersion service, AgentImpl acting) throws AgentException
      Gets an currently running agent executing the given service. Prefer using a locally registered agent.
      Parameters:
      service - service to be invoked
      acting - agent
      Returns:
      the ServiceAgent responsible for the given service class
      Throws:
      AgentException - If any issue with the agent occurs, e. g. not found, XML not readable
    • invoke

      public Serializable invoke(AgentImpl executing, String service, String method, Serializable[] parameters) throws AgentLockedException, ServiceInvocationException
      invoke a service in the network
      Parameters:
      executing - the executing agent
      service - service to be invoked
      method - service method
      parameters - invocation parameters
      Returns:
      Returns the invocation result
      Throws:
      ServiceInvocationException - If service invocation fails
      AgentLockedException - If the executing agent was locked
    • invoke

      public Serializable invoke(AgentImpl executing, ServiceNameVersion service, String method, Serializable[] parameters) throws AgentLockedException, ServiceInvocationException
      invoke a service in the network (choosing an appropriate version)
      Parameters:
      executing - the executing agent
      service - service to be invoked
      method - service method
      parameters - invocation parameters
      Returns:
      Returns the invocation result
      Throws:
      ServiceInvocationException - If service invocation fails
      AgentLockedException - If the executing agent was locked
    • invoke

      public Serializable invoke(AgentImpl executing, ServiceNameVersion service, String method, Serializable[] parameters, boolean exactVersion) throws AgentLockedException, ServiceInvocationException
      invoke a service in the network or locally
      Parameters:
      executing - the executing agent
      service - service to be invoked
      method - service method
      parameters - invocation parameters
      exactVersion - if true, an exact version match is required, otherwise, an appropriate version will be chosen
      Returns:
      Returns the invocation result
      Throws:
      ServiceInvocationException - If service invocation fails
      AgentLockedException - If the executing agent was locked
    • invoke

      public Serializable invoke(AgentImpl executing, ServiceNameVersion service, String method, Serializable[] parameters, boolean exactVersion, boolean localOnly) throws ServiceInvocationException, AgentLockedException
      invoke a service method
      Parameters:
      executing - the executing agent
      service - service to be invoked
      method - service method
      parameters - invocation parameters
      exactVersion - if true, an exact version match is required, otherwise, an appropriate version will be chosen
      localOnly - if true, only locally running services are executed
      Returns:
      Returns the invocation result
      Throws:
      ServiceInvocationException - If service invocation fails
      AgentLockedException - If the executing agent was locked
    • invokeLocally

      public Serializable invokeLocally(AgentImpl executing, ServiceAgentImpl serviceAgent, String method, Serializable[] parameters) throws ServiceInvocationException, AgentLockedException
      invokes a locally running service agent preferably, use invoke(AgentImpl, ServiceNameVersion, String, Serializable[], boolean, boolean)
      Parameters:
      executing - the executing agent
      serviceAgent - the service agent that should be invoked (must run on this node)
      method - service method
      parameters - method parameters
      Returns:
      innovation result
      Throws:
      ServiceInvocationException - If service invocation fails
      AgentLockedException - If the executing agent was locked
    • invokeGlobally

      public Serializable invokeGlobally(AgentImpl executing, String serviceAgentId, Object nodeId, String method, Serializable[] parameters) throws ServiceInvocationException, AgentLockedException
      invokes a service instance in the network preferably, use invoke(AgentImpl, ServiceNameVersion, String, Serializable[], boolean, boolean)
      Parameters:
      executing - the executing agent
      serviceAgentId - the id of the service agent
      nodeId - id of the node running the agent (may be null)
      method - service method
      parameters - method parameters
      Returns:
      invocation result
      Throws:
      ServiceInvocationException - If service invocation fails
      AgentLockedException - If the executing agent is locked
    • getLocalServiceAgent

      public ServiceAgentImpl getLocalServiceAgent(ServiceNameVersion service) throws ServiceNotFoundException
      Tries to get an instance of the given class as a registered service of this node.
      Parameters:
      service - A service name and version to check for
      Returns:
      the instance of the given service class running at this node
      Throws:
      ServiceNotFoundException - If the service is not found
    • registerAnswerListener

      public void registerAnswerListener(long messageId, MessageResultListener listener)
      Registers a MessageResultListener for collecting answers.
      Parameters:
      messageId - A message id to register for
      listener - An answer listener
    • handoverAnswer

      public boolean handoverAnswer(Message answer)
      Hands over an answer message to the corresponding listener.
      Parameters:
      answer - A answer message to handle
      Returns:
      true, if a listener for this answer was notified
    • sendMessageAndWaitForAnswer

      public Message sendMessageAndWaitForAnswer(Message m) throws InterruptedException, TimeoutException
      Sends a message and wait for one answer message.
      Parameters:
      m - A message to send
      Returns:
      a (possible) response message
      Throws:
      InterruptedException - If sending the message was interrupted
      TimeoutException - If sending the message timeouts
    • sendMessageAndWaitForAnswer

      public Message sendMessageAndWaitForAnswer(Message m, Object atNodeId) throws NodeNotFoundException, InterruptedException, TimeoutException
      Sends a message to the given id and wait for one answer message.
      Parameters:
      m - A message to send
      atNodeId - A node id to send from
      Returns:
      a response message
      Throws:
      NodeNotFoundException - If no node was not found with given id
      InterruptedException - If sending the message was interrupted
      TimeoutException - If sending the message timeouts
    • sendMessageAndCollectAnswers

      public Message[] sendMessageAndCollectAnswers(Message m, int recipientCount) throws InterruptedException, TimeoutException
      Sends a message and wait for answer messages Uses a broadcast
      Parameters:
      m - A message to send
      recipientCount - expected number of answers
      Returns:
      Returns an array with all collected answers
      Throws:
      InterruptedException - If sending the message was interrupted
      TimeoutException - If sending the message timeouts
    • getAgentContext

      public AgentContext getAgentContext(String agentId) throws AgentException
      Gets the local execution context of an agent. If there is currently none, a new one will be created and stored for later use.
      Parameters:
      agentId - An agent id to get the context for
      Returns:
      the context for the given agent
      Throws:
      AgentException - If any issue with the agent occurs, e. g. XML not readable
    • getAgentContext

      public AgentContext getAgentContext(AgentImpl agent)
      Gets a (possibly fresh) context for the given agent.
      Parameters:
      agent - An agent to get the context for
      Returns:
      Returns a context
    • hasService

      public boolean hasService(ServiceNameVersion service)
      Checks, if the given service class is running at this node.
      Parameters:
      service - A service name and version to check for
      Returns:
      true, if this node as an instance of the given service running
    • getNodeServiceCache

      public NodeServiceCache getNodeServiceCache()
      get the NodeServiceCache of this node
      Returns:
      Returns the NodeServiceCache instance for this node
    • getNodeCpuLoad

      public double getNodeCpuLoad()
      Gets the approximate CPU load of the JVM the Node is running on. Correct value only available a few seconds after the start of the Node.
      Returns:
      value between 0 and 1: CPU load of the JVM process running this node
    • isBusy

      public boolean isBusy()
    • setCpuLoadThreshold

      public void setCpuLoadThreshold(double cpuLoadThreshold)
    • getNodeRAMLoad

      public long getNodeRAMLoad()
      Gets the approximate RAM load of the JVM the Node is running on.
      Returns:
      the total amount of memory currently available for current and future objects, measured in bytes.
    • getNodeFreeRAMLoad

      public long getNodeFreeRAMLoad()
    • runTidyUpTimer

      protected void runTidyUpTimer()
      executed by the tidy up timer, currently it does: Deleting old AgentContext objects from htLocalExecutionContexts
    • getStartTime

      public Date getStartTime()