com.netflix.servo.publish
Class AsyncMetricObserver

java.lang.Object
  extended by com.netflix.servo.publish.BaseMetricObserver
      extended by com.netflix.servo.publish.AsyncMetricObserver
All Implemented Interfaces:
MetricObserver

public final class AsyncMetricObserver
extends BaseMetricObserver

Wraps another observer and asynchronously updates it in the background. The update call will always return immediately. If the queue fills up newer updates will overwrite older updates.

If an exception is thrown when calling update on wrapped observer it will be logged, but otherwise ignored.


Constructor Summary
AsyncMetricObserver(java.lang.String name, MetricObserver observer)
          Creates a new instance with an unbounded queue and no expiration time.
AsyncMetricObserver(java.lang.String name, MetricObserver observer, int queueSize)
          Creates a new instance with no expiration time.
AsyncMetricObserver(java.lang.String name, MetricObserver observer, int queueSize, long expireTime)
          Creates a new instance.
 
Method Summary
 void stop()
          Stop the background thread that pushes updates to the wrapped observer.
 void updateImpl(java.util.List<Metric> metrics)
          Update method that should be defined by sub-classes.
 
Methods inherited from class com.netflix.servo.publish.BaseMetricObserver
getFailedUpdateCount, getName, getUpdateCount, incrementFailedCount, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AsyncMetricObserver

public AsyncMetricObserver(java.lang.String name,
                           MetricObserver observer,
                           int queueSize,
                           long expireTime)
Creates a new instance.

Parameters:
name - name of this observer
observer - a wrapped observer that will be updated asynchronously
queueSize - maximum size of the update queue, if the queue fills up older entries will be dropped
expireTime - age in milliseconds before an update expires and will not be passed on to the wrapped observer

AsyncMetricObserver

public AsyncMetricObserver(java.lang.String name,
                           MetricObserver observer)
Creates a new instance with an unbounded queue and no expiration time.

Parameters:
name - name of this observer
observer - a wrapped observer that will be updated asynchronously

AsyncMetricObserver

public AsyncMetricObserver(java.lang.String name,
                           MetricObserver observer,
                           int queueSize)
Creates a new instance with no expiration time.

Parameters:
name - name of this observer
observer - a wrapped observer that will be updated asynchronously
queueSize - maximum size of the update queue, if the queue fills up older entries will be dropped
Method Detail

updateImpl

public void updateImpl(java.util.List<Metric> metrics)
Update method that should be defined by sub-classes. This method will get invoked and counts will be maintained in the base observer.

Specified by:
updateImpl in class BaseMetricObserver

stop

public void stop()
Stop the background thread that pushes updates to the wrapped observer.