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 Summary
Modifier and TypeMethodDescriptionbuild()Validates the builder and creates a newJGroupsRaftinstance.Configures the underlyingRAFTprotocol.registerMarshaller(JGroupsRaftCustomMarshaller<?> marshaller) Register a new marshaler to serialize commands.voidvalidate()withClusterName(String clusterName) Defines the name of the cluster to create with JGroups.withJChannel(org.jgroups.JChannel channel) Defines the JGroups channel to be used.withJGroupsConfig(InputStream jgroupsConfig) Defines the JGroups configuration file to be used.withJGroupsConfig(String jgroupsConfig) Defines the path to the JGroups configuration file.withRuntimeProperties(Properties properties) Defines configuration properties to be used.withRuntimeProperties(RuntimeProperties runtimeProperties) Defines configuration properties to be used.
-
Method Details
-
withClusterName
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
Defines the JGroups configuration file to be used.The JGroups configuration file is utilized to create the JGroups channel.
- Specified by:
withJGroupsConfigin interfaceJGroupsRaft.JGroupsBuilderStep<JGroupsRaft<T>, JGroupsRaft.Builder<T>>- Parameters:
jgroupsConfig- file with the JGroups configuration.- Returns:
- the builder instance.
-
withJGroupsConfig
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:
withJGroupsConfigin interfaceJGroupsRaft.JGroupsBuilderStep<JGroupsRaft<T>, JGroupsRaft.Builder<T>>- Parameters:
jgroupsConfig- path to the JGroups configuration file.- Returns:
- the builder instance.
-
withRuntimeProperties
Defines configuration properties to be used.- Parameters:
runtimeProperties- configuration properties to be used.- Returns:
- the builder instance.
-
withRuntimeProperties
Defines configuration properties to be used.- Parameters:
properties- configuration properties to be used.- Returns:
- the builder instance.
-
withJChannel
Defines the JGroups channel to be used.The JGroups channel must contain a valid stack. The stack requires
RAFTand 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:
withJChannelin interfaceJGroupsRaft.JGroupsBuilderStep<JGroupsRaft<T>, JGroupsRaft.Builder<T>>- Parameters:
channel- the JGroups channel to be used.- Returns:
- the builder instance.
-
registerMarshaller
Register a new marshaler to serialize commands.- Parameters:
marshaller- the marshaler to be registered.- Returns:
- the builder instance.
-
configureRaft
-
validate
public void validate() -
build
Validates the builder and creates a newJGroupsRaftinstance.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.
-