Class CPSubsystemConfig
- java.lang.Object
-
- com.hazelcast.config.cp.CPSubsystemConfig
-
public class CPSubsystemConfig extends java.lang.Object
Contains configuration options for CP Subsystem.You can check the following code snippet to see how CP Subsystem can be initialized by configuring only the
setCPMemberCount(int)
value. In this code, we set 3 tosetCPMemberCount(int)
, and we don't set any value tosetGroupSize(int)
. Therefore, there will be 3 CP members in CP Subsystem and each CP groups will have 3 CP members as well.int cpMemberCount = 3; int apMemberCount = 2; int memberCount = cpMemberCount + apMemberCount; Config config = new Config(); config.getCPSubsystemConfig().setCPMemberCount(cpMemberCount); HazelcastInstance[] instances = new HazelcastInstance[memberCount]; for (int i = 0; i < memberCount; i++) { instances[i] = Hazelcast.newHazelcastInstance(config); } // update an atomic long via a CP member IAtomicLong cpLong = instances[0].getCPSubsystem().getAtomicLong("myLong"); cpLong.set(10); // access to its value via an AP member cpLong = instances[cpMemberCount].getCPSubsystem().getAtomicLong("myLong"); System.out.println(cpLong.get());
In the following code snippet, we configure
setCPMemberCount(int)
to 5 andsetGroupSize(int)
to 3, therefore there will be 5 CP members and CP groups will be initialized by selecting 3 random CP members among them.int cpMemberCount = 5; int apMemberCount = 2; int groupSize = 3; int memberCount = cpMemberCount + apMemberCount; Config config = new Config(); config.getCPSubsystemConfig() .setCPMemberCount(cpMemberCount) .setGroupSize(groupSize); HazelcastInstance[] instances = new HazelcastInstance[memberCount]; for (int i = 0; i < memberCount; i++) { instances[i] = Hazelcast.newHazelcastInstance(config); } // update an atomic long via a CP member IAtomicLong cpLong = instances[0].getCPSubsystem().getAtomicLong("myLong"); cpLong.set(10); // access to its value via an AP member cpLong = instances[cpMemberCount].getCPSubsystem().getAtomicLong("myLong"); System.out.println(cpLong.get());
- See Also:
CPSubsystem
,CPMember
,CPSession
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CP_BASE_DIR_DEFAULT
The default directory name for storing CP data.static int
DEFAULT_CP_MAP_LIMIT
The default limit number ofCPMap
that can be created.static int
DEFAULT_DATA_LOAD_TIMEOUT_SECONDS
The default data load timeout duration for restoring CP data from disk.static int
DEFAULT_HEARTBEAT_INTERVAL_SECONDS
The default duration for the periodically-committed CP session heartbeats.static int
DEFAULT_MISSING_CP_MEMBER_AUTO_REMOVAL_SECONDS
The default duration to wait before automatically removing a missing CP member from CP Subsystem.static int
DEFAULT_SESSION_TTL_SECONDS
The default value for a CP session to be kept alive after the last heartbeat it has received.static int
MAX_GROUP_SIZE
The maximum number of CP members that can form a CP group.static int
MIN_GROUP_SIZE
The minimum number of CP members that can form a CP group.
-
Constructor Summary
Constructors Constructor Description CPSubsystemConfig()
CPSubsystemConfig(CPSubsystemConfig config)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CPSubsystemConfig
addCPMapConfig(CPMapConfig cpMapConfig)
Adds theCPMapConfig
configuration.CPSubsystemConfig
addLockConfig(FencedLockConfig lockConfig)
Adds theFencedLock
configuration.CPSubsystemConfig
addSemaphoreConfig(SemaphoreConfig semaphoreConfig)
Adds the CPISemaphore
configuration.boolean
equals(java.lang.Object o)
CPMapConfig
findCPMapConfig(java.lang.String name)
Returns theCPMapConfig
configuration for the given name.FencedLockConfig
findLockConfig(java.lang.String name)
Returns theFencedLock
configuration for the given name.SemaphoreConfig
findSemaphoreConfig(java.lang.String name)
Returns the CPISemaphore
configuration for the given name.java.io.File
getBaseDir()
Returns the base directory for persisting CP data.java.util.Map<java.lang.String,CPMapConfig>
getCpMapConfigs()
Returns the map ofCPMap
configurationsint
getCPMapLimit()
Gets the limit ofCPMap
instances that are permitted to be created.int
getCPMemberCount()
Returns the number of CP members that will initialize CP Subsystem.int
getCPMemberPriority()
Returns the CP member priority.int
getDataLoadTimeoutSeconds()
Returns the timeout duration for CP members to restore their data from stable storage.int
getGroupSize()
Returns the number of CP members to form CP groups.java.util.Map<java.lang.String,FencedLockConfig>
getLockConfigs()
Returns the map ofFencedLock
configurationsint
getMissingCPMemberAutoRemovalSeconds()
Returns the duration to wait before automatically removing a missing CP member from CP SubsystemRaftAlgorithmConfig
getRaftAlgorithmConfig()
Returns configuration options for Hazelcast's Raft consensus algorithm implementationjava.util.Map<java.lang.String,SemaphoreConfig>
getSemaphoreConfigs()
Returns the map of CPISemaphore
configurationsint
getSessionHeartbeatIntervalSeconds()
Returns the interval for the periodically-committed CP session heartbeats.int
getSessionTimeToLiveSeconds()
Returns the duration for a CP session to be kept alive after its last session heartbeat.int
hashCode()
boolean
isFailOnIndeterminateOperationState()
Returns the value to determine if CP Subsystem API calls will fail when result of an API call becomes indeterminate.boolean
isPersistenceEnabled()
Returns whether CP Subsystem Persistence enabled on this member.CPSubsystemConfig
setBaseDir(java.io.File baseDir)
Sets the base directory for persisting CP data.CPSubsystemConfig
setCPMapConfigs(java.util.Map<java.lang.String,CPMapConfig> cpMapConfigs)
Sets the map ofCPMapConfig
configurations, mapped by config name.CPSubsystemConfig
setCPMapLimit(int cpMapLimit)
Sets the limit of permittedCPMap
instances.CPSubsystemConfig
setCPMemberCount(int cpMemberCount)
Sets the CP member count to initialize CP Subsystem.CPSubsystemConfig
setCPMemberPriority(int cpMemberPriority)
Sets the CP member priority.CPSubsystemConfig
setDataLoadTimeoutSeconds(int dataLoadTimeoutSeconds)
Sets the timeout duration for CP members to restore their data from stable storage.CPSubsystemConfig
setFailOnIndeterminateOperationState(boolean failOnIndeterminateOperationState)
Sets the value to determine if CP Subsystem calls will fail when result of an API call becomes indeterminate.CPSubsystemConfig
setGroupSize(int groupSize)
Sets the number of CP members to form CP groups.CPSubsystemConfig
setLockConfigs(java.util.Map<java.lang.String,FencedLockConfig> lockConfigs)
Sets the map ofFencedLock
configurations, mapped by config name.CPSubsystemConfig
setMissingCPMemberAutoRemovalSeconds(int missingCPMemberAutoRemovalSeconds)
Sets the duration to wait before automatically removing a missing CP member from CP Subsystem.CPSubsystemConfig
setPersistenceEnabled(boolean persistenceEnabled)
Sets whether CP Subsystem Persistence is enabled on this member.CPSubsystemConfig
setRaftAlgorithmConfig(RaftAlgorithmConfig raftAlgorithmConfig)
Sets configuration options for Hazelcast's Raft consensus algorithm implementationCPSubsystemConfig
setSemaphoreConfigs(java.util.Map<java.lang.String,SemaphoreConfig> semaphoreConfigs)
Sets the map of CPISemaphore
configurations, mapped by config name.CPSubsystemConfig
setSessionHeartbeatIntervalSeconds(int sessionHeartbeatIntervalSeconds)
Sets the interval for the periodically-committed CP session heartbeats.CPSubsystemConfig
setSessionTimeToLiveSeconds(int sessionTimeToLiveSeconds)
Sets the duration for a CP session to be kept alive after its last session heartbeat.java.lang.String
toString()
-
-
-
Field Detail
-
DEFAULT_SESSION_TTL_SECONDS
public static final int DEFAULT_SESSION_TTL_SECONDS
The default value for a CP session to be kept alive after the last heartbeat it has received. SeesessionTimeToLiveSeconds
-
DEFAULT_HEARTBEAT_INTERVAL_SECONDS
public static final int DEFAULT_HEARTBEAT_INTERVAL_SECONDS
The default duration for the periodically-committed CP session heartbeats. SeesessionHeartbeatIntervalSeconds
- See Also:
- Constant Field Values
-
MIN_GROUP_SIZE
public static final int MIN_GROUP_SIZE
The minimum number of CP members that can form a CP group. SeegroupSize
- See Also:
- Constant Field Values
-
MAX_GROUP_SIZE
public static final int MAX_GROUP_SIZE
The maximum number of CP members that can form a CP group. Theoretically, there is no upper bound on the number of CP members to run the Raft consensus algorithm. However, since the Raft consensus algorithm synchronously replicates operations to the majority of a CP group members, a larger CP group means more replication overhead, and memory consumption as well. The current maximum CP group size limit offers a sufficient degree of fault tolerance for CP Subsystem usages.See
groupSize
- See Also:
- Constant Field Values
-
DEFAULT_MISSING_CP_MEMBER_AUTO_REMOVAL_SECONDS
public static final int DEFAULT_MISSING_CP_MEMBER_AUTO_REMOVAL_SECONDS
The default duration to wait before automatically removing a missing CP member from CP Subsystem. SeemissingCPMemberAutoRemovalSeconds
-
CP_BASE_DIR_DEFAULT
public static final java.lang.String CP_BASE_DIR_DEFAULT
The default directory name for storing CP data. SeebaseDir
- See Also:
- Constant Field Values
-
DEFAULT_DATA_LOAD_TIMEOUT_SECONDS
public static final int DEFAULT_DATA_LOAD_TIMEOUT_SECONDS
The default data load timeout duration for restoring CP data from disk. SeedataLoadTimeoutSeconds
- See Also:
- Constant Field Values
-
DEFAULT_CP_MAP_LIMIT
public static final int DEFAULT_CP_MAP_LIMIT
The default limit number ofCPMap
that can be created.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CPSubsystemConfig
public CPSubsystemConfig()
-
CPSubsystemConfig
public CPSubsystemConfig(CPSubsystemConfig config)
-
-
Method Detail
-
getCPMemberCount
public int getCPMemberCount()
Returns the number of CP members that will initialize CP Subsystem. CP Subsystem is disabled if it is 0.- Returns:
- the number of CP members that will initialize CP Subsystem
-
setCPMemberCount
public CPSubsystemConfig setCPMemberCount(int cpMemberCount)
Sets the CP member count to initialize CP Subsystem. CP Subsystem is disabled if 0. Cannot be smaller thanMIN_GROUP_SIZE
andgroupSize
- Returns:
- this config instance
-
getGroupSize
public int getGroupSize()
Returns the number of CP members to form CP groups. Returns 0 ifcpMemberCount
is 0. If group size is not set: - returns the CP member count if it is an odd number, - returns the CP member count - 1 if it is an even number.- Returns:
- the number of CP members to form CP groups
-
setGroupSize
public CPSubsystemConfig setGroupSize(int groupSize)
Sets the number of CP members to form CP groups. Must be an odd number betweenMIN_GROUP_SIZE
andMAX_GROUP_SIZE
.- Returns:
- this config instance
-
getSessionTimeToLiveSeconds
public int getSessionTimeToLiveSeconds()
Returns the duration for a CP session to be kept alive after its last session heartbeat.- Returns:
- the duration for a CP session to be kept alive after its last session heartbeat
-
setSessionTimeToLiveSeconds
public CPSubsystemConfig setSessionTimeToLiveSeconds(int sessionTimeToLiveSeconds)
Sets the duration for a CP session to be kept alive after its last session heartbeat.- Returns:
- this config instance
-
getSessionHeartbeatIntervalSeconds
public int getSessionHeartbeatIntervalSeconds()
Returns the interval for the periodically-committed CP session heartbeats.- Returns:
- the interval for the periodically-committed CP session heartbeats
-
setSessionHeartbeatIntervalSeconds
public CPSubsystemConfig setSessionHeartbeatIntervalSeconds(int sessionHeartbeatIntervalSeconds)
Sets the interval for the periodically-committed CP session heartbeats.- Returns:
- this config instance
-
getMissingCPMemberAutoRemovalSeconds
public int getMissingCPMemberAutoRemovalSeconds()
Returns the duration to wait before automatically removing a missing CP member from CP Subsystem- Returns:
- the duration to wait before automatically removing a missing CP member from the CP Subsystem
-
setMissingCPMemberAutoRemovalSeconds
public CPSubsystemConfig setMissingCPMemberAutoRemovalSeconds(int missingCPMemberAutoRemovalSeconds)
Sets the duration to wait before automatically removing a missing CP member from CP Subsystem.- Returns:
- this config instance
-
isFailOnIndeterminateOperationState
public boolean isFailOnIndeterminateOperationState()
Returns the value to determine if CP Subsystem API calls will fail when result of an API call becomes indeterminate.- Returns:
- the value to determine if CP Subsystem calls will fail when result of an API call becomes indeterminate
-
setFailOnIndeterminateOperationState
public CPSubsystemConfig setFailOnIndeterminateOperationState(boolean failOnIndeterminateOperationState)
Sets the value to determine if CP Subsystem calls will fail when result of an API call becomes indeterminate.- Returns:
- this config instance
-
isPersistenceEnabled
public boolean isPersistenceEnabled()
Returns whether CP Subsystem Persistence enabled on this member.- Returns:
- true if CP Subsystem Persistence is enabled, false otherwise
-
setPersistenceEnabled
public CPSubsystemConfig setPersistenceEnabled(boolean persistenceEnabled)
Sets whether CP Subsystem Persistence is enabled on this member.- Returns:
- this config instance
-
getBaseDir
public java.io.File getBaseDir()
Returns the base directory for persisting CP data. Can be an absolute or relative path to the node startup directory.- Returns:
- returns the base directory for CP data
-
setBaseDir
public CPSubsystemConfig setBaseDir(java.io.File baseDir)
Sets the base directory for persisting CP data. Can be an absolute or relative path to the node startup directory.- Parameters:
baseDir
- base directory- Returns:
- this config instance
-
getDataLoadTimeoutSeconds
public int getDataLoadTimeoutSeconds()
Returns the timeout duration for CP members to restore their data from stable storage. A CP member fails its startup if it cannot complete its CP data restore process before this timeout duration.- Returns:
- the timeout duration for CP members to restore their data from stable storage
-
setDataLoadTimeoutSeconds
public CPSubsystemConfig setDataLoadTimeoutSeconds(int dataLoadTimeoutSeconds)
Sets the timeout duration for CP members to restore their data from stable storage. A CP member fails its startup if it cannot complete its CP data restore process before this timeout duration.- Parameters:
dataLoadTimeoutSeconds
- the timeout duration for CP members to restore their data from stable storage- Returns:
- this config instance
-
setCPMemberPriority
public CPSubsystemConfig setCPMemberPriority(int cpMemberPriority)
Sets the CP member priority. CP groups' leadership will be transferred to members with higher priorities within the CP group.- Parameters:
cpMemberPriority
- can be any integer number- Returns:
- this config instance
-
getCPMemberPriority
public int getCPMemberPriority()
Returns the CP member priority.- Returns:
- the CP member priority
-
getRaftAlgorithmConfig
public RaftAlgorithmConfig getRaftAlgorithmConfig()
Returns configuration options for Hazelcast's Raft consensus algorithm implementation- Returns:
- configuration options for Hazelcast's Raft consensus algorithm implementation
-
setRaftAlgorithmConfig
public CPSubsystemConfig setRaftAlgorithmConfig(RaftAlgorithmConfig raftAlgorithmConfig)
Sets configuration options for Hazelcast's Raft consensus algorithm implementation- Returns:
- this config instance
-
getSemaphoreConfigs
public java.util.Map<java.lang.String,SemaphoreConfig> getSemaphoreConfigs()
Returns the map of CPISemaphore
configurations- Returns:
- the map of CP
ISemaphore
configurations
-
findSemaphoreConfig
public SemaphoreConfig findSemaphoreConfig(java.lang.String name)
Returns the CPISemaphore
configuration for the given name.The name is matched by stripping the
CPGroup
name from the givenname
if present. Returns null if there is no config found by the givenname
- Parameters:
name
- name of the CPISemaphore
- Returns:
- the CP
ISemaphore
configuration
-
addSemaphoreConfig
public CPSubsystemConfig addSemaphoreConfig(SemaphoreConfig semaphoreConfig)
Adds the CPISemaphore
configuration. Name of the CPISemaphore
could optionally contain aCPGroup
name, like "mySemaphore@group1".- Parameters:
semaphoreConfig
- the CPISemaphore
configuration- Returns:
- this config instance
-
setSemaphoreConfigs
public CPSubsystemConfig setSemaphoreConfigs(java.util.Map<java.lang.String,SemaphoreConfig> semaphoreConfigs)
Sets the map of CPISemaphore
configurations, mapped by config name. Names could optionally contain aCPGroup
name, such as "mySemaphore@group1".- Parameters:
semaphoreConfigs
- the CPISemaphore
config map to set- Returns:
- this config instance
-
getLockConfigs
public java.util.Map<java.lang.String,FencedLockConfig> getLockConfigs()
Returns the map ofFencedLock
configurations- Returns:
- the map of
FencedLock
configurations
-
findLockConfig
public FencedLockConfig findLockConfig(java.lang.String name)
Returns theFencedLock
configuration for the given name.The name is matched by stripping the
CPGroup
name from the givenname
if present. Returns null if there is no config found by the givenname
- Parameters:
name
- name of theFencedLock
- Returns:
- the
FencedLock
configuration
-
addLockConfig
public CPSubsystemConfig addLockConfig(FencedLockConfig lockConfig)
Adds theFencedLock
configuration. Name of theFencedLock
could optionally contain aCPGroup
name, like "myLock@group1".- Parameters:
lockConfig
- theFencedLock
configuration- Returns:
- this config instance
-
setLockConfigs
public CPSubsystemConfig setLockConfigs(java.util.Map<java.lang.String,FencedLockConfig> lockConfigs)
Sets the map ofFencedLock
configurations, mapped by config name. Names could optionally contain aCPGroup
name, such as "myLock@group1".- Parameters:
lockConfigs
- theFencedLock
config map to set- Returns:
- this config instance
-
getCpMapConfigs
public java.util.Map<java.lang.String,CPMapConfig> getCpMapConfigs()
Returns the map ofCPMap
configurations- Returns:
- the map of
CPMapConfig
configurations - Since:
- 5.4
-
findCPMapConfig
public CPMapConfig findCPMapConfig(java.lang.String name)
Returns theCPMapConfig
configuration for the given name.The name is matched by stripping the
CPGroup
name from the givenname
if present. Returns null if there is no config found by the givenname
- Parameters:
name
- name of theCPMapConfig
- Returns:
- the
CPMapConfig
configuration - Since:
- 5.4
-
addCPMapConfig
public CPSubsystemConfig addCPMapConfig(CPMapConfig cpMapConfig)
Adds theCPMapConfig
configuration. Name of theCPMapConfig
could optionally contain aCPGroup
name, like "myMap@group1".- Parameters:
cpMapConfig
- theCPMapConfig
configuration- Returns:
- this config instance
- Since:
- 5.4
-
setCPMapConfigs
public CPSubsystemConfig setCPMapConfigs(java.util.Map<java.lang.String,CPMapConfig> cpMapConfigs)
Sets the map ofCPMapConfig
configurations, mapped by config name. Names could optionally contain aCPGroup
name, such as "myLock@group1".- Parameters:
cpMapConfigs
- theCPMapConfig
config map to set- Returns:
- this config instance
- Since:
- 5.4
-
setCPMapLimit
public CPSubsystemConfig setCPMapLimit(int cpMapLimit)
Sets the limit of permittedCPMap
instances.- Parameters:
cpMapLimit
- limit ofCPMap
instances- Throws:
java.lang.IllegalArgumentException
- ifcpMapLimit < 0
-
getCPMapLimit
public int getCPMapLimit()
Gets the limit ofCPMap
instances that are permitted to be created.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
-