Class JGroupsRaft.Builder<T>

java.lang.Object
org.jgroups.raft.JGroupsRaft.Builder<T>
All Implemented Interfaces:
JGroupsRaft.JGroupsBuilderStep<JGroupsRaft<T>, JGroupsRaft.Builder<T>>
Enclosing interface:
JGroupsRaft<T>

public static final class JGroupsRaft.Builder<T> extends Object implements JGroupsRaft.JGroupsBuilderStep<JGroupsRaft<T>, JGroupsRaft.Builder<T>>
Since:
2.0
Author:
José Bolina
  • Method Details

    • withClusterName

      public JGroupsRaft.Builder<T> withClusterName(String clusterName)
      Defines the name of the cluster to create with JGroups.

      The cluster name is utilized when connecting the JGroups channel. All nodes must share the same name to create a cluster.

      Parameters:
      clusterName - name of the cluster to create with JGroups.
      Returns:
      the builder instance.
    • withJGroupsConfig

      public JGroupsRaft.Builder<T> withJGroupsConfig(InputStream jgroupsConfig)
      Defines the JGroups configuration file to be used.

      The JGroups configuration file is utilized to create the JGroups channel.

      Specified by:
      withJGroupsConfig in interface JGroupsRaft.JGroupsBuilderStep<JGroupsRaft<T>, JGroupsRaft.Builder<T>>
      Parameters:
      jgroupsConfig - file with the JGroups configuration.
      Returns:
      the builder instance.
    • withJGroupsConfig

      public JGroupsRaft.Builder<T> withJGroupsConfig(String jgroupsConfig)
      Defines the path to the JGroups configuration file.

      The JGroups configuration file is utilized to create the JGroups channel. The file must be in the classpath.

      Specified by:
      withJGroupsConfig in interface JGroupsRaft.JGroupsBuilderStep<JGroupsRaft<T>, JGroupsRaft.Builder<T>>
      Parameters:
      jgroupsConfig - path to the JGroups configuration file.
      Returns:
      the builder instance.
    • withRuntimeProperties

      public JGroupsRaft.Builder<T> withRuntimeProperties(RuntimeProperties runtimeProperties)
      Defines configuration properties to be used.
      Parameters:
      runtimeProperties - configuration properties to be used.
      Returns:
      the builder instance.
    • withRuntimeProperties

      public JGroupsRaft.Builder<T> withRuntimeProperties(Properties properties)
      Defines configuration properties to be used.
      Parameters:
      properties - configuration properties to be used.
      Returns:
      the builder instance.
    • withJChannel

      public JGroupsRaft.Builder<T> withJChannel(org.jgroups.JChannel channel)
      Defines the JGroups channel to be used.

      The JGroups channel must contain a valid stack. The stack requires RAFT and an election algorithm.

      If the channel is disconnected, the instance will manage the channel's lifecycle to start and shutdown. Otherwise, the channel must be sopped by the application.

      Specified by:
      withJChannel in interface JGroupsRaft.JGroupsBuilderStep<JGroupsRaft<T>, JGroupsRaft.Builder<T>>
      Parameters:
      channel - the JGroups channel to be used.
      Returns:
      the builder instance.
    • registerMarshaller

      public JGroupsRaft.Builder<T> registerMarshaller(JGroupsRaftCustomMarshaller<?> marshaller)
      Register a new marshaler to serialize commands.
      Parameters:
      marshaller - the marshaler to be registered.
      Returns:
      the builder instance.
    • configureRaft

      public RaftProtocolBuilder<T> configureRaft()
      Configures the underlying RAFT protocol.

      This configuration will take precedence over the configurations defined in the configuration file.

      Returns:
      A builder to configure the RAFT protocol.
    • validate

      public void validate()
    • build

      public JGroupsRaft<T> build()
      Validates the builder and creates a new JGroupsRaft instance.

      The builder has specific requirements:

      • Either a JGroups channel or the configuration must be provided;
      • If a configuration is provided, the cluster name must be defined;
      • If a disconnected channel is provided, the cluster name must be defined;

      Returns:
      A new instance.
      Throws:
      IllegalStateException - if the builder is not properly configured.
      JRaftException - if an error occurs while creating the instance.