Class AbstractDiscoveryStrategy

    • 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()
      The stop 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 a ILogger instance bound to the current class.
      protected <T extends java.lang.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.
      protected <T extends java.lang.Comparable>
      T
      getOrDefault​(java.lang.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.
      protected <T extends java.lang.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.
      protected <T extends java.lang.Comparable>
      T
      getOrNull​(java.lang.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.
      PartitionGroupStrategy getPartitionGroupStrategy()  
      PartitionGroupStrategy getPartitionGroupStrategy​(java.util.Collection<? extends Member> allMembers)
      Returns a custom implementation of a PartitionGroupStrategy to override default behavior of zone aware backup strategies PartitionGroupMetaData 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()
      The start 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
    • 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
        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​(java.util.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 PartitionGroupMetaData 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 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 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 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 a ILogger 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 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 java.lang.Comparable> T getOrNull​(java.lang.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:

        • System.getProperty(String): JVM properties
        • System.getenv(String): System environment
        • Configuration properties of this DiscoveryStrategy
        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 java.lang.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 java.lang.Comparable> T getOrDefault​(java.lang.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:

        • System.getProperty(String): JVM properties
        • System.getenv(String): System environment
        • Configuration properties of this DiscoveryStrategy
        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