Class UDPBabelChannelBuilder
java.lang.Object
pt.unl.fct.di.novasys.babel2.channels.AbstractBabelChannelBuilder<UDPBabelChannelBuilder>
pt.unl.fct.di.novasys.babel2.channels.AbstractIPBabelChannelBuilder<UDPBabelChannelBuilder>
pt.unl.fct.di.novasys.babel2.channels.udp.UDPBabelChannelBuilder
- All Implemented Interfaces:
BabelChannelBuilder
Builder / factory for
UDPBabelChannel instances.
Configure the desired bind address and optional multicast parameters before building the channel:
BabelChannel channel = UDPBabelChannel.builder()
.setBindingAddress(new InetSocketAddress("0.0.0.0", 7000))
.build(babelRuntime, store, myself, protocol);
Once build(Babel, NodeStore, BabelNode, BabelProtocol) has been called, subsequent calls return the same UDPBabelChannel instance.
-
Field Summary
Fields inherited from class AbstractIPBabelChannelBuilder
DEFAULT_CONNECTION_UP_DELAY, DEFAULT_CONNECTION_UP_DELAY_UNITModifier and TypeFieldDescriptionstatic final longDefault delay in milliseconds before dispatching connection-up notifications.static final TimeUnitDefault time unit forAbstractIPBabelChannelBuilder.DEFAULT_CONNECTION_UP_DELAY.Fields inherited from class AbstractBabelChannelBuilder
DEFAULT_NUMBER_OF_CONNECTIONS, DEFAULT_NUMBER_OF_MESSAGESModifier and TypeFieldDescriptionstatic final intDefault number of connections to expect when initializing the channel.static final intDefault number of message types expected by this channel. -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a newUDPBabelChannelBuilderbinding to the default port 7964. -
Method Summary
Modifier and TypeMethodDescriptionaddMulticastAddress(InetSocketAddress multicastAddress) Adds a multicast group address to join and broadcast to.build(Babel runtime, NodeStore store, BabelNode identity, BabelProtocol protocol) Creates a newBabelChannelinstance, registering it with the givenruntimeand limiting its interest to the provided message types.setNumberOfMulticastTtl(int multicastTtl) Sets the Time-To-Live (TTL) hop count for outgoing multicast packets.Methods inherited from class AbstractIPBabelChannelBuilder
getBindingAddress, getConnectionUpDelay, getConnectionUpDelayUnit, getEventLoopGroup, setBindingAddress, setConnectionUpDelay, setConnectionUpDelay, setEventLoopGroupModifier and TypeMethodDescriptionprotected final InetSocketAddressReturns the currently configured binding address.protected final longReturns the configured connection up delay value.protected final TimeUnitReturns the time unit of the connection up delay.protected final io.netty.channel.EventLoopGroupReturns the configured event loop group, initializing a default one viaBabelIpUtils.createLoopGroup()if none has been set.final UDPBabelChannelBuildersetBindingAddress(InetSocketAddress bindingAddress) Sets the local IP socket address to which the channel should bind.final UDPBabelChannelBuildersetConnectionUpDelay(long delayMillis) Sets the delay in milliseconds before notifying the runtime that a connection is fully up.final UDPBabelChannelBuildersetConnectionUpDelay(long delay, TimeUnit unit) Sets the delay and unit before notifying the runtime that a connection is fully up.final UDPBabelChannelBuildersetEventLoopGroup(io.netty.channel.EventLoopGroup eventLoopGroup) Configures the NettyEventLoopGroupused for network I/O.Methods inherited from class AbstractBabelChannelBuilder
getChannel, getNumberOfConnections, getNumberOfMessages, setChannel, setNumberOfConnections, setNumberOfMessages, validateStateOrThrowModifier and TypeMethodDescriptionprotected final @Nullable BabelChannelReturns the channel instance created by this builder, ornullif not yet built.protected final intGets the expected number of connections set in this builder.protected final intGets the expected number of messages set in this builder.protected final voidsetChannel(BabelChannel channel) Sets the constructed channel instance created by this builder.final UDPBabelChannelBuildersetNumberOfConnections(int numberOfConnections) Sets the default number of connections expected.final UDPBabelChannelBuildersetNumberOfMessages(int numberOfMessages) Sets the expected number of distinct message types handled by this channel.protected final voidValidates that this builder has not yet built its channel instance.
-
Constructor Details
-
UDPBabelChannelBuilder
public UDPBabelChannelBuilder()Constructs a newUDPBabelChannelBuilderbinding to the default port 7964.
-
-
Method Details
-
setNumberOfMulticastTtl
Sets the Time-To-Live (TTL) hop count for outgoing multicast packets.- Parameters:
multicastTtl- the multicast TTL value- Returns:
- this builder instance
- Throws:
IllegalStateException- if the channel has already been built
-
addMulticastAddress
Adds a multicast group address to join and broadcast to.- Parameters:
multicastAddress- the multicast socket address- Returns:
- this builder instance
- Throws:
IllegalArgumentException- if the provided address is not a multicast addressIllegalStateException- if the channel has already been built
-
build
public BabelChannel build(Babel runtime, NodeStore store, BabelNode identity, BabelProtocol protocol) Description copied from interface:BabelChannelBuilderCreates a newBabelChannelinstance, registering it with the givenruntimeand limiting its interest to the provided message types.- Parameters:
runtime- the owningBabelruntimestore- theNodeStorethat will be used by this channelidentity-BabelNodeobject used to represent this Babel instance to other instancesprotocol- the protocol instance associated with this channel- Returns:
- a ready-to-use
BabelChannel
-