Class BabelIpUtils

java.lang.Object
pt.unl.fct.di.novasys.babel2.channels.utils.BabelIpUtils

public final class BabelIpUtils extends Object
Shared utility constants and helper methods used by the Babel 2 IP channel implementations.

On class load this class auto-detects the best available Netty transport backend and sets the channel class and I/O handler factory constants accordingly:

  1. epoll — used on Linux kernels that support it (best performance).
  2. kqueue — used on macOS / BSD kernels (good performance).
  3. NIO — portable fallback for other platforms.

This class is not instantiable.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    Magic number (0xBABE12) written at the start of every regular Babel message frame.
    static final Class<? extends io.netty.channel.socket.DatagramChannel>
    Datagram channel class selected for the current OS (epoll / kqueue / NIO).
    static final io.netty.channel.IoHandlerFactory
    I/O handler factory selected for the current OS (epoll / kqueue / NIO).
    static final Class<? extends io.netty.channel.socket.ServerSocketChannel>
    Server socket channel class selected for the current OS (epoll / kqueue / NIO).
    static final Class<? extends io.netty.channel.socket.SocketChannel>
    Socket channel class selected for the current OS (epoll / kqueue / NIO).
  • Method Summary

    Modifier and Type
    Method
    Description
    static io.netty.channel.EventLoopGroup
    Creates a new Netty EventLoopGroup using the platform-optimized I/O handler with the default thread count.
    static io.netty.channel.EventLoopGroup
    createLoopGroup(int numberOfThreads)
    Creates a new Netty EventLoopGroup using the platform-optimized I/O handler with the specified thread count.
    static it.unimi.dsi.fastutil.ints.Int2ObjectMap<BabelNetworkMessageSerializer<?>>
    getSerializersMap(Set<Class<? extends BabelMessage>> interestedMessages)
    Builds a fast map from message-type IDs to their serializers for the given set of interested message classes.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • BABEL_MAGIC_NUMBER

      public static final int BABEL_MAGIC_NUMBER
      Magic number (0xBABE12) written at the start of every regular Babel message frame. Receiving handlers verify this value before proceeding with deserialization; a mismatch causes a DecoderException.
      See Also:
    • DATAGRAM_CHANNEL_CLASS

      public static final Class<? extends io.netty.channel.socket.DatagramChannel> DATAGRAM_CHANNEL_CLASS
      Datagram channel class selected for the current OS (epoll / kqueue / NIO).
    • SOCKET_CHANNEL_CLASS

      public static final Class<? extends io.netty.channel.socket.SocketChannel> SOCKET_CHANNEL_CLASS
      Socket channel class selected for the current OS (epoll / kqueue / NIO).
    • SERVER_CHANNEL_CLASS

      public static final Class<? extends io.netty.channel.socket.ServerSocketChannel> SERVER_CHANNEL_CLASS
      Server socket channel class selected for the current OS (epoll / kqueue / NIO).
    • IO_HANLDER

      public static final io.netty.channel.IoHandlerFactory IO_HANLDER
      I/O handler factory selected for the current OS (epoll / kqueue / NIO).
  • Method Details

    • getSerializersMap

      public static it.unimi.dsi.fastutil.ints.Int2ObjectMap<BabelNetworkMessageSerializer<?>> getSerializersMap(Set<Class<? extends BabelMessage>> interestedMessages)
      Builds a fast map from message-type IDs to their serializers for the given set of interested message classes.

      Uses an Int2ObjectArrayMap for small sets (<= 16 types) and an Int2ObjectOpenHashMap for larger sets to optimise both memory and lookup speed.

      Parameters:
      interestedMessages - the set of message classes whose serializers should be indexed
      Returns:
      an unmodifiable map from message type ID to the corresponding serializer
    • createLoopGroup

      public static io.netty.channel.EventLoopGroup createLoopGroup(int numberOfThreads)
      Creates a new Netty EventLoopGroup using the platform-optimized I/O handler with the specified thread count.
      Parameters:
      numberOfThreads - the number of event loop threads
      Returns:
      a newly configured event loop group
    • createLoopGroup

      public static io.netty.channel.EventLoopGroup createLoopGroup()
      Creates a new Netty EventLoopGroup using the platform-optimized I/O handler with the default thread count.
      Returns:
      a newly configured event loop group