Enum HaMode

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<HaMode>

    public enum HaMode
    extends java.lang.Enum<HaMode>
    Failover (High-availability) mode
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      LOADBALANCE
      load-balance: driver will connect to any host using round-robin, permitting balancing connections
      NONE
      no ha-mode.
      REPLICATION
      replication mode : first is primary, other are replica
      SEQUENTIAL
      sequential: driver will always connect according to connection string order
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private HaMode​(java.lang.String value)  
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      static HaMode from​(java.lang.String value)
      Get HAMode from values or aliases
      abstract java.util.Optional<HostAddress> getAvailableHost​(java.util.List<HostAddress> hostAddresses, java.util.concurrent.ConcurrentMap<HostAddress,​java.lang.Long> denyList, boolean primary)
      List of hosts without blacklist entries, ordered according to HA mode
      static java.util.Optional<HostAddress> getAvailableHostInOrder​(java.util.List<HostAddress> hostAddresses, java.util.concurrent.ConcurrentMap<HostAddress,​java.lang.Long> denyList, boolean primary)
      return hosts of corresponding type (primary or not) without blacklisted hosts.
      static java.util.Optional<HostAddress> getAvailableRoundRobinHost​(HaMode haMode, java.util.List<HostAddress> hostAddresses, java.util.concurrent.ConcurrentMap<HostAddress,​java.lang.Long> denyList, boolean primary)
      return hosts of corresponding type (primary or not) without blacklisted hosts.
      static HostAddress getHostWithLessConnections​(java.util.List<HostAddress> hostAddresses, java.util.concurrent.ConcurrentMap<HostAddress,​java.lang.Long> denyList, boolean primary)
      If all hosts not blacklisted connection number are known, choose the host with the less connections.
      void resetLast()
      For testing purpose only
      static HaMode valueOf​(java.lang.String name)
      Returns the enum constant of this type with the specified name.
      static HaMode[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • REPLICATION

        public static final HaMode REPLICATION
        replication mode : first is primary, other are replica
      • SEQUENTIAL

        public static final HaMode SEQUENTIAL
        sequential: driver will always connect according to connection string order
      • LOADBALANCE

        public static final HaMode LOADBALANCE
        load-balance: driver will connect to any host using round-robin, permitting balancing connections
      • NONE

        public static final HaMode NONE
        no ha-mode. Connect to first host only
    • Field Detail

      • value

        private final java.lang.String value
      • lastRoundRobinPrimaryHost

        private HostAddress lastRoundRobinPrimaryHost
      • lastRoundRobinSecondaryHost

        private HostAddress lastRoundRobinSecondaryHost
    • Constructor Detail

      • HaMode

        private HaMode​(java.lang.String value)
    • Method Detail

      • values

        public static HaMode[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (HaMode c : HaMode.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static HaMode valueOf​(java.lang.String name)
        Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
        Parameters:
        name - the name of the enum constant to be returned.
        Returns:
        the enum constant with the specified name
        Throws:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • from

        public static HaMode from​(java.lang.String value)
        Get HAMode from values or aliases
        Parameters:
        value - value or alias
        Returns:
        HaMode if corresponding mode is found
      • getAvailableHostInOrder

        public static java.util.Optional<HostAddress> getAvailableHostInOrder​(java.util.List<HostAddress> hostAddresses,
                                                                              java.util.concurrent.ConcurrentMap<HostAddress,​java.lang.Long> denyList,
                                                                              boolean primary)
        return hosts of corresponding type (primary or not) without blacklisted hosts. hosts in blacklist reaching blacklist timeout will be present. order corresponds to connection string order.
        Parameters:
        hostAddresses - hosts
        denyList - blacklist
        primary - returns primary hosts or replica
        Returns:
        list without denied hosts
      • getHostWithLessConnections

        public static HostAddress getHostWithLessConnections​(java.util.List<HostAddress> hostAddresses,
                                                             java.util.concurrent.ConcurrentMap<HostAddress,​java.lang.Long> denyList,
                                                             boolean primary)
        If all hosts not blacklisted connection number are known, choose the host with the less connections.
        Parameters:
        hostAddresses - host addresses
        denyList - blacklist
        primary - requires primary host
        Returns:
        the host with less connection, or null if unknown.
      • getAvailableRoundRobinHost

        public static java.util.Optional<HostAddress> getAvailableRoundRobinHost​(HaMode haMode,
                                                                                 java.util.List<HostAddress> hostAddresses,
                                                                                 java.util.concurrent.ConcurrentMap<HostAddress,​java.lang.Long> denyList,
                                                                                 boolean primary)
        return hosts of corresponding type (primary or not) without blacklisted hosts. hosts in blacklist reaching blacklist timeout will be present, RoundRobin Order.
        Parameters:
        haMode - current haMode
        hostAddresses - hosts
        denyList - blacklist
        primary - returns primary hosts or replica
        Returns:
        list without denied hosts
      • resetLast

        public void resetLast()
        For testing purpose only
      • getAvailableHost

        public abstract java.util.Optional<HostAddress> getAvailableHost​(java.util.List<HostAddress> hostAddresses,
                                                                         java.util.concurrent.ConcurrentMap<HostAddress,​java.lang.Long> denyList,
                                                                         boolean primary)
        List of hosts without blacklist entries, ordered according to HA mode
        Parameters:
        hostAddresses - hosts
        denyList - hosts temporary denied
        primary - type
        Returns:
        list without denied hosts