Class HekateBootstrap
- java.lang.Object
-
- io.hekate.core.HekateBootstrap
-
- Direct Known Subclasses:
HekateSpringBootstrap
public class HekateBootstrap extends Object
Main configuration and factory forHekate
instances.This class provides bean-style properties with getters/setters (to be used in the Spring Framework XML files) as well as fluent-style API for programmatic configuration from within the Java code.
Configuration options are:
Node name
Node properties
Node roles
Data serialization codec
Plugins
that should run within the node-
Services
to be provided by the node:
Once configured, the
join()
method must be called in order to construct a newHekate
instance and join the cluster.For more details about the lifecycle and available services please see the documentation of
Hekate
interface.
-
-
Constructor Summary
Constructors Constructor Description HekateBootstrap()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Hekate
create()
Creates a newHekate
instance.CodecFactory<Object>
getDefaultCodec()
Returns the default codec factory (seesetDefaultCodec(CodecFactory)
).HekateFatalErrorPolicy
getFatalErrorPolicy()
Returns fatal error handling policy (seesetFatalErrorPolicy(HekateFatalErrorPolicy)
).List<Hekate.LifecycleListener>
getLifecycleListeners()
Returns the list of instance lifecycle listeners (seesetLifecycleListeners(List)
).io.micrometer.core.instrument.MeterRegistry
getMetrics()
Returns the metrics registry.String
getNodeName()
Returns the node name (seesetNodeName(String)
).List<Plugin>
getPlugins()
Returns the list of plugins that should run within the local node (seesetPlugins(List)
).Map<String,String>
getProperties()
Returns a map of local node properties (seesetProperties(Map)
).List<PropertyProvider>
getPropertyProviders()
Returns a list of node property providers (seesetPropertyProviders(List)
).List<String>
getRoles()
Returns a list of the local node's roles (seesetRoles(List)
).List<ServiceFactory<? extends Service>>
getServices()
Returns services of the local node (seesetServices(List)
).Hekate
initialize()
Constructs a newHekate
instance and synchronouslyinitializes
it without joining the cluster.boolean
isConfigReport()
true
if the configuration report should be logged during node initialization.Hekate
join()
JoinFuture
joinAsync()
<T extends ServiceFactory<?>>
Optional<T>service(Class<T> factoryType)
Finds a service factory of the specified type (seesetServices(List)
).void
setConfigReport(boolean configReport)
true
if the configuration report should be logged during node initialization.void
setDefaultCodec(CodecFactory<Object> defaultCodec)
Sets the codec factory that should be used by theCodecService
.void
setFatalErrorPolicy(HekateFatalErrorPolicy fatalErrorPolicy)
Sets the fatal error handling policy.void
setLifecycleListeners(List<Hekate.LifecycleListener> lifecycleListeners)
Sets the list ofHekate
lifecycle listeners.void
setMetrics(io.micrometer.core.instrument.MeterRegistry metrics)
Sets the metrics registry.void
setNodeName(String nodeName)
Sets the node name.void
setPlugins(List<Plugin> plugins)
Sets the list of plugins that should run within the local node.void
setProperties(Map<String,String> properties)
Sets node's properties.void
setPropertyProviders(List<PropertyProvider> propertyProviders)
Sets the list of node property providers.void
setRoles(List<String> roles)
Sets node's roles.void
setServices(List<ServiceFactory<? extends Service>> services)
Sets the list of services that should be provided by the local node.String
toString()
HekateBootstrap
withCluster(Consumer<ClusterServiceFactory> configurer)
ConfiguresClusterService
.HekateBootstrap
withConfigReport(boolean configReport)
Fluent-style version ofsetConfigReport(boolean)
.HekateBootstrap
withCoordination(Consumer<CoordinationServiceFactory> configurer)
ConfiguresCoordinationService
.HekateBootstrap
withDefaultCodec(CodecFactory<Object> defaultCodec)
Fluent-style version ofsetDefaultCodec(CodecFactory)
.HekateBootstrap
withElection(Consumer<ElectionServiceFactory> configurer)
ConfiguresElectionService
.HekateBootstrap
withFatalErrorPolicy(HekateFatalErrorPolicy fatalErrorPolicy)
Fluent-style version ofsetFatalErrorPolicy(HekateFatalErrorPolicy)
.HekateBootstrap
withJmx(Consumer<JmxServiceFactory> configurer)
ConfiguresJmxService
.HekateBootstrap
withLifecycleListener(Hekate.LifecycleListener listener)
Fluent-style version ofsetLifecycleListeners(List)
.HekateBootstrap
withLocks(Consumer<LockServiceFactory> configurer)
ConfiguresLockService
.HekateBootstrap
withMessaging(Consumer<MessagingServiceFactory> configurer)
ConfiguresMessagingService
.HekateBootstrap
withMetrics(io.micrometer.core.instrument.MeterRegistry metrics)
Fluent-style version ofsetMetrics(MeterRegistry)
.HekateBootstrap
withNetwork(Consumer<NetworkServiceFactory> configurer)
ConfiguresNetworkService
.HekateBootstrap
withNodeName(String nodeName)
Fluent-style version ofsetNodeName(String)
.HekateBootstrap
withPlugin(Plugin plugin)
Adds the specified plugin to alist of plugins
.HekateBootstrap
withProperty(String key, String value)
Puts the specified property value into the node'sproperties map
.HekateBootstrap
withPropertyProvider(PropertyProvider propertyProvider)
Fluent-style version ofsetPropertyProviders(List)
.HekateBootstrap
withRole(String role)
Adds the specifiedrole
to theroles set
.HekateBootstrap
withRpc(Consumer<RpcServiceFactory> configurer)
ConfiguresRpcService
.HekateBootstrap
withService(ServiceFactory<? extends Service> service)
Adds the specified factory to the list ofservice factories
.<T extends ServiceFactory<?>>
TwithService(Class<T> factoryType)
Returns an existing service factory of the specified type or creates and registers a new one.<T extends ServiceFactory<?>>
HekateBootstrapwithService(Class<T> factoryType, Consumer<T> configurer)
Applies the specifiedconfigurer
to a service factory of the specified type.
-
-
-
Method Detail
-
joinAsync
public JoinFuture joinAsync() throws HekateException
- Returns:
- Future result of this operation.
- Throws:
HekateException
- If configuration is invalid.
-
join
public Hekate join() throws HekateException
- Returns:
- new
Hekate
instance. - Throws:
HekateException
- If failure occurred while initializing or joining to cluster.
-
initialize
public Hekate initialize() throws HekateException
Constructs a newHekate
instance and synchronouslyinitializes
it without joining the cluster.Joining to the cluster can be later performed via
Hekate.join()
method.- Returns:
- new
Hekate
instance. - Throws:
HekateException
- If failure occurred while initializing or joining to cluster.
-
getNodeName
public String getNodeName()
Returns the node name (seesetNodeName(String)
).- Returns:
- Node name.
-
setNodeName
public void setNodeName(String nodeName)
Sets the node name. Can contain only alpha-numeric characters and non-repeatable dots/hyphens.Node name is optional and its default value is
null
.- Parameters:
nodeName
- Node name (can contain only alpha-numeric characters and non-repeatable dots/hyphens).- See Also:
ClusterNode.name()
-
withNodeName
public HekateBootstrap withNodeName(String nodeName)
Fluent-style version ofsetNodeName(String)
.- Parameters:
nodeName
- Node name.- Returns:
- This instance.
-
getRoles
public List<String> getRoles()
Returns a list of the local node's roles (seesetRoles(List)
).- Returns:
- List of local node roles.
-
setRoles
public void setRoles(List<String> roles)
Sets node's roles.Roles are string identifiers that can be used for logical grouping of cluster nodes. Roles of each node are visible to all other cluster members via
ClusterNode.roles()
and can be used by applications to operate on a sub-set of cluster nodes with specific role(s) (seeClusterFilterSupport.forRole(String)
).- Parameters:
roles
- Set of roles.- See Also:
ClusterNode.roles()
,ClusterTopology.filter(ClusterNodeFilter)
-
withRole
public HekateBootstrap withRole(String role)
Adds the specifiedrole
to theroles set
.- Parameters:
role
- Role.- Returns:
- This instance.
-
getProperties
public Map<String,String> getProperties()
Returns a map of local node properties (seesetProperties(Map)
).- Returns:
- Map of local node properties.
-
setProperties
public void setProperties(Map<String,String> properties)
Sets node's properties.Properties of each node are visible to all other cluster members via
ClusterNode.properties()
.- Parameters:
properties
- Map of local node properties.- See Also:
ClusterNode.properties()
,setPropertyProviders(List)
-
withProperty
public HekateBootstrap withProperty(String key, String value)
Puts the specified property value into the node'sproperties map
.- Parameters:
key
- Property key.value
- Property value.- Returns:
- This instance.
-
getPropertyProviders
public List<PropertyProvider> getPropertyProviders()
Returns a list of node property providers (seesetPropertyProviders(List)
).- Returns:
- Node property providers.
-
setPropertyProviders
public void setPropertyProviders(List<PropertyProvider> propertyProviders)
Sets the list of node property providers.Such providers can be used to provide properties that were dynamically obtained from some third party sources and should become part of
node properties
.- Parameters:
propertyProviders
- Node property providers.- See Also:
setProperties(Map)
-
withPropertyProvider
public HekateBootstrap withPropertyProvider(PropertyProvider propertyProvider)
Fluent-style version ofsetPropertyProviders(List)
.- Parameters:
propertyProvider
- Property provider.- Returns:
- This instance.
-
getServices
public List<ServiceFactory<? extends Service>> getServices()
Returns services of the local node (seesetServices(List)
).- Returns:
- List of service factories.
-
setServices
public void setServices(List<ServiceFactory<? extends Service>> services)
Sets the list of services that should be provided by the local node.- Parameters:
services
- Service factories.- See Also:
Service
,ServiceFactory
-
withService
public HekateBootstrap withService(ServiceFactory<? extends Service> service)
Adds the specified factory to the list ofservice factories
.- Parameters:
service
- Service factory.- Returns:
- This instance.
-
withService
public <T extends ServiceFactory<?>> HekateBootstrap withService(Class<T> factoryType, Consumer<T> configurer)
Applies the specifiedconfigurer
to a service factory of the specified type. If factory is not registered yet then it will be automatically registered viawithService(Class)
.- Type Parameters:
T
- Service factory type.- Parameters:
factoryType
- Service factory type.configurer
- Service factory configurer.- Returns:
- This instance.
-
withService
public <T extends ServiceFactory<?>> T withService(Class<T> factoryType)
Returns an existing service factory of the specified type or creates and registers a new one.Note that the specified type must have a public no-arg constructor.
- Type Parameters:
T
- Service factory type.- Parameters:
factoryType
- Service factory type.- Returns:
- Service factory instance.
-
withJmx
public HekateBootstrap withJmx(Consumer<JmxServiceFactory> configurer)
ConfiguresJmxService
.- Parameters:
configurer
- Configuration function.- Returns:
- This instance.
- See Also:
JmxServiceFactory
-
withNetwork
public HekateBootstrap withNetwork(Consumer<NetworkServiceFactory> configurer)
ConfiguresNetworkService
.- Parameters:
configurer
- Configuration function.- Returns:
- This instance.
- See Also:
NetworkServiceFactory
-
withCluster
public HekateBootstrap withCluster(Consumer<ClusterServiceFactory> configurer)
ConfiguresClusterService
.- Parameters:
configurer
- Configuration function.- Returns:
- This instance.
- See Also:
ClusterServiceFactory
-
withMessaging
public HekateBootstrap withMessaging(Consumer<MessagingServiceFactory> configurer)
ConfiguresMessagingService
.- Parameters:
configurer
- Configuration function.- Returns:
- This instance.
- See Also:
MessagingServiceFactory
-
withRpc
public HekateBootstrap withRpc(Consumer<RpcServiceFactory> configurer)
ConfiguresRpcService
.- Parameters:
configurer
- Configuration function.- Returns:
- This instance.
- See Also:
RpcServiceFactory
-
withLocks
public HekateBootstrap withLocks(Consumer<LockServiceFactory> configurer)
ConfiguresLockService
.- Parameters:
configurer
- Configuration function.- Returns:
- This instance.
- See Also:
LockServiceFactory
-
withElection
public HekateBootstrap withElection(Consumer<ElectionServiceFactory> configurer)
ConfiguresElectionService
.- Parameters:
configurer
- Configuration function.- Returns:
- This instance.
- See Also:
ElectionServiceFactory
-
withCoordination
public HekateBootstrap withCoordination(Consumer<CoordinationServiceFactory> configurer)
ConfiguresCoordinationService
.- Parameters:
configurer
- Configuration function.- Returns:
- This instance.
- See Also:
CoordinationServiceFactory
-
service
public <T extends ServiceFactory<?>> Optional<T> service(Class<T> factoryType)
Finds a service factory of the specified type (seesetServices(List)
).- Type Parameters:
T
- Service factory type.- Parameters:
factoryType
- Service factory type.- Returns:
- Optional service factory if it was registered within this instance.
-
getPlugins
public List<Plugin> getPlugins()
Returns the list of plugins that should run within the local node (seesetPlugins(List)
).- Returns:
- List of plugins.
-
setPlugins
public void setPlugins(List<Plugin> plugins)
Sets the list of plugins that should run within the local node.Plugins are custom extensions that run within the context of a local node and whose lifecycle is controlled by the lifecycle of that node. For more info please see description of the
Plugin
interface.- Parameters:
plugins
- List of plugins.- See Also:
Plugin
-
withPlugin
public HekateBootstrap withPlugin(Plugin plugin)
Adds the specified plugin to alist of plugins
.- Parameters:
plugin
- Plugin.- Returns:
- This instance.
-
getDefaultCodec
public CodecFactory<Object> getDefaultCodec()
Returns the default codec factory (seesetDefaultCodec(CodecFactory)
).- Returns:
- Default codec factory.
-
setDefaultCodec
public void setDefaultCodec(CodecFactory<Object> defaultCodec)
Sets the codec factory that should be used by theCodecService
.This parameter is mandatory and can't be
null
. Also, the specified codec factory must be stateless (seeCodec.isStateful()
).If not configured then
AutoSelectCodecFactory
will be used by default.- Parameters:
defaultCodec
- Codec factory (must be stateless, seeCodec.isStateful()
) .- See Also:
CodecService
-
withDefaultCodec
public HekateBootstrap withDefaultCodec(CodecFactory<Object> defaultCodec)
Fluent-style version ofsetDefaultCodec(CodecFactory)
.- Parameters:
defaultCodec
- Default codec factory.- Returns:
- This instance.
-
getMetrics
public io.micrometer.core.instrument.MeterRegistry getMetrics()
Returns the metrics registry.- Returns:
- Metrics registry.
-
setMetrics
public void setMetrics(io.micrometer.core.instrument.MeterRegistry metrics)
Sets the metrics registry.If not specified then
SimpleMeterRegistry
will be used by default.- Parameters:
metrics
- Metrics registry.
-
withMetrics
public HekateBootstrap withMetrics(io.micrometer.core.instrument.MeterRegistry metrics)
Fluent-style version ofsetMetrics(MeterRegistry)
.- Parameters:
metrics
- Metrics registry.- Returns:
- This instance.
-
getLifecycleListeners
public List<Hekate.LifecycleListener> getLifecycleListeners()
Returns the list of instance lifecycle listeners (seesetLifecycleListeners(List)
).- Returns:
- Lifecycle listeners.
-
setLifecycleListeners
public void setLifecycleListeners(List<Hekate.LifecycleListener> lifecycleListeners)
Sets the list ofHekate
lifecycle listeners.- Parameters:
lifecycleListeners
- Lifecycle listeners.- See Also:
Hekate.addListener(Hekate.LifecycleListener)
-
withLifecycleListener
public HekateBootstrap withLifecycleListener(Hekate.LifecycleListener listener)
Fluent-style version ofsetLifecycleListeners(List)
.- Parameters:
listener
- Lifecycle listener.- Returns:
- This instance.
-
getFatalErrorPolicy
public HekateFatalErrorPolicy getFatalErrorPolicy()
Returns fatal error handling policy (seesetFatalErrorPolicy(HekateFatalErrorPolicy)
).- Returns:
- Fatal error handling policy.
-
setFatalErrorPolicy
public void setFatalErrorPolicy(HekateFatalErrorPolicy fatalErrorPolicy)
Sets the fatal error handling policy.This policy is applied if
Hekate
node faces an unrecoverable internal error.If not specified then
HekateFatalErrorPolicy.terminate()
policy will be used by default.- Parameters:
fatalErrorPolicy
- Fatal error handling policy.
-
withFatalErrorPolicy
public HekateBootstrap withFatalErrorPolicy(HekateFatalErrorPolicy fatalErrorPolicy)
Fluent-style version ofsetFatalErrorPolicy(HekateFatalErrorPolicy)
.- Parameters:
fatalErrorPolicy
- Fatal error handling policy.- Returns:
- Fatal error handling policy.
-
isConfigReport
public boolean isConfigReport()
true
if the configuration report should be logged during node initialization.- Returns:
true
if the configuration report should be logged during node initialization.
-
setConfigReport
public void setConfigReport(boolean configReport)
true
if the configuration report should be logged during node initialization.Default value of this property is
false
.- Parameters:
configReport
-true
if the configuration report should be logged during node initialization.
-
withConfigReport
public HekateBootstrap withConfigReport(boolean configReport)
Fluent-style version ofsetConfigReport(boolean)
.- Parameters:
configReport
-true
if the configuration report should be logged during node initialization.- Returns:
- This instance.
-
-