Class BabelBootstrap
java.lang.Object
pt.unl.fct.di.novasys.babel2.core.BabelBootstrap
Builder class for configuring and creating a
Babel runtime instance.
BabelBootstrap configures the protocols, channel builders, protocol extensions, node store, and cryptographic identity of the node before instantiating the runtime.
Babel babel = Babel.builder()
.setKeyPair(myKeyPair)
.setNodeStore(myStore)
.registerProtocol(myProtocol, holderFactory, channelBuilder)
.build()
.init();
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault expected number of channels used to size internal structures.static final intDefault expected number of distinct event types used to size internal maps.static final intDefault expected number of protocol extensions used to size internal maps.static final intDefault expected number of distinct message types used to size internal maps.static final intDefault expected number of protocols used to size internal maps. -
Method Summary
Modifier and TypeMethodDescriptionbuild()Constructs and returns the configuredBabelruntime instance.registerExtension(Class<? extends BabelProtocol> protocol, ProtocolExtensionFactory extension) Registers aProtocolExtensionFactorythat will be applied to every registered protocol that is an instance ofprotocol.registerProtocol(BabelProtocol protocol, BabelProtocolHolderFactory holderFactory, BabelChannelBuilder... channelFactories) Registers a protocol instance with this Babel runtime, optionally associating it with one or more channel builders.setKeyPair(KeyPair keyPair) Sets the asymmetric key pair representing the cryptographic identity of the local node.Sets the localBabelNodeidentity representing this node.setNodeStore(NodeStore store) Sets the node store to be used by the runtime.
-
Field Details
-
DEFAULT_NUMBER_OF_PROTOCOLS
public static final int DEFAULT_NUMBER_OF_PROTOCOLSDefault expected number of protocols used to size internal maps.- See Also:
-
DEFAULT_NUMBER_OF_EXTENSIONS
public static final int DEFAULT_NUMBER_OF_EXTENSIONSDefault expected number of protocol extensions used to size internal maps.- See Also:
-
DEFAULT_NUMBER_OF_MESSAGES
public static final int DEFAULT_NUMBER_OF_MESSAGESDefault expected number of distinct message types used to size internal maps.- See Also:
-
DEFAULT_NUMBER_OF_EVENTS
public static final int DEFAULT_NUMBER_OF_EVENTSDefault expected number of distinct event types used to size internal maps.- See Also:
-
DEFAULT_NUMBER_OF_CHANNELS
public static final int DEFAULT_NUMBER_OF_CHANNELSDefault expected number of channels used to size internal structures.- See Also:
-
-
Method Details
-
registerProtocol
public BabelBootstrap registerProtocol(BabelProtocol protocol, BabelProtocolHolderFactory holderFactory, BabelChannelBuilder... channelFactories) Registers a protocol instance with this Babel runtime, optionally associating it with one or more channel builders.- Parameters:
protocol- the protocol instance to registerholderFactory- the factory used to create aBabelProtocolHolderfor this protocolchannelFactories- an array of channel builders to associate with the protocol- Returns:
- this builder for fluent chaining
-
registerExtension
public BabelBootstrap registerExtension(Class<? extends BabelProtocol> protocol, ProtocolExtensionFactory extension) Registers aProtocolExtensionFactorythat will be applied to every registered protocol that is an instance ofprotocol.Extensions are used to augment protocols with cross-cutting capabilities (e.g., broadcast consumer/provider, membership consumer/provider) without requiring the protocol implementation to subclass a specific base class.
- Parameters:
protocol- the protocol interface or class that triggers this extensionextension- the factory that produces extension instances- Returns:
- this builder
-
setNodeStore
Sets the node store to be used by the runtime.- Parameters:
store- the node store implementation- Returns:
- this builder for fluent chaining
-
setKeyPair
Sets the asymmetric key pair representing the cryptographic identity of the local node.- Parameters:
keyPair- the key pair containing public and private keys- Returns:
- this builder for fluent chaining
-
setMyself
Sets the localBabelNodeidentity representing this node.- Parameters:
myself- the local node identity- Returns:
- this builder for fluent chaining
-
build
Constructs and returns the configuredBabelruntime instance.Call
Babel.init()on the returned instance to deliver theStartEventto each protocol and begin processing.- Returns:
- a fully initialised but not yet started
Babelruntime
-