Class AbstractDiscoveryStrategy

java.lang.Object
com.hazelcast.spi.discovery.AbstractDiscoveryStrategy
All Implemented Interfaces:
DiscoveryStrategy
Direct Known Subclasses:
MulticastDiscoveryStrategy

public abstract class AbstractDiscoveryStrategy extends Object implements DiscoveryStrategy
A common abstract superclass for 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 Details

  • Method Details

    • destroy

      public void destroy()
      Description copied from interface: DiscoveryStrategy
      The stop method is used to stop internal services, sockets or to destroy any kind of internal state.
      Specified by:
      destroy in interface DiscoveryStrategy
    • start

      public void start()
      Description copied from interface: DiscoveryStrategy
      The start 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 the DiscoveryNode instance passed to the DiscoveryStrategyFactory.
      Specified by:
      start in interface DiscoveryStrategy
    • getPartitionGroupStrategy

      public PartitionGroupStrategy getPartitionGroupStrategy()
      Specified by:
      getPartitionGroupStrategy in interface DiscoveryStrategy
      Returns:
      a custom implementation of a PartitionGroupStrategy otherwise null in case of the default implementation is to be used
    • getPartitionGroupStrategy

      public PartitionGroupStrategy getPartitionGroupStrategy(Collection<? extends Member> allMembers)
      Description copied from interface: DiscoveryStrategy
      Returns a custom implementation of a PartitionGroupStrategy 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 interface DiscoveryStrategy
      Parameters:
      allMembers - Current state of Cluster data members, excluding lite members
      Returns:
      a custom implementation of a PartitionGroupStrategy otherwise null in case of the default implementation is to be used
    • discoverLocalMetadata

      public Map<String,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 Members 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 an NullPointerException inside the cluster system.

      Specified by:
      discoverLocalMetadata in interface DiscoveryStrategy
      Returns:
      a map of discovered metadata as provided by the runtime environment
    • getProperties

      protected Map<String,Comparable> getProperties()
      Returns an immutable copy of the configuration properties.
      Returns:
      the configuration properties
    • getLogger

      protected ILogger getLogger()
      Returns a ILogger instance bound to the current class.
      Returns:
      a ILogger instance
    • getOrNull

      protected <T extends Comparable> T getOrNull(PropertyDefinition property)
      Returns the value of the requested PropertyDefinition if available in the declarative or programmatic configuration (XML or Config API), otherwise it will return null.

      This method overload won't do environment or JVM property lookup. A call to this overload is equivalent to getOrNull(String, PropertyDefinition) with null passed as the first parameter.

      Type Parameters:
      T - the type of the property, must be compatible with the conversion result of PropertyDefinition.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 Comparable> T getOrNull(String prefix, PropertyDefinition property)
      Returns the value of the requested PropertyDefinition 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 null.

      This overload will resolve the requested property in the following order, whereas the higher priority is from top to bottom:

      To resolve JVM properties or the system environment the property's key is prefixed with given 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 of PropertyDefinition.typeConverter()
      Parameters:
      prefix - the property key prefix for environment and JVM properties lookup
      property - 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 Comparable> T getOrDefault(PropertyDefinition property, T defaultValue)
      Returns the value of the requested PropertyDefinition if available in the declarative or programmatic configuration (XML or Config API), otherwise it will return the given defaultValue.

      This method overload won't do environment or JVM property lookup. A call to this overload is equivalent to getOrDefault(String, PropertyDefinition, Comparable) with null passed as the first parameter.

      Type Parameters:
      T - the type of the property, must be compatible with the conversion result of PropertyDefinition.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 requested PropertyDefinition 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 given defaultValue.

      This overload will resolve the requested property in the following order, whereas the higher priority is from top to bottom:

      To resolve JVM properties or the system environment the property's key is prefixed with given 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 of PropertyDefinition.typeConverter()
      Parameters:
      prefix - the property key prefix for environment and JVM properties lookup
      property - 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