Class FailoverAccessPolicy

  • All Implemented Interfaces:
    ActionPolicy

    public class FailoverAccessPolicy
    extends Object
    implements ActionPolicy
    FailoverAccessPolicy is used to moderate the client request load during a failover event in order to allow cache servers adequate opportunity to re-establish partition backups.

    While typically not necessary to ensure the timely recovery to a "safe" state, this access policy could be used in situations where a heavy load of of high-latency requests may prevent or significantly delay cache servers from successfully acquiring exclusive access to partitions needing to be transferred or backed up.

    Since:
    Coherence 12.1.2
    Author:
    rhl 09.12.2011
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  FailoverAccessPolicy.MembershipListener
      The MemberListener is used to listen to service membership events to monitor the endangered status of the service.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      long m_cLimitMillis
      The amount of time after being in an endangered state after which the quorum policy makes a maximal effort to hold client requests.
      long m_cMaxDelayMillis
      The maximum amount of time (in ms) that a request could be delayed by this quorum policy.
      long m_cThresholdMillis
      The amount of time after being in an endangered state before the quorum policy should start to hold client requests.
      long m_ldtEndangered
      The time at which the service most recently became endangered (or 0 if the service is in the "safe" state).
      int m_nState
      One of the STATE_* constants representing the current quorum state.
      protected PartitionedService m_service
      The PartitionedService that this quorum policy is bound to.
      static int STATE_ENDANGERED
      Constant used to indicate that the service is in an endangered state.
      static int STATE_SAFE
      Constant used to indicate that the service is "safe" (non-endangered).
      static int STATE_UNKNOWN
      Constant used to indicate that the service is in an unknown (possibly endangered) state.
    • Constructor Summary

      Constructors 
      Constructor Description
      FailoverAccessPolicy()
      Default constructor.
      FailoverAccessPolicy​(long cThresholdMillis, long cLimitMillis, long cMaxDelayMillis)
      Construct a FailoverAccessPolicy according to the specified parameters.
    • Field Detail

      • STATE_SAFE

        public static final int STATE_SAFE
        Constant used to indicate that the service is "safe" (non-endangered).
        See Also:
        Constant Field Values
      • STATE_UNKNOWN

        public static final int STATE_UNKNOWN
        Constant used to indicate that the service is in an unknown (possibly endangered) state.
        See Also:
        Constant Field Values
      • STATE_ENDANGERED

        public static final int STATE_ENDANGERED
        Constant used to indicate that the service is in an endangered state.
        See Also:
        Constant Field Values
      • m_cThresholdMillis

        public long m_cThresholdMillis
        The amount of time after being in an endangered state before the quorum policy should start to hold client requests.
      • m_cLimitMillis

        public long m_cLimitMillis
        The amount of time after being in an endangered state after which the quorum policy makes a maximal effort to hold client requests.
      • m_cMaxDelayMillis

        public long m_cMaxDelayMillis
        The maximum amount of time (in ms) that a request could be delayed by this quorum policy.
      • m_nState

        public int m_nState
        One of the STATE_* constants representing the current quorum state.

        Note: this field is intentionally left non-volatile. The consequence of a "stale" read is that the first request per thread following a transition to endangered could be missed by this quorum (allowed to proceed). As this has no impact, we would rather avoid the additional volatile read on each "normal" operation.

      • m_ldtEndangered

        public long m_ldtEndangered
        The time at which the service most recently became endangered (or 0 if the service is in the "safe" state).
      • m_service

        protected PartitionedService m_service
        The PartitionedService that this quorum policy is bound to.
    • Constructor Detail

      • FailoverAccessPolicy

        public FailoverAccessPolicy()
        Default constructor.
      • FailoverAccessPolicy

        public FailoverAccessPolicy​(long cThresholdMillis,
                                    long cLimitMillis,
                                    long cMaxDelayMillis)
        Construct a FailoverAccessPolicy according to the specified parameters.
        Parameters:
        cThresholdMillis - the delay before the policy should start holding requests (after becoming endangered)
        cLimitMillis - the delay before the policy makes a maximal effort to hold requests (after becoming endangered)
        cMaxDelayMillis - the maximum amount of time to hold a request
    • Method Detail

      • getState

        public int getState()
        Return the current endangered state (one of the STATE_* constants).
        Returns:
        the current endangered state
      • setState

        protected void setState​(int nState)
        Set the endangered state (one of the STATE_* constants).
        Parameters:
        nState - the new endangered state
      • init

        public void init​(Service service)
        Called when the specified service loads and configures this policy.

        Note: A policy could be applied to multiple services.

        Specified by:
        init in interface ActionPolicy
        Parameters:
        service - the service that this policy applies to
      • isAllowed

        public boolean isAllowed​(Service service,
                                 Action action)
        Evaluate if the specified action is currently allowed by this policy.

        Note: for forward compatibility, implementations should generally return true for actions that are not recognized.

        Specified by:
        isAllowed in interface ActionPolicy
        Parameters:
        service - the service that is performing the action
        action - the action that is being performed
        Returns:
        true iff the specified action is currently allowed by this policy
      • calculateWaitTime

        protected long calculateWaitTime​(long cMillisEndangered)
        Return the amount of time that a request should be delayed before being allowed to proceed.
        Parameters:
        cMillisEndangered - the amount of time that the service has been endangered
        Returns:
        the amount of time (in ms) to delay the client request
      • checkEndangered

        protected boolean checkEndangered()
        Check to see if the associated service is endangered.

        Note: the caller must hold synchronization on this quorum policy.

        Returns:
        true iff the service is endangered