Class AbstractDiscoveryStrategy
- java.lang.Object
-
- com.hazelcast.spi.discovery.AbstractDiscoveryStrategy
-
- All Implemented Interfaces:
DiscoveryStrategy
- Direct Known Subclasses:
AwsDiscoveryStrategy
,AzureDiscoveryStrategy
,GcpDiscoveryStrategy
,MulticastDiscoveryStrategy
public abstract class AbstractDiscoveryStrategy extends java.lang.Object implements DiscoveryStrategy
A common abstract superclass forDiscoveryStrategy
implementations, offering convenient access to configuration properties (which may be overridden on the system's environment or JVM properties), as well as aILogger
instance.- Since:
- 3.6
-
-
Constructor Summary
Constructors Constructor Description AbstractDiscoveryStrategy(ILogger logger, java.util.Map<java.lang.String,java.lang.Comparable> properties)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
destroy()
Thestop
method is used to stop internal services, sockets or to destroy any kind of internal state.java.util.Map<java.lang.String,java.lang.String>
discoverLocalMetadata()
Returns a map with discovered metadata provided by the runtime environment.protected ILogger
getLogger()
Returns aILogger
instance bound to the current class.protected <T extends java.lang.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 java.lang.Comparable>
TgetOrDefault(java.lang.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 java.lang.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 java.lang.Comparable>
TgetOrNull(java.lang.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.PartitionGroupStrategy
getPartitionGroupStrategy()
PartitionGroupStrategy
getPartitionGroupStrategy(java.util.Collection<? extends Member> allMembers)
Returns a custom implementation of aPartitionGroupStrategy
to override default behavior of zone aware backup strategiesPartitionGroupMetaData
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 java.util.Map<java.lang.String,java.lang.Comparable>
getProperties()
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 Detail
-
AbstractDiscoveryStrategy
public AbstractDiscoveryStrategy(ILogger logger, java.util.Map<java.lang.String,java.lang.Comparable> properties)
-
-
Method Detail
-
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
public PartitionGroupStrategy 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
public PartitionGroupStrategy getPartitionGroupStrategy(java.util.Collection<? extends Member> allMembers)
Description copied from interface:DiscoveryStrategy
Returns a custom implementation of aPartitionGroupStrategy
to override default behavior of zone aware backup strategiesPartitionGroupMetaData
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
public java.util.Map<java.lang.String,java.lang.String> 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
protected java.util.Map<java.lang.String,java.lang.Comparable> getProperties()
Returns an immutable copy of the configuration properties.- Returns:
- the configuration properties
-
getLogger
protected ILogger getLogger()
Returns aILogger
instance bound to the current class.- Returns:
- a ILogger instance
-
getOrNull
protected <T extends java.lang.Comparable> T getOrNull(PropertyDefinition property)
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
protected <T extends java.lang.Comparable> T getOrNull(java.lang.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. 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
protected <T extends java.lang.Comparable> T getOrDefault(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
.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 java.lang.Comparable> T getOrDefault(java.lang.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
-
-