Package i5.las2peer.p2p
Class LocalNode
java.lang.Object
i5.las2peer.api.Configurable
i5.las2peer.p2p.Node
i5.las2peer.p2p.LocalNode
- All Implemented Interfaces:
L2pStorageInterface
,NodeStorageInterface
,AgentStorage
Implementation of the abstract
Node
class mostly for testing purposes. All data and agents will be stored in
the same JVM, which may be used in JUnit test cases or to launch a local only server for example.
TODO: uses loggers / observers-
Nested Class Summary
Nested classes/interfaces inherited from class i5.las2peer.p2p.Node
Node.NodeStatus, Node.SendMode
-
Field Summary
Fields inherited from class i5.las2peer.p2p.Node
DEFAULT_AGENT_CONTEXT_LIFETIME, DEFAULT_CPU_LOAD_TRESHOLD, DEFAULT_INVOCATION_RETRY_COUNT, DEFAULT_NODE_SERVICE_CACHE_LIFETIME, DEFAULT_NODE_SERVICE_CACHE_RESULT_COUNT, DEFAULT_TIDY_UP_TIMER_INTERVAL
-
Constructor Summary
ConstructorDescriptionLocalNode
(LocalNodeManager localNodeManager) create a LocalNodeLocalNode
(LocalNodeManager localNodeManager, ClassManager classManager) create a LocalNode -
Method Summary
Modifier and TypeMethodDescriptioncreateEnvelope
(EnvelopeVersion previousVersion, Serializable content) Creates an continuous version instance for the given Envelope.createEnvelope
(EnvelopeVersion previousVersion, Serializable content, AgentImpl... reader) Creates an continuous version instance for the given Envelope.createEnvelope
(EnvelopeVersion previousVersion, Serializable content, Collection<?> readers) Creates an continous version instance for the given Envelope.createEnvelope
(String identifier, PublicKey authorPubKey, Serializable content, AgentImpl... reader) Creates a new version of an Envelope.createEnvelope
(String identifier, PublicKey authorPubKey, Serializable content, Collection<?> readers) Creates a new version of an Envelope.createUnencryptedEnvelope
(EnvelopeVersion previousVersion, Serializable content) Creates an continous unencrypted version instance for the given Envelope.createUnencryptedEnvelope
(String identifier, PublicKey authorPubKey, Serializable content) Creates a new version of an unencrypted Envelope.fetchArtifact
(long id) Deprecated.fetchArtifact
(String identifier) fetchEnvelope
(String identifier) Fetches the latest version for the given identifier from the network.fetchEnvelope
(String identifier, long timeoutMs) Fetches the latest version for the given identifier from the network.void
fetchEnvelopeAsync
(String identifier, StorageEnvelopeHandler envelopeHandler, StorageExceptionHandler exceptionHandler) Fetches the latest version for the given identifier from the network.Object[]
findRegisteredAgent
(String agentId, int hintOfExpectedCount) Searches the nodes for registered Versions of the given Agent.Gets an agent description from the net.get the id of this nodegetNodeInformation
(Object nodeId) Gets information about a distant node.Object[]
Gets an array with identifiers of other (locally known) nodes in this network.protected void
Starts this node.void
registerReceiver
(MessageReceiver receiver) Registers a (local) Agent for usage through this node.void
removeArtifact
(long id, byte[] signature) Deprecated.UseremoveEnvelope(String)
insteadvoid
removeEnvelope
(String identifier) Removes the envelope with the given identifier from the network.void
sendMessage
(Message message, MessageResultListener listener, Node.SendMode mode) Sends a message, recipient and sender are stated in the message.void
sendMessage
(Message message, Object atNodeId, MessageResultListener listener) Sends a message to the agent residing at the given node.void
shutDown()
Stops the node.void
storeAgent
(Agent agent) void
storeAgent
(AgentImpl agent) Stores a new Agent to the network.void
storeArtifact
(EnvelopeVersion envelope) Deprecated.UsestoreEnvelope(EnvelopeVersion, AgentImpl)
insteadvoid
storeEnvelope
(EnvelopeVersion envelope, AgentImpl author) Stores the given Envelope in the network.void
storeEnvelope
(EnvelopeVersion envelope, AgentImpl author, long timeoutMs) Stores the given Envelope in the network.void
storeEnvelopeAsync
(EnvelopeVersion envelope, AgentImpl author, StorageStoreResultHandler resultHandler, StorageCollisionHandler collisionHandler, StorageExceptionHandler exceptionHandler) Stores the given Envelope in the network.void
updateAgent
(AgentImpl agent) Deprecated.Methods inherited from class i5.las2peer.p2p.Node
addObserver, createMediatorForAgent, findRegisteredAgent, findRegisteredAgent, findRegisteredAgent, getAgentContext, getAgentContext, getAgentIdForEmail, getAgentIdForGroupName, getAgentIdForLogin, getBaseClassLoader, getInformationFilename, getLocalAgent, getLocalServiceAgent, getNodeCpuLoad, getNodeFreeRAMLoad, getNodeInformation, getNodeRAMLoad, getNodeRepresentation, getNodeServiceCache, getRegisteredAgents, getRegisteredServices, getServiceAgent, getServiceAliasManager, getStartTime, getStatus, getUserManager, handoverAnswer, hasAgent, hasLocalAgent, hasLocalAgent, hasService, hasTopic, invoke, invoke, invoke, invoke, invokeGlobally, invokeLocally, isBusy, launch, observerNotice, observerNotice, observerNotice, observerNotice, observerNotice, observerNotice, observerNotice, observerNotice, receiveMessage, registerAnswerListener, registerReceiverToTopic, removeObserver, runTidyUpTimer, sendMessage, sendMessageAndCollectAnswers, sendMessageAndWaitForAnswer, sendMessageAndWaitForAnswer, sendResponse, setCpuLoadThreshold, setInformationFilename, setServiceMonitoring, setStatus, startService, stopService, stopService, unregisterReceiver, unregisterReceiverFromTopic
Methods inherited from class i5.las2peer.api.Configurable
getProperties, setFieldValues
-
Constructor Details
-
LocalNode
create a LocalNode- Parameters:
localNodeManager
- A manager to handle a group (network) of local nodes
-
LocalNode
create a LocalNode- Parameters:
localNodeManager
- A manager to handle a group (network) of local nodesclassManager
- A class manager to use
-
-
Method Details
-
getNodeId
get the id of this node -
launchSub
protected void launchSub()Description copied from class:Node
Starts this node. -
shutDown
public void shutDown()Description copied from class:Node
Stops the node. -
registerReceiver
public void registerReceiver(MessageReceiver receiver) throws AgentAlreadyRegisteredException, AgentException Description copied from class:Node
Registers a (local) Agent for usage through this node. The Agent has to be unlocked before registration.- Overrides:
registerReceiver
in classNode
- 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)
-
sendMessage
Description copied from class:Node
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!- Specified by:
sendMessage
in classNode
- Parameters:
message
- the message to sendlistener
- a listener for getting the result separatelymode
- is it a broadcast or an any-cast message?
-
sendMessage
public void sendMessage(Message message, Object atNodeId, MessageResultListener listener) throws NodeNotFoundException Description copied from class:Node
Sends a message to the agent residing at the given node.- Specified by:
sendMessage
in classNode
- 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
-
fetchArtifact
@Deprecated public EnvelopeVersion fetchArtifact(long id) throws EnvelopeNotFoundException, EnvelopeException Deprecated.UsefetchEnvelope(String)
instead- Specified by:
fetchArtifact
in classNode
- 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
-
storeArtifact
@Deprecated public void storeArtifact(EnvelopeVersion envelope) throws EnvelopeAlreadyExistsException, EnvelopeException Deprecated.UsestoreEnvelope(EnvelopeVersion, AgentImpl)
instead- Specified by:
storeArtifact
in classNode
- Parameters:
envelope
- An envelope to store- Throws:
EnvelopeAlreadyExistsException
- If the envelope already existsEnvelopeException
- If an issue with the envelope occurred
-
removeArtifact
@Deprecated public void removeArtifact(long id, byte[] signature) throws EnvelopeNotFoundException, EnvelopeException Deprecated.UseremoveEnvelope(String)
instead- Specified by:
removeArtifact
in classNode
- 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 Object[] findRegisteredAgent(String agentId, int hintOfExpectedCount) throws AgentNotRegisteredException Description copied from class:Node
Searches the nodes for registered Versions of the given Agent. Returns an array of objects identifying the nodes the given agent is registered to.- Specified by:
findRegisteredAgent
in classNode
- 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
-
getAgent
Description copied from class:Node
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
- Specified by:
getAgent
in classNode
- Parameters:
id
- An agent id- Returns:
- the requested agent
- Throws:
AgentNotFoundException
- If the agent is not found
-
storeAgent
- Throws:
AgentException
-
storeAgent
Description copied from class:Node
Stores a new Agent to the network.- Specified by:
storeAgent
in classNode
- Parameters:
agent
- An agent to store- Throws:
AgentException
- If any issue with the agent occurs
-
updateAgent
Deprecated.Description copied from class:Node
Updates an existing agent of the network.- Specified by:
updateAgent
in classNode
- Parameters:
agent
- An agent to update- Throws:
AgentException
- If any issue with the agent occurs
-
getOtherKnownNodes
Description copied from class:Node
Gets an array with identifiers of other (locally known) nodes in this network.- Specified by:
getOtherKnownNodes
in classNode
- Returns:
- array with handles of other (known) p2p network nodes
-
getNodeInformation
Description copied from class:Node
Gets information about a distant node.- Specified by:
getNodeInformation
in classNode
- Parameters:
nodeId
- A node id to query- Returns:
- information about the node
- Throws:
NodeNotFoundException
- If the node was not found
-
createEnvelope
public EnvelopeVersion createEnvelope(String identifier, PublicKey authorPubKey, Serializable content, AgentImpl... reader) throws IllegalArgumentException, SerializationException, CryptoException Description copied from interface:L2pStorageInterface
Creates a new version of an Envelope. The Envelope uses by default the start version number.- Parameters:
identifier
- An unique identifier for the Envelope.authorPubKey
- The authors public key. Validated on store operation.content
- The actual content that should be stored.reader
- An arbitrary number of Agents, who are allowed to read the content.- Returns:
- Returns the Envelope instance.
- Throws:
IllegalArgumentException
- If the given identifier isnull
, the version number is below the start version number or too high.SerializationException
- If a problem occurs with object serialization.CryptoException
- If an cryptographic issue occurs.
-
createEnvelope
public EnvelopeVersion createEnvelope(EnvelopeVersion previousVersion, Serializable content) throws IllegalArgumentException, SerializationException, CryptoException Description copied from interface:L2pStorageInterface
Creates an continuous version instance for the given Envelope. This method copies the reader list from the previous Envelope instance.- Parameters:
previousVersion
- The previous version of the Envelope that should be updated.content
- The updated content that should be stored.- Returns:
- Returns the Envelope instance.
- Throws:
IllegalArgumentException
- If the given identifier isnull
, the version number is below the start version number or too high.SerializationException
- If a problem occurs with object serialization.CryptoException
- If an cryptographic issue occurs.
-
createEnvelope
public EnvelopeVersion createEnvelope(EnvelopeVersion previousVersion, Serializable content, AgentImpl... reader) throws IllegalArgumentException, SerializationException, CryptoException Description copied from interface:L2pStorageInterface
Creates an continuous version instance for the given Envelope.- Parameters:
previousVersion
- The previous version of the Envelope that should be updated.content
- The updated content that should be stored.reader
- An arbitrary number of Agents, who are allowed to read the content.- Returns:
- Returns the Envelope instance.
- Throws:
IllegalArgumentException
- If the given identifier isnull
, the version number is below the start version number or too high.SerializationException
- If a problem occurs with object serialization.CryptoException
- If an cryptographic issue occurs.
-
storeEnvelope
Description copied from interface:NodeStorageInterface
Stores the given Envelope in the network. The content is signed with the key from the given author. If an exception occurs its wrapped as StorageException. With this method collisions are handled by throwing anEnvelopeAlreadyExistsException
. This method uses the default timeout defined by the acting node.- Parameters:
envelope
- The Envelope to store in the network.author
- The author that is used to sign the content.- Throws:
EnvelopeException
- If an issue with the storage occurs.
-
fetchEnvelope
Description copied from interface:NodeStorageInterface
Fetches the latest version for the given identifier from the network. This method uses the default timeout defined by the acting node.- Parameters:
identifier
- An unique identifier for the Envelope.- Returns:
- Returns the fetched Envelope from the network.
- Throws:
EnvelopeNotFoundException
- If no envelope or any part of it was not found in the network.EnvelopeException
- If an issue with the storage occurs.
-
createEnvelope
public EnvelopeVersion createEnvelope(String identifier, PublicKey authorPubKey, Serializable content, Collection<?> readers) throws IllegalArgumentException, SerializationException, CryptoException Description copied from interface:L2pStorageInterface
Creates a new version of an Envelope. The Envelope uses by default the start version number.- Parameters:
identifier
- An unique identifier for the Envelope.authorPubKey
- The authors public key. Validated on store operation.content
- The actual content that should be stored.readers
- An arbitrary number of Agents, who are allowed to read the content.- Returns:
- Returns the Envelope instance.
- Throws:
IllegalArgumentException
- If the given identifier isnull
, the version number is below the start version number or too high.SerializationException
- If a problem occurs with object serialization.CryptoException
- If an cryptographic issue occurs.
-
createEnvelope
public EnvelopeVersion createEnvelope(EnvelopeVersion previousVersion, Serializable content, Collection<?> readers) throws IllegalArgumentException, SerializationException, CryptoException Description copied from interface:L2pStorageInterface
Creates an continous version instance for the given Envelope.- Parameters:
previousVersion
- The previous version of the Envelope that should be updated.content
- The updated content that should be stored.readers
- An arbitrary number of Agents, who are allowed to read the content.- Returns:
- Returns the Envelope instance.
- Throws:
IllegalArgumentException
- If the given identifier isnull
, the version number is below the start version number or too high.SerializationException
- If a problem occurs with object serialization.CryptoException
- If an cryptographic issue occurs.
-
createUnencryptedEnvelope
public EnvelopeVersion createUnencryptedEnvelope(String identifier, PublicKey authorPubKey, Serializable content) throws IllegalArgumentException, SerializationException, CryptoException Description copied from interface:L2pStorageInterface
Creates a new version of an unencrypted Envelope. The Envelope uses by default the start version number.- Parameters:
identifier
- An unique identifier for the Envelope.authorPubKey
- The authors public key. Validated on store operation.content
- The updated content that should be stored.- Returns:
- Returns the Envelope instance.
- Throws:
IllegalArgumentException
- If the given identifier isnull
, the version number is below the start version number or too high.SerializationException
- If a problem occurs with object serialization.CryptoException
- If an cryptographic issue occurs.
-
createUnencryptedEnvelope
public EnvelopeVersion createUnencryptedEnvelope(EnvelopeVersion previousVersion, Serializable content) throws IllegalArgumentException, SerializationException, CryptoException Description copied from interface:L2pStorageInterface
Creates an continous unencrypted version instance for the given Envelope.- Parameters:
previousVersion
- The previous version of the Envelope that should be updated.content
- The updated content that should be stored.- Returns:
- Returns the Envelope instance.
- Throws:
IllegalArgumentException
- If the given identifier isnull
, the version number is below the start version number or too high.SerializationException
- If a problem occurs with object serialization.CryptoException
- If an cryptographic issue occurs.
-
storeEnvelope
public void storeEnvelope(EnvelopeVersion envelope, AgentImpl author, long timeoutMs) throws EnvelopeAlreadyExistsException, EnvelopeException Description copied from interface:L2pStorageInterface
Stores the given Envelope in the network. The content is signed with the key from the given author. If an exception occurs it's wrapped as StorageException. With this method collisions are handled by throwing anEnvelopeAlreadyExistsException
.- Parameters:
envelope
- The Envelope to store in the network.author
- The author that is used to sign the content.timeoutMs
- A timeout after that anEnvelopeException
is thrown.- Throws:
EnvelopeAlreadyExistsException
- If an Envelope with the given identifier and version is already known in the network.EnvelopeException
- If an issue with the storage occurs.
-
storeEnvelopeAsync
public void storeEnvelopeAsync(EnvelopeVersion envelope, AgentImpl author, StorageStoreResultHandler resultHandler, StorageCollisionHandler collisionHandler, StorageExceptionHandler exceptionHandler) Description copied from interface:L2pStorageInterface
Stores the given Envelope in the network. The content is signed with the key from the given author. If an exception occurs the operation is canceled and the exception handler is called. Same for collisions. If the operations is completed the result handler is called.- Parameters:
envelope
- The Envelope to store in the network.author
- The author that is used to sign the content.resultHandler
- A result handler that is called, if the operation terminates.collisionHandler
- A collision handler that is called, if an Envelope with the given identifier and version already exists.exceptionHandler
- An exception handler that is called, if an exception occurs.
-
fetchEnvelope
public EnvelopeVersion fetchEnvelope(String identifier, long timeoutMs) throws EnvelopeNotFoundException, EnvelopeException Description copied from interface:L2pStorageInterface
Fetches the latest version for the given identifier from the network.- Parameters:
identifier
- An unique identifier for the Envelope.timeoutMs
- A timeout after that anEnvelopeException
is thrown.- Returns:
- Returns the fetched Envelope from the network.
- Throws:
EnvelopeNotFoundException
- If no envelope or any part of it was not found in the network.EnvelopeException
- If an issue with the storage occurs.
-
fetchEnvelopeAsync
public void fetchEnvelopeAsync(String identifier, StorageEnvelopeHandler envelopeHandler, StorageExceptionHandler exceptionHandler) Description copied from interface:L2pStorageInterface
Fetches the latest version for the given identifier from the network.- Parameters:
identifier
- An unique identifier for the Envelope.envelopeHandler
- A result handler that is called, if the operation terminates.exceptionHandler
- An exception handler that is called, if an exception occurs.
-
removeEnvelope
Description copied from interface:L2pStorageInterface
Removes the envelope with the given identifier from the network.- Parameters:
identifier
- An unique identifier for the Envelope.- Throws:
EnvelopeNotFoundException
- If no envelope or any part of it was not found in the network.EnvelopeException
- If an issue with the storage occurs.
-
fetchArtifact
public EnvelopeVersion fetchArtifact(String identifier) throws EnvelopeNotFoundException, EnvelopeException - Specified by:
fetchArtifact
in classNode
- 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
-
fetchEnvelope(String)
instead