Class GuardSupport.Context

    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected Context​(Guardable guardable, long cTimeoutMillis, float flPctRecover)
      Construct a Context.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Guardable getGuardable()
      Return the Guardable for this context.
      Guardian getGuardian()
      Return the Guardian for this context.
      protected long getMissedSoftTimeout()
      Return the last missed soft-timeout for this Guardable (that resulted in a recovery attempt).
      protected long getRecoveryMillis()
      Return the recovery interval for this Guardable.
      protected long getSoftTimeout()
      Return the next soft-timeout for this Guardable.
      long getSoftTimeoutMillis()
      Return the soft timeout interval for the represented Guardable.
      int getState()
      Return the state of the Guardable.
      protected long getTimeout()
      Return the next timeout for this Guardable.
      long getTimeoutMillis()
      Return the hard timeout interval for the represented Guardable.
      void heartbeat()
      Called by the Guardable to signal that it is still alive.
      void heartbeat​(long cMillis)
      Called by the Guardable to signal that it is still alive, and that it should not be considered timed out for the specified number of milliseconds.
      protected boolean isSuspect​(long ldtNow)
      Is the Guardable represented by this GuardContext suspect (in danger of timing out soon).
      protected boolean isTimedOut​(long ldtNow)
      Is the Guardable represented by this GuardContext timed out?
      protected void onRecovery()
      Called when the guardable enters the "RECOVERY" state.
      protected void onTerminate()
      Called when the guardable enters the "TERMINATING" state.
      void release()
      Release this context, causing the Guardian to discontinue monitoring of the represented Guardable.
      void reset()
      If more than half of the soft-timeout interval has passed, issue a heartbeat and clear the interrupted status if set.
      protected void setMissedSoftTimeout​(long ldtSoftTimeout)
      Set the missed soft-timeout for this guardable.
      protected void setRecoveryMillis​(long cRecoveryMillis)
      Set the recovery interval for this Guardable.
      protected void setSoftTimeout​(long ldtSoftTimeout)
      Set the next soft-timeout for this Guardable.
      protected void setState​(int nState)
      Set the state of the GuardContext to the specified value.
      protected void setTimeout​(long ldtTimeout)
      Set the next timeout for this Guardable.
      String toString()
      Return a human-readable description.
    • Field Detail

      • m_nState

        protected volatile int m_nState
        The current state of the Context.
      • m_ldtTimeout

        protected long m_ldtTimeout
        The next timeout for the Guardable. This property is only used by the guardian thread.
      • m_cRecoveryMillis

        protected volatile long m_cRecoveryMillis
        The amount of time to allow for recovery
      • m_ldtSoftTimeout

        protected volatile long m_ldtSoftTimeout
        The next soft-timeout for the Guardable
      • f_guardable

        protected final Guardable f_guardable
        The Guardable represented by this GuardContext
      • m_cDefaultTimeoutMillis

        protected long m_cDefaultTimeoutMillis
        The default timeout interval to use for the represented Guardable.
      • m_cTimeoutMillis

        protected long m_cTimeoutMillis
        The timeout interval to use for the represented Guardable.
      • m_cDefaultSoftTimeoutMillis

        protected long m_cDefaultSoftTimeoutMillis
        The default soft-timeout interval to use for the represented Guardable.
      • m_ldtLastMissedSoftTimeout

        protected long m_ldtLastMissedSoftTimeout
        The soft-timeout stamp that was violated, resulting in a recovery attempt.
      • m_flPctRecover

        protected float m_flPctRecover
        Percentage of the timeout after which to attempt recovery of the Guardable.
    • Constructor Detail

      • Context

        protected Context​(Guardable guardable,
                          long cTimeoutMillis,
                          float flPctRecover)
        Construct a Context.
        Parameters:
        guardable - the guardable represented by this Context
        cTimeoutMillis - the timeout interval for the specified Guardable
        flPctRecover - the percentage of the timeout after which to attempt recovery of the Guardable; 0 < flPctRecover <= 1.0
    • Method Detail

      • setState

        protected void setState​(int nState)
        Set the state of the GuardContext to the specified value.
        Parameters:
        nState - the state to set this GuardContext to
      • getTimeout

        protected long getTimeout()
        Return the next timeout for this Guardable.
        Returns:
        the next timestamp, after which this Guardable should be considered timed out
      • setTimeout

        protected void setTimeout​(long ldtTimeout)
        Set the next timeout for this Guardable.
        Parameters:
        ldtTimeout - the next timestamp, after which this Guardable should be considered timed out
      • getSoftTimeout

        protected long getSoftTimeout()
        Return the next soft-timeout for this Guardable. The soft-timeout is used to determine when to attempt recovery of the Guardable.
        Returns:
        the next timestamp, after which this Guardable should be considered suspect, and recovery attempted
      • setSoftTimeout

        protected void setSoftTimeout​(long ldtSoftTimeout)
        Set the next soft-timeout for this Guardable.
        Parameters:
        ldtSoftTimeout - the next timestamp, after which this Guardable should be considered suspect, and recovery attempted
      • getRecoveryMillis

        protected long getRecoveryMillis()
        Return the recovery interval for this Guardable.
        Returns:
        the recovery interval for this Guardable
      • setRecoveryMillis

        protected void setRecoveryMillis​(long cRecoveryMillis)
        Set the recovery interval for this Guardable.
        Parameters:
        cRecoveryMillis - the recovery interval for this Guardable
      • getMissedSoftTimeout

        protected long getMissedSoftTimeout()
        Return the last missed soft-timeout for this Guardable (that resulted in a recovery attempt).
        Returns:
        the last missed soft-timeout for this guardable
      • setMissedSoftTimeout

        protected void setMissedSoftTimeout​(long ldtSoftTimeout)
        Set the missed soft-timeout for this guardable.
        Parameters:
        ldtSoftTimeout - the soft-timeout that was missed
      • isTimedOut

        protected boolean isTimedOut​(long ldtNow)
        Is the Guardable represented by this GuardContext timed out?
        Parameters:
        ldtNow - the current timestamp
        Returns:
        true iff the represented Guardable is timed out
      • isSuspect

        protected boolean isSuspect​(long ldtNow)
        Is the Guardable represented by this GuardContext suspect (in danger of timing out soon).
        Parameters:
        ldtNow - the current timestamp
        Returns:
        true iff the represented Guardable is suspect
      • reset

        public void reset()
        If more than half of the soft-timeout interval has passed, issue a heartbeat and clear the interrupted status if set.
      • toString

        public String toString()
        Return a human-readable description.
        Overrides:
        toString in class Object
        Returns:
        a human-readable description
      • heartbeat

        public void heartbeat()
        Called by the Guardable to signal that it is still alive.
        Specified by:
        heartbeat in interface Guardian.GuardContext
      • heartbeat

        public void heartbeat​(long cMillis)
        Called by the Guardable to signal that it is still alive, and that it should not be considered timed out for the specified number of milliseconds.
        Specified by:
        heartbeat in interface Guardian.GuardContext
        Parameters:
        cMillis - the number of milliseconds for which the guardable should not be considered timed out
      • getState

        public int getState()
        Return the state of the Guardable. Valid values are STATE_* constants.
        Specified by:
        getState in interface Guardian.GuardContext
        Returns:
        the state of the Guardable
      • release

        public void release()
        Release this context, causing the Guardian to discontinue monitoring of the represented Guardable.
        Specified by:
        release in interface Guardian.GuardContext
      • getSoftTimeoutMillis

        public long getSoftTimeoutMillis()
        Return the soft timeout interval for the represented Guardable.

        The soft timeout interval is the amount of time that must pass after the last received heartbeat before a recovery attempt is made.

        Specified by:
        getSoftTimeoutMillis in interface Guardian.GuardContext
        Returns:
        the soft timeout interval for the represented Guardable
      • getTimeoutMillis

        public long getTimeoutMillis()
        Return the hard timeout interval for the represented Guardable.
        Specified by:
        getTimeoutMillis in interface Guardian.GuardContext
        Returns:
        the hard timeout interval for the represented Guardable
      • onRecovery

        protected void onRecovery()
        Called when the guardable enters the "RECOVERY" state.
      • onTerminate

        protected void onTerminate()
        Called when the guardable enters the "TERMINATING" state.