Class BaseNodeMonitor<T>

  • Direct Known Subclasses:
    TrafficNodeMonitor

    public abstract class BaseNodeMonitor<T>
    extends Object
    A node monitor is responsible for maintaining the state of a monitored node. It has the following properties:
    • A node is taken out of operation if it fails
    • A node is put back in operation when it responds correctly again responseAfterFailLimit times unless it has failed failQuarantineLimit. In the latter case it won't be put into operation again before that time period has expired
    Author:
    bratseth
    • Field Detail

      • log

        protected static Logger log
      • node

        protected T node
        The object representing the monitored node
      • isWorking

        protected boolean isWorking
      • isQuarantined

        protected boolean isQuarantined
        Whether this node is quarantined for unstability
      • failedAt

        protected long failedAt
        The last time this node failed, in ms
      • respondedAt

        protected long respondedAt
        The last time this node responded (failed or succeeded), in ms
      • succeededAt

        protected long succeededAt
        The last time this node responded successfully
    • Constructor Detail

      • BaseNodeMonitor

        public BaseNodeMonitor​(boolean internal)
    • Method Detail

      • getNode

        public T getNode()
      • isWorking

        public boolean isWorking()
        Returns whether this node is currently in a state suitable for receiving traffic (default true)
      • isQuarantined

        @Deprecated
        public boolean isQuarantined()
        Deprecated.
        Not used
      • failed

        public abstract void failed​(ErrorMessage error)
        Called when this node fails.
        Parameters:
        error - a description of the error
      • responded

        public abstract void responded()
        Called when a response is received from this node. If the node was quarantined and it has been in that state for more than QuarantineTime milliseconds, it is taken out of quarantine. if it is not in quarantine but is not working, it may be set to working if this method is called at least responseAfterFailLimit times
      • isIdle

        @Deprecated
        public boolean isIdle()
        Deprecated.
        Not used
      • now

        protected long now()
      • setWorking

        protected abstract void setWorking​(boolean working,
                                           String explanation)
        Thread-safely changes the state of this node if required
      • isInternal

        public boolean isInternal()
        Returns whether or not this is monitoring an internal node. Default is false.