Class UDPBabelChannel

java.lang.Object
pt.unl.fct.di.novasys.babel2.channels.udp.UDPBabelChannel
All Implemented Interfaces:
BabelChannel, BroadcastIPBabelChannel, IPBabelChannel

public class UDPBabelChannel extends Object implements BroadcastIPBabelChannel
Babel 2 channel implementation that transports messages as connectionless UDP datagrams.

Unlike the TCP and QUIC channels, UDPBabelChannel does not maintain persistent connections. Each message is sent as a separate datagram addressed to the target peer via sendEphemeral(BabelNode, BabelMessage). The connection-oriented operations (connect(BabelNode), disconnect(BabelNode), send(BabelNode, BabelMessage), and isConnected(BabelNode)) are all unsupported and will throw UnsupportedOperationException.

The channel binds a single Netty DatagramChannel to the address provided at construction time. Incoming datagrams are decoded by UDPBabelMessageCodec and delivered to the Babel runtime as MessageInEvent notifications by UDPBabelDeliver. Outgoing datagrams are encoded by UDPBabelMessageCodec.

The underlying transport (epoll / kqueue / NIO) is selected automatically by BabelIpUtils based on OS availability.

Use builder() to obtain a UDPBabelChannelBuilder and configure the channel before passing it to the Babel runtime.

  • Method Details

    • connect

      public void connect(BabelNode peer)
      Description copied from interface: BabelChannel
      Connect to another Babel runtime. The pecularities of how a channel "connects" to another Babel runtime is up to its implementation. Whether the connection is successful or not, this method should trigger the ConnectionUpEvent or ConnectionFailedEvent. May throw UnsupportedOperationException
      Specified by:
      connect in interface BabelChannel
      Parameters:
      peer - the peer to connect to
    • sendEphemeral

      public void sendEphemeral(BabelNode peer, BabelMessage message)
      Description copied from interface: BabelChannel
      Sends a message to peer without establishing a persistent connection. The channel implementation may use a transient transport internally, but none of the connection lifecycle events (connectionUp / connectionDown) are triggered.
      Specified by:
      sendEphemeral in interface BabelChannel
      Parameters:
      peer - the target node
      message - the message to deliver
    • send

      public void send(BabelNode peer, BabelMessage message)
      Description copied from interface: BabelChannel
      Sends a message through this channel to the given peer using a persistent connection. If the connection is not currently open, the message may be queued depending on the implementation.
      Specified by:
      send in interface BabelChannel
      Parameters:
      peer - the peer to send the message to
      message - the message to be sent
    • disconnect

      public void disconnect(BabelNode peer)
      Description copied from interface: BabelChannel
      Closes the connection to peer. A ConnectionDownEvent will be delivered to interested protocols after the connection has been torn down.
      Specified by:
      disconnect in interface BabelChannel
      Parameters:
      peer - the node to disconnect from
    • isConnected

      public boolean isConnected(BabelNode peer)
      Description copied from interface: BabelChannel
      Returns true if a connection to peer is currently open on this channel.
      Specified by:
      isConnected in interface BabelChannel
      Parameters:
      peer - the node whose connection status is queried
      Returns:
      true if connected, false otherwise
    • shutdown

      public void shutdown()
      Description copied from interface: BabelChannel
      Releases all resources held by this channel, closing any open connections.
      Specified by:
      shutdown in interface BabelChannel
    • builder

      public static UDPBabelChannelBuilder builder()
      Returns a new UDPBabelChannelBuilder configured with default settings.
      Returns:
      a new UDP channel builder
    • multicast

      public void multicast(BabelMessage message)
      Description copied from interface: BroadcastIPBabelChannel
      Multicast for all the connected local network nodes. The multicast address must be set during the instantiation of the channel. The channel should also be listening in the same multicast address and port.
      Specified by:
      multicast in interface BroadcastIPBabelChannel
      Parameters:
      message - message to be broadcasted.
    • getBindingAddress

      public InetSocketAddress getBindingAddress()
      Description copied from interface: IPBabelChannel
      Returns the local IP socket address to which this channel is bound.
      Specified by:
      getBindingAddress in interface IPBabelChannel
      Returns:
      the local binding InetSocketAddress