Class AbstractDiscoveryStrategy
- All Implemented Interfaces:
DiscoveryStrategy
- Direct Known Subclasses:
MulticastDiscoveryStrategy
DiscoveryStrategy
implementations,
offering convenient access to configuration properties (which may be overridden
on the system's environment or JVM properties), as well as a ILogger
instance.- Since:
- 3.6
-
Constructor Summary
ConstructorDescriptionAbstractDiscoveryStrategy
(ILogger logger, Map<String, Comparable> properties) -
Method Summary
Modifier and TypeMethodDescriptionvoid
destroy()
Thestop
method is used to stop internal services, sockets or to destroy any kind of internal state.Returns a map with discovered metadata provided by the runtime environment.protected ILogger
Returns aILogger
instance bound to the current class.protected <T extends Comparable>
TgetOrDefault
(PropertyDefinition property, T defaultValue) Returns the value of the requestedPropertyDefinition
if available in the declarative or programmatic configuration (XML or Config API), otherwise it will return the givendefaultValue
.protected <T extends Comparable>
TgetOrDefault
(String prefix, PropertyDefinition property, T defaultValue) Returns the value of the requestedPropertyDefinition
if available in the declarative or programmatic configuration (XML or Config API), can be found in the system's environment, or passed as a JVM property.protected <T extends Comparable>
TgetOrNull
(PropertyDefinition property) Returns the value of the requestedPropertyDefinition
if available in the declarative or programmatic configuration (XML or Config API), otherwise it will returnnull
.protected <T extends Comparable>
TgetOrNull
(String prefix, PropertyDefinition property) Returns the value of the requestedPropertyDefinition
if available in the declarative or programmatic configuration (XML or Config API), can be found in the system's environment, or passed as a JVM property.getPartitionGroupStrategy
(Collection<? extends Member> allMembers) Returns a custom implementation of aPartitionGroupStrategy
to override default behavior of zone aware backup strategies or to provide a specific behavior in case the discovery environment does not provide information about the infrastructure to be used for automatic configuration.protected Map<String,
Comparable> Returns an immutable copy of the configuration properties.void
start()
Thestart
method is used to initialize internal state and perform any kind of startup procedure like multicast socket creation.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.hazelcast.spi.discovery.DiscoveryStrategy
discoverNodes, getUnhealthyEndpoints, markEndpointAsUnhealthy
-
Constructor Details
-
AbstractDiscoveryStrategy
-
-
Method Details
-
destroy
public void destroy()Description copied from interface:DiscoveryStrategy
Thestop
method is used to stop internal services, sockets or to destroy any kind of internal state.- Specified by:
destroy
in interfaceDiscoveryStrategy
-
start
public void start()Description copied from interface:DiscoveryStrategy
Thestart
method is used to initialize internal state and perform any kind of startup procedure like multicast socket creation. The behavior of this method might change based on theDiscoveryNode
instance passed to theDiscoveryStrategyFactory
.- Specified by:
start
in interfaceDiscoveryStrategy
-
getPartitionGroupStrategy
- Specified by:
getPartitionGroupStrategy
in interfaceDiscoveryStrategy
- Returns:
- a custom implementation of a
PartitionGroupStrategy
otherwisenull
in case of the default implementation is to be used
-
getPartitionGroupStrategy
Description copied from interface:DiscoveryStrategy
Returns a custom implementation of aPartitionGroupStrategy
to override default behavior of zone aware backup strategies or to provide a specific behavior in case the discovery environment does not provide information about the infrastructure to be used for automatic configuration.- Specified by:
getPartitionGroupStrategy
in interfaceDiscoveryStrategy
- Parameters:
allMembers
- Current state of Cluster data members, excluding lite members- Returns:
- a custom implementation of a
PartitionGroupStrategy
otherwisenull
in case of the default implementation is to be used
-
discoverLocalMetadata
Description copied from interface:DiscoveryStrategy
Returns a map with discovered metadata provided by the runtime environment. Those information may include, but are not limited, to location information like datacenter, node name or additional tags to be used for custom purpose.Information discovered from this method are shaded into the
Member
s attributes. Existing attributes will not be overridden, that way local attribute configuration overrides provided metadata.The default implementation provides an empty map with no further metadata configured. Returning
null
is not permitted and will most probably result in anNullPointerException
inside the cluster system.- Specified by:
discoverLocalMetadata
in interfaceDiscoveryStrategy
- Returns:
- a map of discovered metadata as provided by the runtime environment
-
getProperties
Returns an immutable copy of the configuration properties.- Returns:
- the configuration properties
-
getLogger
Returns aILogger
instance bound to the current class.- Returns:
- a ILogger instance
-
getOrNull
Returns the value of the requestedPropertyDefinition
if available in the declarative or programmatic configuration (XML or Config API), otherwise it will returnnull
.This method overload won't do environment or JVM property lookup. A call to this overload is equivalent to
getOrNull(String, PropertyDefinition)
withnull
passed as the first parameter.- Type Parameters:
T
- the type of the property, must be compatible with the conversion result ofPropertyDefinition.typeConverter()
- Parameters:
property
- the PropertyDefinition to lookup- Returns:
- the value of the given property if available in the configuration, otherwise null
-
getOrNull
Returns the value of the requestedPropertyDefinition
if available in the declarative or programmatic configuration (XML or Config API), can be found in the system's environment, or passed as a JVM property. Otherwise, it will returnnull
.This overload will resolve the requested property in the following order, whereas the higher priority is from top to bottom:
System.getProperty(String)
: JVM propertiesSystem.getenv(String)
: System environment- Configuration properties of this
DiscoveryStrategy
prefix
, therefore a prefix of com.hazelcast.discovery and a property key of hostname will result in a property lookup of com.hazelcast.discovery.hostname in the system environment and JVM properties.- Type Parameters:
T
- the type of the property, must be compatible with the conversion result ofPropertyDefinition.typeConverter()
- Parameters:
prefix
- the property key prefix for environment and JVM properties lookupproperty
- the PropertyDefinition to lookup- Returns:
- the value of the given property if available in the configuration, system environment or JVM properties, otherwise null
-
getOrDefault
Returns the value of the requestedPropertyDefinition
if available in the declarative or programmatic configuration (XML or Config API), otherwise it will return the givendefaultValue
.This method overload won't do environment or JVM property lookup. A call to this overload is equivalent to
getOrDefault(String, PropertyDefinition, Comparable)
withnull
passed as the first parameter.- Type Parameters:
T
- the type of the property, must be compatible with the conversion result ofPropertyDefinition.typeConverter()
- Parameters:
property
- the PropertyDefinition to lookup- Returns:
- the value of the given property if available in the configuration, otherwise the given default value
-
getOrDefault
protected <T extends Comparable> T getOrDefault(String prefix, PropertyDefinition property, T defaultValue) Returns the value of the requestedPropertyDefinition
if available in the declarative or programmatic configuration (XML or Config API), can be found in the system's environment, or passed as a JVM property. otherwise it will return the givendefaultValue
.This overload will resolve the requested property in the following order, whereas the higher priority is from top to bottom:
System.getProperty(String)
: JVM propertiesSystem.getenv(String)
: System environment- Configuration properties of this
DiscoveryStrategy
prefix
, therefore a prefix of com.hazelcast.discovery and a property key of hostname will result in a property lookup of com.hazelcast.discovery.hostname in the system environment and JVM properties.- Type Parameters:
T
- the type of the property, must be compatible with the conversion result ofPropertyDefinition.typeConverter()
- Parameters:
prefix
- the property key prefix for environment and JVM properties lookupproperty
- the PropertyDefinition to lookup- Returns:
- the value of the given property if available in the configuration, system environment or JVM properties, otherwise the given default value
-