Class LocalHostDiscovery

java.lang.Object
io.netty.channel.ChannelHandlerAdapter
io.netty.channel.ChannelInboundHandlerAdapter
io.netty.channel.ChannelDuplexHandler
org.drasyl.handler.remote.LocalHostDiscovery
All Implemented Interfaces:
io.netty.channel.ChannelHandler, io.netty.channel.ChannelInboundHandler, io.netty.channel.ChannelOutboundHandler

public class LocalHostDiscovery extends io.netty.channel.ChannelDuplexHandler
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

  • Nested Class Summary

    Nested classes/interfaces inherited from interface io.netty.channel.ChannelHandler

    io.netty.channel.ChannelHandler.Sharable
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
     
    static final Duration
     
    static final Duration
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    LocalHostDiscovery(int networkId, boolean watchEnabled, Duration leaseTime, Path path)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    channelInactive(io.netty.channel.ChannelHandlerContext ctx)
     
    void
    userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt)
     
    void
    write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise)
     

    Methods inherited from class io.netty.channel.ChannelDuplexHandler

    bind, close, connect, deregister, disconnect, flush, read

    Methods inherited from class io.netty.channel.ChannelInboundHandlerAdapter

    channelActive, channelRead, channelReadComplete, channelRegistered, channelUnregistered, channelWritabilityChanged, exceptionCaught

    Methods inherited from class io.netty.channel.ChannelHandlerAdapter

    ensureNotSharable, handlerAdded, handlerRemoved, isSharable

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface io.netty.channel.ChannelHandler

    handlerAdded, handlerRemoved
  • Field Details

    • 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:
  • Constructor Details

    • LocalHostDiscovery

      public LocalHostDiscovery(int networkId, boolean watchEnabled, Duration leaseTime, Path path)
  • Method Details

    • write

      public void write(io.netty.channel.ChannelHandlerContext ctx, Object msg, io.netty.channel.ChannelPromise promise) throws Exception
      Specified by:
      write in interface io.netty.channel.ChannelOutboundHandler
      Overrides:
      write in class io.netty.channel.ChannelDuplexHandler
      Throws:
      Exception
    • channelInactive

      public void channelInactive(io.netty.channel.ChannelHandlerContext ctx)
      Specified by:
      channelInactive in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      channelInactive in class io.netty.channel.ChannelInboundHandlerAdapter
    • userEventTriggered

      public void userEventTriggered(io.netty.channel.ChannelHandlerContext ctx, Object evt)
      Specified by:
      userEventTriggered in interface io.netty.channel.ChannelInboundHandler
      Overrides:
      userEventTriggered in class io.netty.channel.ChannelInboundHandlerAdapter