Class BabelIpUtils
java.lang.Object
pt.unl.fct.di.novasys.babel2.channels.utils.BabelIpUtils
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:
- epoll — used on Linux kernels that support it (best performance).
- kqueue — used on macOS / BSD kernels (good performance).
- NIO — portable fallback for other platforms.
This class is not instantiable.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intMagic 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.IoHandlerFactoryI/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 TypeMethodDescriptionstatic io.netty.channel.EventLoopGroupCreates a new NettyEventLoopGroupusing the platform-optimized I/O handler with the default thread count.static io.netty.channel.EventLoopGroupcreateLoopGroup(int numberOfThreads) Creates a new NettyEventLoopGroupusing 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.
-
Field Details
-
BABEL_MAGIC_NUMBER
public static final int BABEL_MAGIC_NUMBERMagic number (0xBABE12) written at the start of every regular Babel message frame. Receiving handlers verify this value before proceeding with deserialization; a mismatch causes aDecoderException.- See Also:
-
DATAGRAM_CHANNEL_CLASS
Datagram channel class selected for the current OS (epoll / kqueue / NIO). -
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_CLASSServer socket channel class selected for the current OS (epoll / kqueue / NIO). -
IO_HANLDER
public static final io.netty.channel.IoHandlerFactory IO_HANLDERI/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
Int2ObjectArrayMapfor small sets (<= 16types) and anInt2ObjectOpenHashMapfor 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 NettyEventLoopGroupusing 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 NettyEventLoopGroupusing the platform-optimized I/O handler with the default thread count.- Returns:
- a newly configured event loop group
-