Package i5.las2peer.p2p
Class Node
java.lang.Object
i5.las2peer.api.Configurable
i5.las2peer.p2p.Node
- All Implemented Interfaces:
L2pStorageInterface
,NodeStorageInterface
,AgentStorage
- Direct Known Subclasses:
LocalNode
,PastryNodeImpl
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enum with the possible states of a node.static enum
The Sending mode for outgoing messages. -
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final double
static final int
static final int
static final int
static final int
-
Constructor Summary
ConstructorDescriptionNode()
Creates a new node with a standard plain text log file observer.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.Node
(ClassManager classManager) Node
(ClassManager classManager, boolean standardObserver) Node
(ClassManager classManager, boolean standardObserver, boolean monitoringObserver) Generates a new Node with the given baseClassLoader. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addObserver
(NodeObserver observer) Adds an observer to this node.createMediatorForAgent
(AgentImpl agent) Gets a local registered mediator for the given agent id.abstract EnvelopeVersion
fetchArtifact
(long id) Deprecated.abstract EnvelopeVersion
fetchArtifact
(String identifier) Deprecated.UseNodeStorageInterface.fetchEnvelope(String)
instead Gets an artifact from the p2p storage.Object[]
findRegisteredAgent
(AgentImpl agent) Search the nodes for registered versions of the given agent.Object[]
findRegisteredAgent
(AgentImpl agent, int hintOfExpectedCount) searches the nodes for registered versions of the given agent.Object[]
findRegisteredAgent
(String agentId) Searches the nodes for registered versions of the given agentId.abstract Object[]
findRegisteredAgent
(String agentId, int hintOfExpectedCount) Searches the nodes for registered Versions of the given Agent.abstract AgentImpl
Gets an agent description from the net.getAgentContext
(AgentImpl agent) Gets a (possibly fresh) context for the given agent.getAgentContext
(String agentId) Gets the local execution context of an agent.getAgentIdForEmail
(String email) Gets an id for the user for the given email address.getAgentIdForGroupName
(String groupName) Gets an id for the group for the given group name.getAgentIdForLogin
(String login) Gets an id for the user for the given login name.Gets the class loader, this node is bound to.Gets the filename of the current information file for this node.getLocalAgent
(String id) Gets a local registered agent by its id.getLocalServiceAgent
(ServiceNameVersion service) Tries to get an instance of the given class as a registered service of this node.double
Gets the approximate CPU load of the JVM the Node is running on.long
abstract Serializable
Gets some kind of node identifier.Gets information about this node including all registered service classes.abstract NodeInformation
getNodeInformation
(Object nodeId) Gets information about a distant node.long
Gets the approximate RAM load of the JVM the Node is running on.protected String
getNodeRepresentation
(Object node) Derive a String representation for a node from the given identifier object.get the NodeServiceCache of this nodeabstract Object[]
Gets an array with identifiers of other (locally known) nodes in this network.Gets an array with allUserAgentImpl
s registered at this node.Gets an array with allServiceAgentImpl
s registered at this node.getServiceAgent
(ServiceNameVersion service, AgentImpl acting) Gets an currently running agent executing the given service.get the manager responsible for the mapping from service alias to service namesGets the status of this node.returns the manager responsible for user managementboolean
handoverAnswer
(Message answer) Hands over an answer message to the corresponding listener.boolean
does this storage know the requested agent? Does not refer to the backup storage if applicableboolean
hasLocalAgent
(AgentImpl agent) Is an instance of the given agent running at this node?boolean
hasLocalAgent
(String agentId) Is an instance of the given agent running at this node?boolean
hasService
(ServiceNameVersion service) Checks, if the given service class is running at this node.protected boolean
hasTopic
(long topic) checks if a receiver is registered to the topicinvoke
(AgentImpl executing, ServiceNameVersion service, String method, Serializable[] parameters) invoke a service in the network (choosing an appropriate version)invoke
(AgentImpl executing, ServiceNameVersion service, String method, Serializable[] parameters, boolean exactVersion) invoke a service in the network or locallyinvoke
(AgentImpl executing, ServiceNameVersion service, String method, Serializable[] parameters, boolean exactVersion, boolean localOnly) invoke a service methodinvoke
(AgentImpl executing, String service, String method, Serializable[] parameters) invoke a service in the networkinvokeGlobally
(AgentImpl executing, String serviceAgentId, Object nodeId, String method, Serializable[] parameters) invokes a service instance in the network preferably, useinvoke(AgentImpl, ServiceNameVersion, String, Serializable[], boolean, boolean)
invokeLocally
(AgentImpl executing, ServiceAgentImpl serviceAgent, String method, Serializable[] parameters) invokes a locally running service agent preferably, useinvoke(AgentImpl, ServiceNameVersion, String, Serializable[], boolean, boolean)
boolean
isBusy()
final void
launch()
Starts this node.protected abstract void
Starts this node.void
observerNotice
(MonitoringEvent event, Object sourceNode, Agent sourceAgent, Object destinationNode, Agent destinationAgent, String remarks) Logs an event to all observers.void
observerNotice
(MonitoringEvent event, Object sourceNode, MessageReceiver sourceAgent, String remarks) Logs an event to all observers.void
observerNotice
(MonitoringEvent event, Object sourceNode, String remarks) Logs an event to all observers.void
observerNotice
(MonitoringEvent event, Object sourceNode, String sourceAgentId, Object destinationNode, String destinationAgentId, String remarks) Logs an event to all observers.void
observerNotice
(MonitoringEvent event, Object sourceNode, String sourceAgentId, String remarks) Logs an event to all observers.void
observerNotice
(MonitoringEvent event, String remarks) Logs an event to all observers.void
receiveMessage
(Message message) For external access to this node.void
registerAnswerListener
(long messageId, MessageResultListener listener) Registers a MessageResultListener for collecting answers.void
registerReceiver
(MessageReceiver receiver) Registers a (local) Agent for usage through this node.void
registerReceiverToTopic
(MessageReceiver receiver, long topic) register a receiver to a topicabstract void
removeArtifact
(long id, byte[] signature) Deprecated.UseL2pStorageInterface.removeEnvelope(String)
instead Removes an artifact from the p2p storage.void
removeObserver
(NodeObserver observer) Removes an observer from this node.protected void
executed by the tidy up timer, currently it does: Deleting oldAgentContext
objects fromhtLocalExecutionContexts
void
sendMessage
(Message message, MessageResultListener listener) Sends a message, recipient and sender are stated in the message.abstract void
sendMessage
(Message message, MessageResultListener listener, Node.SendMode mode) Sends a message, recipient and sender are stated in the message.abstract void
sendMessage
(Message message, Object atNodeId, MessageResultListener listener) Sends a message to the agent residing at the given node.Message[]
sendMessageAndCollectAnswers
(Message m, int recipientCount) Sends a message and wait for answer messages Uses a broadcastSends a message and wait for one answer message.sendMessageAndWaitForAnswer
(Message m, Object atNodeId) Sends a message to the given id and wait for one answer message.void
sendResponse
(Message message, Object atNodeId) Sends the given response message to the given node.void
setCpuLoadThreshold
(double cpuLoadThreshold) void
setInformationFilename
(String filename) Sets the nodes information filename.void
setServiceMonitoring
(ServiceAgentImpl service) Enables the service monitoring for the requested Service.protected void
setStatus
(Node.NodeStatus newstatus) Sets the status of this node.void
shutDown()
Stops the node.startService
(ServiceNameVersion nameVersion, String passphrase) Starts a new instance of the given service on this node.void
stopService
(ServiceNameVersion nameVersion) Stops the local service instance.void
stopService
(ServiceAgentImpl serviceAgent) Stops the local service instance.abstract void
storeAgent
(AgentImpl agent) Stores a new Agent to the network.abstract void
storeArtifact
(EnvelopeVersion envelope) Deprecated.UseNodeStorageInterface.storeEnvelope(EnvelopeVersion, AgentImpl)
instead Stores an artifact to the p2p storage.void
unregisterReceiver
(MessageReceiver receiver) Unregisters a MessageReceiver from this node.void
unregisterReceiverFromTopic
(MessageReceiver receiver, long topic) unregister a receiver from a topicabstract void
updateAgent
(AgentImpl agent) Deprecated.Methods inherited from class i5.las2peer.api.Configurable
getProperties, setFieldValues
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface i5.las2peer.persistency.L2pStorageInterface
createEnvelope, createEnvelope, createEnvelope, createEnvelope, createEnvelope, createUnencryptedEnvelope, createUnencryptedEnvelope, fetchEnvelope, fetchEnvelopeAsync, removeEnvelope, storeEnvelope, storeEnvelopeAsync
Methods inherited from interface i5.las2peer.persistency.NodeStorageInterface
fetchEnvelope, storeEnvelope
-
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
- Parameters:
classManager
- A default class loader used by this node.
-
Node
- Parameters:
classManager
- A default class loader used by this node.standardObserver
- If true, the node uses the default logger.
-
Node
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
Adds an observer to this node.- Parameters:
observer
- The observer that should be notified.
-
removeObserver
Removes an observer from this node.- Parameters:
observer
- The observer that should be removed.
-
setServiceMonitoring
Enables the service monitoring for the requested Service.- Parameters:
service
- The service that should be monitored.
-
observerNotice
Logs an event to all observers.- Parameters:
event
- The event for this notification.remarks
- Some free text note or description about this event.
-
observerNotice
Logs an event to all observers.- Parameters:
event
- The event for this notification.sourceNode
- A source node for this eventremarks
- 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 eventsourceAgentId
- A source agent id for this eventremarks
- 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 eventsourceAgent
- A source agent for this eventremarks
- 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 eventsourceAgent
- A source agent for this eventdestinationNode
- A destination node for this eventdestinationAgent
- A destination agent for this eventremarks
- 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 eventsourceAgentId
- A source agent id for this eventdestinationNode
- A destination node for this eventdestinationAgentId
- A destination agent id for this eventremarks
- Some free text note or description about this event.
-
getNodeRepresentation
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
orNodeHandle
).- Parameters:
node
- The node that should be represented.- Returns:
- string representation for the given node object
-
getStatus
Gets the status of this node.- Returns:
- status of this node
-
getNodeId
Gets some kind of node identifier.- Returns:
- id of this node
-
getBaseClassLoader
Gets the class loader, this node is bound to. In a real las2peer environment, this should refer to aClassManager
Otherwise, the class loader of this Node class is used.- Returns:
- a class loader
-
setStatus
Sets the status of this node.- Parameters:
newstatus
- The new status for this node.
-
getInformationFilename
Gets the filename of the current information file for this node. The file should be an XML file representation of aNodeInformation
.- Returns:
- filename
-
setInformationFilename
Sets the nodes information filename.- Parameters:
filename
- The filename for the information file.
-
getNodeInformation
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
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
Gets an array with identifiers of other (locally known) nodes in this network.- Returns:
- array with handles of other (known) p2p network nodes
-
launchSub
Starts this node.- Throws:
NodeException
- If launching the node fails
-
launch
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 nodeAgentLockedException
- the agent is not unlockedAgentException
- any problem with the agent itself (probably on callingAgentImpl.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 nodeNodeException
- error in underlying layer
-
registerReceiverToTopic
public void registerReceiverToTopic(MessageReceiver receiver, long topic) throws AgentNotRegisteredException register a receiver to a topic- Parameters:
receiver
- the MessageReceivertopic
- the topic id- Throws:
AgentNotRegisteredException
- The given MessageReceiver is not registered to this node
-
unregisterReceiverFromTopic
unregister a receiver from a topic- Parameters:
receiver
- the receivertopic
- 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
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
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 servicepassphrase
- A passphrase to secure this instance- Returns:
- Returns the local service agent instance
- Throws:
CryptoException
AgentException
-
stopService
public void stopService(ServiceNameVersion nameVersion) throws AgentNotRegisteredException, ServiceNotFoundException, NodeException Stops the local service instance.- Parameters:
nameVersion
- A service name and version to identify the service- Throws:
AgentNotRegisteredException
- If the service is not registered locallyServiceNotFoundException
- If the service is not known locallyNodeException
-
stopService
public void stopService(ServiceAgentImpl serviceAgent) throws AgentNotRegisteredException, NodeException Stops the local service instance.- Parameters:
serviceAgent
-- Throws:
AgentNotRegisteredException
- If the service is not registered locallyNodeException
-
sendMessage
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 sendlistener
- 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 sendlistener
- a listener for getting the result separatelymode
- 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 sendatNodeId
- A node id to send fromlistener
- a listener for getting the result separately- Throws:
NodeNotFoundException
- If the node was not found
-
sendResponse
Sends the given response message to the given node.- Parameters:
message
- A message to sendatNodeId
- 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 nodeAgentException
- If any other issue with the agent occurs, e. g. XML not readableMessageException
- If handling the message fails
-
fetchArtifact
@Deprecated public abstract EnvelopeVersion fetchArtifact(long id) throws EnvelopeNotFoundException, EnvelopeException Deprecated.UseNodeStorageInterface.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 foundEnvelopeException
- If an issue with the envelope occurred
-
fetchArtifact
@Deprecated public abstract EnvelopeVersion fetchArtifact(String identifier) throws EnvelopeNotFoundException, EnvelopeException Deprecated.UseNodeStorageInterface.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 foundEnvelopeException
- If an issue with the envelope occurred
-
storeArtifact
@Deprecated public abstract void storeArtifact(EnvelopeVersion envelope) throws EnvelopeAlreadyExistsException, EnvelopeException Deprecated.UseNodeStorageInterface.storeEnvelope(EnvelopeVersion, AgentImpl)
instead Stores an artifact to the p2p storage.- Parameters:
envelope
- An envelope to store- Throws:
EnvelopeAlreadyExistsException
- If the envelope already existsEnvelopeException
- If an issue with the envelope occurred
-
removeArtifact
@Deprecated public abstract void removeArtifact(long id, byte[] signature) throws EnvelopeNotFoundException, EnvelopeException Deprecated.UseL2pStorageInterface.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 artifactsignature
- A signature to use- Throws:
EnvelopeNotFoundException
- If the envelope was not foundEnvelopeException
- 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 forhintOfExpectedCount
- 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
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
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 forhintOfExpectedCount
- 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
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 interfaceAgentStorage
- Parameters:
id
- An agent id- Returns:
- the requested agent
- Throws:
AgentNotFoundException
- If the agent is not foundAgentException
- If any other issue with the agent occurs, e. g. XML not readable
-
hasAgent
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 interfaceAgentStorage
- 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
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
Gets an array with allUserAgentImpl
s registered at this node.- Returns:
- all local registered UserAgents
-
getRegisteredServices
Gets an array with allServiceAgentImpl
s 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
Stores a new Agent to the network.- Parameters:
agent
- An agent to store- Throws:
AgentException
- If any issue with the agent occurs
-
updateAgent
Deprecated.Updates an existing agent of the network.- Parameters:
agent
- An agent to update- Throws:
AgentException
- If any issue with the agent occurs
-
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 foundAgentOperationFailedException
- 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 foundAgentOperationFailedException
- 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 foundAgentOperationFailedException
- If any other issue with the agent occurs, e. g. XML not readable
-
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 invokedacting
- 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 agentservice
- service to be invokedmethod
- service methodparameters
- invocation parameters- Returns:
- Returns the invocation result
- Throws:
ServiceInvocationException
- If service invocation failsAgentLockedException
- 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 agentservice
- service to be invokedmethod
- service methodparameters
- invocation parameters- Returns:
- Returns the invocation result
- Throws:
ServiceInvocationException
- If service invocation failsAgentLockedException
- 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 agentservice
- service to be invokedmethod
- service methodparameters
- invocation parametersexactVersion
- 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 failsAgentLockedException
- 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 agentservice
- service to be invokedmethod
- service methodparameters
- invocation parametersexactVersion
- if true, an exact version match is required, otherwise, an appropriate version will be chosenlocalOnly
- if true, only locally running services are executed- Returns:
- Returns the invocation result
- Throws:
ServiceInvocationException
- If service invocation failsAgentLockedException
- 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, useinvoke(AgentImpl, ServiceNameVersion, String, Serializable[], boolean, boolean)
- Parameters:
executing
- the executing agentserviceAgent
- the service agent that should be invoked (must run on this node)method
- service methodparameters
- method parameters- Returns:
- innovation result
- Throws:
ServiceInvocationException
- If service invocation failsAgentLockedException
- 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, useinvoke(AgentImpl, ServiceNameVersion, String, Serializable[], boolean, boolean)
- Parameters:
executing
- the executing agentserviceAgentId
- the id of the service agentnodeId
- id of the node running the agent (may be null)method
- service methodparameters
- method parameters- Returns:
- invocation result
- Throws:
ServiceInvocationException
- If service invocation failsAgentLockedException
- 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
Registers a MessageResultListener for collecting answers.- Parameters:
messageId
- A message id to register forlistener
- An answer listener
-
handoverAnswer
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
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 interruptedTimeoutException
- 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 sendatNodeId
- A node id to send from- Returns:
- a response message
- Throws:
NodeNotFoundException
- If no node was not found with given idInterruptedException
- If sending the message was interruptedTimeoutException
- 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 sendrecipientCount
- expected number of answers- Returns:
- Returns an array with all collected answers
- Throws:
InterruptedException
- If sending the message was interruptedTimeoutException
- If sending the message timeouts
-
getAgentContext
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
Gets a (possibly fresh) context for the given agent.- Parameters:
agent
- An agent to get the context for- Returns:
- Returns a context
-
hasService
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
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 oldAgentContext
objects fromhtLocalExecutionContexts
-
getStartTime
-
NodeStorageInterface.fetchEnvelope(String)
instead Gets an artifact from the p2p storage.