Package i5.las2peer.p2p
Class PastryNodeImpl
java.lang.Object
i5.las2peer.api.Configurable
i5.las2peer.p2p.Node
i5.las2peer.p2p.PastryNodeImpl
- All Implemented Interfaces:
L2pStorageInterface
,NodeStorageInterface
,AgentStorage
- Direct Known Subclasses:
EthereumNode
A FreePastry implementation of a las2peer
Node
.
This class is the actual heart of the p2p based network of interacting nodes an agents in the las2peer setting.
The package i5.las2peer.p2p.pastry
provides all necessary helper classes for the integration (and
encapsulation) of the FreePastry library.-
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
ConstructorDescriptionPastryNodeImpl
(ClassManager classManager, boolean useMonitoringObserver, InetAddress pastryBindAddress, Integer pastryPort, List<String> bootstrap, SharedStorage.STORAGE_MODE storageMode, String storageDir, Long nodeIdSeed) This is the regular constructor used by theL2pNodeLauncher
.PastryNodeImpl
(String bootstrap, SharedStorage.STORAGE_MODE storageMode, String storageDir, Long nodeIdSeed) This constructor is mainly used by theTestSuite
, uses a random system defined port number and sets all parameters for a debugging and testing optimized operation mode. -
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) Deprecated.UsefetchEnvelope(String)
insteadfetchEnvelope
(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.byte[]
fetchHashedContent
(byte[] hash) byte[]
fetchHashedContent
(byte[] hash, long timeoutMs) void
fetchHashedContentAsync
(byte[] hash, StorageArtifactHandler artifactHandler, StorageExceptionHandler exceptionHandler) Object[]
findRegisteredAgent
(String agentId, int hintOfExpectedCount) Searches the nodes for registered Versions of the given Agent.Gets an agent description from the net.provides access to the underlying pastry application mostly for testing purposeslong
long
get the identifier of this node (string representation of the pastry node)getNodeInformation
(Object nodeId) Gets information about a distant node.Object[]
Gets an array with identifiers of other (locally known) nodes in this network.rice.pastry.PastryNode
access to the underlying pastry nodeint
getPort()
protected void
start this nodevoid
registerReceiver
(MessageReceiver receiver) Registers a (local) Agent for usage through this node.void
registerReceiverToTopic
(MessageReceiver receiver, long topic) register a receiver to a topicvoid
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.protected void
Add past storage as network repositoryvoid
shutDown()
Stops the node.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
storeHashedContent
(byte[] content) void
storeHashedContent
(byte[] content, long timeoutMs) void
storeHashedContentAsync
(byte[] content, StorageStoreResultHandler resultHandler, StorageExceptionHandler exceptionHandler) void
unregisterReceiver
(MessageReceiver receiver) Unregisters a MessageReceiver from this node.void
unregisterReceiverFromTopic
(MessageReceiver receiver, long topic) unregister a receiver from a topicvoid
updateAgent
(AgentImpl agent) Deprecated.UsestoreAgent(AgentImpl)
insteadMethods 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, removeObserver, runTidyUpTimer, sendMessage, sendMessageAndCollectAnswers, sendMessageAndWaitForAnswer, sendMessageAndWaitForAnswer, sendResponse, setCpuLoadThreshold, setInformationFilename, setServiceMonitoring, setStatus, startService, stopService, stopService
Methods inherited from class i5.las2peer.api.Configurable
getProperties, setFieldValues
-
Field Details
-
DEFAULT_BOOTSTRAP_PORT
public static final int DEFAULT_BOOTSTRAP_PORT- See Also:
-
-
Constructor Details
-
Method Details
-
getPastryNode
public rice.pastry.PastryNode getPastryNode()access to the underlying pastry node- Returns:
- the pastry node representing this las2peer node
-
setupRepository
protected void setupRepository()Add past storage as network repository -
launchSub
start this node- Specified by:
launchSub
in classNode
- Throws:
NodeException
- If launching the node fails
-
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)
-
unregisterReceiver
public void unregisterReceiver(MessageReceiver receiver) throws AgentNotRegisteredException, NodeException Description copied from class:Node
Unregisters a MessageReceiver from this node.- Overrides:
unregisterReceiver
in classNode
- 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 Description copied from class:Node
register a receiver to a topic- Overrides:
registerReceiverToTopic
in classNode
- Parameters:
receiver
- the MessageReceivertopic
- the topic id- Throws:
AgentNotRegisteredException
- The given MessageReceiver is not registered to this node
-
unregisterReceiverFromTopic
Description copied from class:Node
unregister a receiver from a topic- Overrides:
unregisterReceiverFromTopic
in classNode
- Parameters:
receiver
- the receivertopic
- the topic id- Throws:
NodeException
- If unregistering fails
-
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
-
fetchArtifact
@Deprecated public EnvelopeVersion fetchArtifact(String identifier) throws EnvelopeNotFoundException, EnvelopeException Deprecated.UsefetchEnvelope(String)
instead- 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
-
storeArtifact
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
-
getApplication
provides access to the underlying pastry application mostly for testing purposes- Returns:
- the pastry node application of this pastry 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 foundAgentException
- If any other issue with the agent occurs, e. g. XML not readable
-
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.UsestoreAgent(AgentImpl)
insteadDescription 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
-
getNodeId
get the identifier of this node (string representation of the pastry node) -
getBindAddress
-
getPort
public int getPort() -
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
-
getLocalStorageSize
public long getLocalStorageSize() -
getLocalMaxStorageSize
public long getLocalMaxStorageSize() -
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
public EnvelopeVersion fetchEnvelope(String identifier) throws EnvelopeNotFoundException, EnvelopeException 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, 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(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) 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.
-
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 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.
-
storeHashedContentAsync
public void storeHashedContentAsync(byte[] content, StorageStoreResultHandler resultHandler, StorageExceptionHandler exceptionHandler) -
storeHashedContent
- Throws:
EnvelopeException
-
storeHashedContent
- Throws:
EnvelopeException
-
fetchHashedContentAsync
public void fetchHashedContentAsync(byte[] hash, StorageArtifactHandler artifactHandler, StorageExceptionHandler exceptionHandler) -
fetchHashedContent
- Throws:
EnvelopeException
-
fetchHashedContent
- Throws:
EnvelopeException
-
fetchEnvelope(String)
instead