Class ClusterServiceFactory
- java.lang.Object
-
- io.hekate.cluster.ClusterServiceFactory
-
- All Implemented Interfaces:
ServiceFactory<ClusterService>
public class ClusterServiceFactory extends Object implements ServiceFactory<ClusterService>
Factory forClusterService
.This class represents a configurable factory for
ClusterService
. Instances of this class can beregistered
within theHekateBootstrap
in order to customize options of theClusterService
.For more details about the
ClusterService
and its capabilities please see the documentation ofClusterService
interface.
-
-
Field Summary
Fields Modifier and Type Field Description static long
DEFAULT_GOSSIP_INTERVAL
Default value (=1000L) in milliseconds forsetGossipInterval(long)
.static String
DEFAULT_NAMESPACE
Default value (="default") forsetNamespace(String)
.static int
DEFAULT_SPEED_UP_SIZE
Default value (=100) forsetSpeedUpGossipSize(int)
.
-
Constructor Summary
Constructors Constructor Description ClusterServiceFactory()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ClusterService
createService()
Constructs a new service instance based on the configuration options of this factory.List<ClusterAcceptor>
getAcceptors()
Returns a list of the cluster join acceptors (seesetAcceptors(List)
).List<ClusterEventListener>
getClusterListeners()
Returns a list of cluster event listeners (seesetClusterListeners(List)
).FailureDetector
getFailureDetector()
Returns the failure detector (seesetFailureDetector(FailureDetector)
).long
getGossipInterval()
Returns the time interval in millisecond between gossip rounds (seesetGossipInterval(long)
).String
getNamespace()
Returns the cluster namespace (seesetNamespace(String)
).SeedNodeProvider
getSeedNodeProvider()
Returns seed node provider (seesetSeedNodeProvider(SeedNodeProvider)
).int
getSpeedUpGossipSize()
Returns the maximum amount of nodes in the cluster for the gossip protocol to speeded up by sending messages at a higher rate so that the cluster could converge faster (seesetSpeedUpGossipSize(int)
).long
getSplitBrainCheckInterval()
Returns the time interval in milliseconds for split-brain checking (seesetSplitBrainCheckInterval(long)
).SplitBrainDetector
getSplitBrainDetector()
Returns the cluster split-brain detector (seesetSplitBrainDetector(SplitBrainDetector)
).void
setAcceptors(List<ClusterAcceptor> acceptors)
Sets the list of the cluster join acceptors.void
setClusterListeners(List<ClusterEventListener> clusterListeners)
Sets a list of cluster event listeners to be notified uponClusterEvent
.void
setFailureDetector(FailureDetector failureDetector)
Sets the failure detector that should be used for health checking of remote nodes.void
setGossipInterval(long gossipInterval)
Sets the time interval in milliseconds between gossip rounds.void
setNamespace(String namespace)
Sets the cluster namespace.void
setSeedNodeProvider(SeedNodeProvider seedNodeProvider)
Sets seed node provider that should be used to discover existing cluster nodes when local node starts joining to a cluster.void
setSpeedUpGossipSize(int speedUpGossipSize)
Sets the maximum amount of nodes in the cluster for the gossip protocol to speed up by sending messages at a higher rate so that the cluster could converge faster.void
setSplitBrainCheckInterval(long splitBrainCheckInterval)
Sets the time interval in milliseconds for split-brain checking.void
setSplitBrainDetector(SplitBrainDetector splitBrainDetector)
Sets the cluster split-brain detector.String
toString()
ClusterServiceFactory
withAcceptor(ClusterAcceptor acceptor)
Fluent-style version ofsetAcceptors(List)
.ClusterServiceFactory
withClusterListener(ClusterEventListener listener)
Fluent-style version ofsetClusterListeners(List)
.ClusterServiceFactory
withFailureDetector(FailureDetector failureDetector)
Fluent-style version ofsetSeedNodeProvider(SeedNodeProvider)
.ClusterServiceFactory
withGossipInterval(long gossipInterval)
Fluent-style version ofsetGossipInterval(long)
.ClusterServiceFactory
withNamespace(String namespace)
Fluent-style version ofsetNamespace(String)
.ClusterServiceFactory
withSeedNodeProvider(SeedNodeProvider seedNodeProvider)
Fluent-style version ofsetSeedNodeProvider(SeedNodeProvider)
.ClusterServiceFactory
withSpeedUpGossipSize(int speedUpSize)
Fluent-style version ofsetSpeedUpGossipSize(int)
.ClusterServiceFactory
withSplitBrainCheckInterval(long splitBrainCheckInterval)
Fluent-style version ofsetSplitBrainCheckInterval(long)
.ClusterServiceFactory
withSplitBrainDetector(SplitBrainDetector splitBrainDetector)
Fluent-style version ofsetSplitBrainDetector(SplitBrainDetector)
.
-
-
-
Field Detail
-
DEFAULT_NAMESPACE
public static final String DEFAULT_NAMESPACE
Default value (="default") forsetNamespace(String)
.- See Also:
- Constant Field Values
-
DEFAULT_GOSSIP_INTERVAL
public static final long DEFAULT_GOSSIP_INTERVAL
Default value (=1000L) in milliseconds forsetGossipInterval(long)
.- See Also:
- Constant Field Values
-
DEFAULT_SPEED_UP_SIZE
public static final int DEFAULT_SPEED_UP_SIZE
Default value (=100) forsetSpeedUpGossipSize(int)
.- See Also:
- Constant Field Values
-
-
Method Detail
-
getNamespace
public String getNamespace()
Returns the cluster namespace (seesetNamespace(String)
).- Returns:
- Cluster namespace.
-
setNamespace
public void setNamespace(String namespace)
Sets the cluster namespace. Can contain only alpha-numeric characters and non-repeatable dots/hyphens.Only those nodes that are configured with the same cluster namespace can form a cluster. Nodes that have different namespaces will form completely independent clusters.
Default value of this property is "default".
Hint: For breaking nodes into logical sub-groups within the same cluster consider using
node roles
withnodes filtering
.- Parameters:
namespace
- Cluster namespace (can contain only alpha-numeric characters and non-repeatable dots/hyphens).
-
withNamespace
public ClusterServiceFactory withNamespace(String namespace)
Fluent-style version ofsetNamespace(String)
.- Parameters:
namespace
- Cluster namespace.- Returns:
- This instance.
-
getSeedNodeProvider
public SeedNodeProvider getSeedNodeProvider()
Returns seed node provider (seesetSeedNodeProvider(SeedNodeProvider)
).- Returns:
- Seed node provider.
-
setSeedNodeProvider
public void setSeedNodeProvider(SeedNodeProvider seedNodeProvider)
Sets seed node provider that should be used to discover existing cluster nodes when local node starts joining to a cluster.By default this property is initialized with
MulticastSeedNodeProvider
instance. Note that this requires multicasting to be enabled on the target platform.- Parameters:
seedNodeProvider
- Seed node provider.- See Also:
SeedNodeProvider
-
withSeedNodeProvider
public ClusterServiceFactory withSeedNodeProvider(SeedNodeProvider seedNodeProvider)
Fluent-style version ofsetSeedNodeProvider(SeedNodeProvider)
.- Parameters:
seedNodeProvider
- Seed node provider.- Returns:
- This instance.
-
getFailureDetector
public FailureDetector getFailureDetector()
Returns the failure detector (seesetFailureDetector(FailureDetector)
).- Returns:
- Failure detector.
-
setFailureDetector
public void setFailureDetector(FailureDetector failureDetector)
Sets the failure detector that should be used for health checking of remote nodes.By default this property is initialized with a
DefaultFailureDetector
instance.- Parameters:
failureDetector
- Failure detector.- See Also:
FailureDetector
-
withFailureDetector
public ClusterServiceFactory withFailureDetector(FailureDetector failureDetector)
Fluent-style version ofsetSeedNodeProvider(SeedNodeProvider)
.- Parameters:
failureDetector
- Failure detector.- Returns:
- This instance.
-
getSplitBrainDetector
public SplitBrainDetector getSplitBrainDetector()
Returns the cluster split-brain detector (seesetSplitBrainDetector(SplitBrainDetector)
).- Returns:
- Cluster split-brain detector.
-
setSplitBrainDetector
public void setSplitBrainDetector(SplitBrainDetector splitBrainDetector)
Sets the cluster split-brain detector.Split-brain can happen if other cluster members decided that this node is not reachable (due to some networking problems or long GC pauses). In such case they will remove this node from their topology while this node will think that it is still a member of the cluster. This component is responsible for checking if local node is reachable by other cluster nodes.
If this component detects that local node is not reachable then
HekateFatalErrorPolicy
will be applied to the local node withClusterSplitBrainException
as a cause.- Parameters:
splitBrainDetector
- Cluster split-brain detector.
-
withSplitBrainDetector
public ClusterServiceFactory withSplitBrainDetector(SplitBrainDetector splitBrainDetector)
Fluent-style version ofsetSplitBrainDetector(SplitBrainDetector)
.- Parameters:
splitBrainDetector
- Cluster split-brain detector.- Returns:
- This instance.
-
getSplitBrainCheckInterval
public long getSplitBrainCheckInterval()
Returns the time interval in milliseconds for split-brain checking (seesetSplitBrainCheckInterval(long)
).- Returns:
- Time interval in milliseconds.
-
setSplitBrainCheckInterval
public void setSplitBrainCheckInterval(long splitBrainCheckInterval)
Sets the time interval in milliseconds for split-brain checking.If the specified value is greater than zero then once per such interval the
SplitBrainDetector
component will be called to check the node's health.Default value of this parameter is
0
(i.e. periodic checks are disabled by default).- Parameters:
splitBrainCheckInterval
- Time interval in milliseconds.
-
withSplitBrainCheckInterval
public ClusterServiceFactory withSplitBrainCheckInterval(long splitBrainCheckInterval)
Fluent-style version ofsetSplitBrainCheckInterval(long)
.- Parameters:
splitBrainCheckInterval
- Time interval in milliseconds.- Returns:
- This instance.
-
getClusterListeners
public List<ClusterEventListener> getClusterListeners()
Returns a list of cluster event listeners (seesetClusterListeners(List)
).- Returns:
- List of cluster event listeners.
-
setClusterListeners
public void setClusterListeners(List<ClusterEventListener> clusterListeners)
Sets a list of cluster event listeners to be notified uponClusterEvent
.- Parameters:
clusterListeners
- Cluster event listeners.
-
withClusterListener
public ClusterServiceFactory withClusterListener(ClusterEventListener listener)
Fluent-style version ofsetClusterListeners(List)
.- Parameters:
listener
- Cluster event listener.- Returns:
- This instance.
-
getAcceptors
public List<ClusterAcceptor> getAcceptors()
Returns a list of the cluster join acceptors (seesetAcceptors(List)
).- Returns:
- List of cluster join acceptors.
-
setAcceptors
public void setAcceptors(List<ClusterAcceptor> acceptors)
Sets the list of the cluster join acceptors.Cluster join acceptors are responsible for implementing a custom logic of accepting/rejecting new nodes based on some application-specific criteria (f.e. configuration compatibility, authorization, etc). For more details please see the documentation of the
ClusterAcceptor
interface.- Parameters:
acceptors
- List of cluster join acceptors.- See Also:
ClusterAcceptor
-
withAcceptor
public ClusterServiceFactory withAcceptor(ClusterAcceptor acceptor)
Fluent-style version ofsetAcceptors(List)
.- Parameters:
acceptor
- Cluster join acceptor.- Returns:
- This instance.
-
getGossipInterval
public long getGossipInterval()
Returns the time interval in millisecond between gossip rounds (seesetGossipInterval(long)
).- Returns:
- The time interval in millisecond between gossip rounds.
-
setGossipInterval
public void setGossipInterval(long gossipInterval)
Sets the time interval in milliseconds between gossip rounds.During each round the local node will exchange its topology view with a set of randomly selected remote nodes in order to make sure that topology view is consistent across the whole cluster.
Value of this parameter must be greater than zero.
Default value of this parameter is 1000L.
- Parameters:
gossipInterval
- The time interval in milliseconds between gossip rounds.
-
withGossipInterval
public ClusterServiceFactory withGossipInterval(long gossipInterval)
Fluent-style version ofsetGossipInterval(long)
.- Parameters:
gossipInterval
- The time interval in milliseconds between gossip rounds.- Returns:
- This instance.
-
getSpeedUpGossipSize
public int getSpeedUpGossipSize()
Returns the maximum amount of nodes in the cluster for the gossip protocol to speeded up by sending messages at a higher rate so that the cluster could converge faster (seesetSpeedUpGossipSize(int)
).- Returns:
- The maximum amount of nodes in the cluster when gossip protocol can be speeded up.
-
setSpeedUpGossipSize
public void setSpeedUpGossipSize(int speedUpGossipSize)
Sets the maximum amount of nodes in the cluster for the gossip protocol to speed up by sending messages at a higher rate so that the cluster could converge faster.If this parameter is set to a positive value and the current cluster size is less than the specified value then local node will send gossip messages at higher rate in order to speed-up cluster convergence. However this can highly increase resources utilization and should be used in a cluster of relatively small size.
Default value of this parameter is 100.
- Parameters:
speedUpGossipSize
- The maximum amount of nodes in the cluster when gossip protocol can be speeded up.
-
withSpeedUpGossipSize
public ClusterServiceFactory withSpeedUpGossipSize(int speedUpSize)
Fluent-style version ofsetSpeedUpGossipSize(int)
.- Parameters:
speedUpSize
- The maximum amount of nodes in the cluster when gossip protocol can be speeded up.- Returns:
- This instance.
-
createService
public ClusterService createService()
Description copied from interface:ServiceFactory
Constructs a new service instance based on the configuration options of this factory.- Specified by:
createService
in interfaceServiceFactory<ClusterService>
- Returns:
- New service instance.
-
-