Package org.drasyl.localhost
Class LocalHostDiscovery
- java.lang.Object
-
- org.drasyl.pipeline.skeleton.HandlerAdapter
-
- org.drasyl.pipeline.skeleton.AddressHandlerAdapter<A>
-
- org.drasyl.pipeline.skeleton.SimpleOutboundHandler<SerializedApplicationMessage,CompressedPublicKey>
-
- org.drasyl.localhost.LocalHostDiscovery
-
- All Implemented Interfaces:
Handler
public class LocalHostDiscovery extends SimpleOutboundHandler<SerializedApplicationMessage,CompressedPublicKey>
Uses the file system to discover other drasyl nodes running on the local computer.To do this, all nodes regularly write their
UdpServer
address(es) to the file system. At the same time the file system is monitored to detect other nodes. If the file system does not support monitoring (WatchService
), a fallback to polling is used.Inspired by: Jadex
-
-
Field Summary
Fields Modifier and Type Field Description static String
FILE_SUFFIX
static String
LOCAL_HOST_DISCOVERY
static Duration
REFRESH_INTERVAL_SAFETY_MARGIN
static Duration
WATCH_SERVICE_POLL_INTERVAL
-
Constructor Summary
Constructors Constructor Description LocalHostDiscovery()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
eventTriggered(HandlerContext ctx, Event event, CompletableFuture<Void> future)
Gets called if aEvent
was emitted.protected void
matchedWrite(HandlerContext ctx, CompressedPublicKey recipient, SerializedApplicationMessage msg, CompletableFuture<Void> future)
Is called for each message of typeSimpleOutboundHandler
.-
Methods inherited from class org.drasyl.pipeline.skeleton.SimpleOutboundHandler
acceptOutbound, write
-
Methods inherited from class org.drasyl.pipeline.skeleton.AddressHandlerAdapter
acceptAddress
-
Methods inherited from class org.drasyl.pipeline.skeleton.HandlerAdapter
exceptionCaught, handlerAdded, handlerRemoved, read
-
-
-
-
Field Detail
-
LOCAL_HOST_DISCOVERY
public static final String LOCAL_HOST_DISCOVERY
- See Also:
- Constant Field Values
-
REFRESH_INTERVAL_SAFETY_MARGIN
public static final Duration REFRESH_INTERVAL_SAFETY_MARGIN
-
WATCH_SERVICE_POLL_INTERVAL
public static final Duration WATCH_SERVICE_POLL_INTERVAL
-
FILE_SUFFIX
public static final String FILE_SUFFIX
- See Also:
- Constant Field Values
-
-
Method Detail
-
eventTriggered
public void eventTriggered(HandlerContext ctx, Event event, CompletableFuture<Void> future)
Description copied from interface:Handler
Gets called if aEvent
was emitted.- Specified by:
eventTriggered
in interfaceHandler
- Overrides:
eventTriggered
in classHandlerAdapter
- Parameters:
ctx
- handler contextevent
- the eventfuture
- a future for the message
-
matchedWrite
protected void matchedWrite(HandlerContext ctx, CompressedPublicKey recipient, SerializedApplicationMessage msg, CompletableFuture<Void> future)
Description copied from class:SimpleOutboundHandler
Is called for each message of typeSimpleOutboundHandler
.- Specified by:
matchedWrite
in classSimpleOutboundHandler<SerializedApplicationMessage,CompressedPublicKey>
- Parameters:
ctx
- handler contextrecipient
- the recipient of the messagemsg
- the messagefuture
- a future for the message
-
-