Class DrasylNode
- java.lang.Object
-
- org.drasyl.DrasylNode
-
public abstract class DrasylNode extends Object
Represents a node in the drasyl Overlay Network. Applications that want to run on drasyl must implement this class.Example usage:
{@code DrasylNode node = new DrasylNode() {
-
-
Constructor Summary
Constructors Constructor Description DrasylNode()
Creates a new drasyl Node.DrasylNode(DrasylConfig config)
Creates a new drasyl Node with the givenconfig
.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description static String
getVersion()
Returns the version of the node.static void
irrevocablyTerminate()
This method stops the shared threads (EventLoopGroup
s), but only if noneDrasylNode
is using them anymore.abstract void
onEvent(Event event)
Sendsevent
to the application and tells it information about the local node, other peers, connections or incoming messages.Pipeline
pipeline()
Returns thePipeline
to allow users to add own handlers.void
send(String recipient, byte[] payload)
void
send(String recipient, String payload)
Sends the content ofpayload
to the identityrecipient
.void
send(CompressedPublicKey recipient, byte[] payload)
Sends the content ofpayload
to the identityrecipient
.void
send(CompressedPublicKey recipient, String payload)
Sends the content ofpayload
to the identityrecipient
.static void
setLogLevel(ch.qos.logback.classic.Level level)
Set log level of all drasyl loggers in org.drasyl package namespace.CompletableFuture<Void>
shutdown()
Shut the Drasyl node down.CompletableFuture<Void>
shutdownFuture()
This method returns a future, which complements if all shutdown steps have been completed.CompletableFuture<Void>
start()
Start the Drasyl node.
-
-
-
Constructor Detail
-
DrasylNode
public DrasylNode() throws DrasylException
Creates a new drasyl Node.- Throws:
DrasylException
-
DrasylNode
public DrasylNode(DrasylConfig config) throws DrasylException
Creates a new drasyl Node with the givenconfig
.- Parameters:
config
-- Throws:
DrasylException
-
-
Method Detail
-
onEvent
public abstract void onEvent(Event event)
Sendsevent
to the application and tells it information about the local node, other peers, connections or incoming messages.- Parameters:
event
- the event
-
setLogLevel
public static void setLogLevel(ch.qos.logback.classic.Level level)
Set log level of all drasyl loggers in org.drasyl package namespace.- Parameters:
level
-
-
send
public void send(String recipient, byte[] payload) throws DrasylException
- Throws:
DrasylException
-
send
public void send(CompressedPublicKey recipient, byte[] payload)
Sends the content ofpayload
to the identityrecipient
. Throws aMessengerException
if the message could not be sent to the recipient or a super peer. Important: Just because no exception was thrown does not automatically mean that the message could be delivered. Delivery confirmations must be implemented by the application.- Parameters:
recipient
- the recipient of a messagepayload
- the payload of a message
-
send
public void send(String recipient, String payload) throws DrasylException
Sends the content ofpayload
to the identityrecipient
. Throws aMessengerException
if the message could not be sent to the recipient or a super peer. Important: Just because no exception was thrown does not automatically mean that the message could be delivered. Delivery confirmations must be implemented by the application.- Parameters:
recipient
- the recipient of a messagepayload
- the payload of a message- Throws:
MessengerException
- if an error occurs during the processingDrasylException
-
send
public void send(CompressedPublicKey recipient, String payload)
Sends the content ofpayload
to the identityrecipient
. Throws aMessengerException
if the message could not be sent to the recipient or a super peer. Important: Just because no exception was thrown does not automatically mean that the message could be delivered. Delivery confirmations must be implemented by the application.- Parameters:
recipient
- the recipient of a messagepayload
- the payload of a message
-
shutdown
public CompletableFuture<Void> 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.
-
shutdownFuture
public CompletableFuture<Void> shutdownFuture()
This method returns a future, which complements if all shutdown steps have been completed.- Returns:
- this method returns a future, which complements if all shutdown steps have been
-
start
public CompletableFuture<Void> 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.
-
getVersion
public static String getVersion()
Returns the version of the node. If the version could not be read,null
is returned.
-
irrevocablyTerminate
public static void irrevocablyTerminate()
This method stops the shared threads (EventLoopGroup
s), but only if noneDrasylNode
is using them anymore.This operation cannot be undone. After performing this operation, no new DrasylNodes can be created!
-
-