Class DrasylNode
- Direct Known Subclasses:
ObservableDrasylNode
Example usage:
DrasylNode node = new DrasylNode() {
@Override
public void onEvent(Event event) {
// handle incoming events (messages) here
System.out.println("Event received: " + event);
}
};
node.start();
// wait till NodeOnlineEvent has been received
// send message to another node
node.send("0229041b273dd5ee1c2bef2d77ae17dbd00d2f0a2e939e22d42ef1c4bf05147ea9", "Hello World");
// shutdown node
node.shutdown();
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedCreates a new drasyl Node.protectedDrasylNode(DrasylConfig config) Creates a new drasyl Node with the givenconfig.protectedDrasylNode(DrasylConfig config, Identity identity, PeersManager peersManager, PeerChannelGroup channelGroup, Set<Endpoint> endpoints, AtomicBoolean acceptNewConnections, Pipeline pipeline, List<DrasylNodeComponent> components, PluginManager pluginManager, AtomicBoolean started, CompletableFuture<Void> startSequence, CompletableFuture<Void> shutdownSequence) -
Method Summary
Modifier and TypeMethodDescriptionstatic io.netty.channel.EventLoopGroupReturns theEventLoopGroupthat fits best to the current environment.static io.netty.channel.EventLoopGroupgetBestEventLoop(int poolSize) Returns theEventLoopGroupthat fits best to the current environment.static StringReturns the version of the node.identity()Returns theIdentityof this node.static voidThis method stops the shared threads (EventLoopGroups), but only if noneDrasylNodeis using them anymore.abstract voidSendseventto the application and tells it information about the local node, other peers, connections or incoming messages.pipeline()Returns thePipelineto allow users to add own handlers.Sends the content ofpayloadto the identityrecipient.send(CompressedPublicKey recipient, Object payload) Sends the content ofpayloadto the identityrecipient.shutdown()Shut the drasyl node down.start()Start the drasyl node.
-
Constructor Details
-
DrasylNode
Creates a new drasyl Node. The node is only being created, it neither connects to the Overlay Network, nor can send or receive messages. To do this you have to callstart().Note: This is a blocking method, because when a node is started for the first time, its identity must be created. This can take up to a minute because of the proof of work.
- Throws:
DrasylException
-
DrasylNode
Creates a new drasyl Node with the givenconfig. The node is only being created, it neither connects to the Overlay * Network, nor can send or receive messages. To do this you have to callstart().Note: This is a blocking method, because when a node is started for the first time, its identity must be created. This can take up to a minute because of the proof of work.
- Parameters:
config- custom configuration used for this node- Throws:
DrasylException
-
DrasylNode
protected DrasylNode(DrasylConfig config, Identity identity, PeersManager peersManager, PeerChannelGroup channelGroup, Set<Endpoint> endpoints, AtomicBoolean acceptNewConnections, Pipeline pipeline, List<DrasylNodeComponent> components, PluginManager pluginManager, AtomicBoolean started, CompletableFuture<Void> startSequence, CompletableFuture<Void> shutdownSequence)
-
-
Method Details
-
getVersion
Returns the version of the node. If the version could not be read,nullis returned.- Returns:
- the version of the node
-
irrevocablyTerminate
public static void irrevocablyTerminate()This method stops the shared threads (EventLoopGroups), but only if noneDrasylNodeis using them anymore.This operation cannot be undone. After performing this operation, no new DrasylNodes can be created!
-
getBestEventLoop
public static io.netty.channel.EventLoopGroup getBestEventLoop(int poolSize) Returns theEventLoopGroupthat fits best to the current environment. Under Linux the more performantEpollEventLoopGroupis returned.- Returns:
EventLoopGroupthat fits best to the current environment
-
getBestEventLoop
public static io.netty.channel.EventLoopGroup getBestEventLoop()Returns theEventLoopGroupthat fits best to the current environment. Under Linux the more performantEpollEventLoopGroupis returned.- Returns:
EventLoopGroupthat fits best to the current environment
-
onEvent
Sendseventto the application and tells it information about the local node, other peers, connections or incoming messages.- Parameters:
event- the event
-
send
Sends the content ofpayloadto the identityrecipient. Returns a failed future with aIllegalStateExceptionif the message could not be sent to the recipient or a super peer. Important: Just because the future did not fail does not automatically mean that the message could be delivered. Delivery confirmations must be implemented by the application.Note: It is possible that the passed object cannot be serialized. In this case it is not sent and the future is fulfilled with an exception. By default, drasyl allows the serialization of Java's primitive types, as well as
StringandNumber. Further objects can be added on start via theDrasylConfigor on demand viaHandlerContext.inboundValidator()orHandlerContext.outboundValidator(). If theDefaultCodecdoes not support these objects, a customCodeccan be added to the beginning of thePipeline.- Parameters:
recipient- the recipient of a message as compressed public keypayload- the payload of a message- Returns:
- a completed future if the message was successfully processed, otherwise an exceptionally future
- Since:
- 0.1.3-SNAPSHOT
- See Also:
-
send
Sends the content ofpayloadto the identityrecipient. Returns a failed future with aIllegalStateExceptionif the message could not be sent to the recipient or a super peer. Important: Just because the future did not fail does not automatically mean that the message could be delivered. Delivery confirmations must be implemented by the application.Note: It is possible that the passed object cannot be serialized. In this case it is not sent and the future is fulfilled with an exception. By default, drasyl allows the serialization of Java's primitive types, as well as
StringandNumber. Further objects can be added on start via theDrasylConfigor on demand viaHandlerContext.inboundValidator()orHandlerContext.outboundValidator(). If theDefaultCodecdoes not support these objects, a customCodeccan be added to the beginning of thePipeline.- Parameters:
recipient- the recipient of a messagepayload- the payload of a message- Returns:
- a completed future if the message was successfully processed, otherwise an exceptionally future
- Since:
- 0.1.3-SNAPSHOT
- See Also:
-
shutdown
Shut the drasyl node down.If there is a connection to a Super Peer, our node will deregister from that Super Peer.
If the local server has been started, it will now be stopped.
This method does not stop the shared threads. To kill the shared threads, you have to call the
irrevocablyTerminate()method.- Returns:
- this method returns a future, which complements if all shutdown steps have been completed.
-
start
Start the drasyl node.First, the identity of the node is loaded. If none exists, a new one is generated.
If activated, a local server is started. This allows other nodes to discover our node.
If a super peer has been configured, a client is started which connects to this super peer. Our node uses the Super Peer to discover and communicate with other nodes.
- Returns:
- this method returns a future, which complements if all components necessary for the operation have been started.
-
pipeline
Returns thePipelineto allow users to add own handlers.- Returns:
- the pipeline
-
identity
Returns theIdentityof this node.- Returns:
- the
Identityof this node
-