com.netflix.hystrix.util
Class HystrixTimer

java.lang.Object
  extended by com.netflix.hystrix.util.HystrixTimer

public class HystrixTimer
extends java.lang.Object

Timer used by the HystrixCollapser to trigger batch executions.

Used instead of java.util.Timer because:


Nested Class Summary
static interface HystrixTimer.TimerListener
           
 
Method Summary
 java.lang.ref.Reference<HystrixTimer.TimerListener> addTimerListener(HystrixTimer.TimerListener listener)
          Add a HystrixTimer.TimerListener that will be executed until it is garbage collected or removed by clearing the returned Reference.
static HystrixTimer getInstance()
          Retrieve the global instance with a single backing thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static HystrixTimer getInstance()
Retrieve the global instance with a single backing thread.


addTimerListener

public java.lang.ref.Reference<HystrixTimer.TimerListener> addTimerListener(HystrixTimer.TimerListener listener)
Add a HystrixTimer.TimerListener that will be executed until it is garbage collected or removed by clearing the returned Reference.

NOTE: It is the responsibility of code that adds a listener via this method to clear this listener when completed.

 // add a TimerListener 
 Reference<TimerListener> listener = HystrixTimer.getInstance().addTimerListener(listenerImpl);
 
 // sometime later, often in a thread shutdown, request cleanup, servlet filter or something similar the listener must be shutdown via the clear() method
 listener.clear();
 

Parameters:
listener - TimerListener implementation that will be triggered according to its getIntervalTimeInMilliseconds() method implementation.
Returns:
reference to the TimerListener that allows cleanup via the clear() method