Class BabelBootstrap

java.lang.Object
pt.unl.fct.di.novasys.babel2.core.BabelBootstrap

public final class BabelBootstrap extends Object
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 Details

    • DEFAULT_NUMBER_OF_PROTOCOLS

      public static final int DEFAULT_NUMBER_OF_PROTOCOLS
      Default expected number of protocols used to size internal maps.
      See Also:
    • DEFAULT_NUMBER_OF_EXTENSIONS

      public static final int DEFAULT_NUMBER_OF_EXTENSIONS
      Default expected number of protocol extensions used to size internal maps.
      See Also:
    • DEFAULT_NUMBER_OF_MESSAGES

      public static final int DEFAULT_NUMBER_OF_MESSAGES
      Default expected number of distinct message types used to size internal maps.
      See Also:
    • DEFAULT_NUMBER_OF_EVENTS

      public static final int DEFAULT_NUMBER_OF_EVENTS
      Default expected number of distinct event types used to size internal maps.
      See Also:
    • DEFAULT_NUMBER_OF_CHANNELS

      public static final int DEFAULT_NUMBER_OF_CHANNELS
      Default 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 register
      holderFactory - the factory used to create a BabelProtocolHolder for this protocol
      channelFactories - 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 a ProtocolExtensionFactory that will be applied to every registered protocol that is an instance of protocol.

      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 extension
      extension - the factory that produces extension instances
      Returns:
      this builder
    • setNodeStore

      public BabelBootstrap setNodeStore(NodeStore store)
      Sets the node store to be used by the runtime.
      Parameters:
      store - the node store implementation
      Returns:
      this builder for fluent chaining
    • setKeyPair

      public BabelBootstrap setKeyPair(KeyPair keyPair)
      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

      public BabelBootstrap setMyself(BabelNode myself)
      Sets the local BabelNode identity representing this node.
      Parameters:
      myself - the local node identity
      Returns:
      this builder for fluent chaining
    • build

      public Babel build()
      Constructs and returns the configured Babel runtime instance.

      Call Babel.init() on the returned instance to deliver the StartEvent to each protocol and begin processing.

      Returns:
      a fully initialised but not yet started Babel runtime