Class 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
    • Constructor Summary

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

      All Methods Instance Methods Concrete Methods 
      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 interface io.netty.channel.ChannelHandler

        handlerAdded, handlerRemoved
    • Field Detail

      • REFRESH_INTERVAL_SAFETY_MARGIN

        public static final Duration REFRESH_INTERVAL_SAFETY_MARGIN
      • WATCH_SERVICE_POLL_INTERVAL

        public static final Duration WATCH_SERVICE_POLL_INTERVAL
    • Constructor Detail

      • LocalHostDiscovery

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

      • 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