Package io.opencensus.impl.internal
Class DisruptorEventQueue
- java.lang.Object
-
- io.opencensus.impl.internal.DisruptorEventQueue
-
- All Implemented Interfaces:
EventQueue
@ThreadSafe public final class DisruptorEventQueue extends java.lang.Object implements EventQueue
A low-latency event queue for background updating of (possibly contended) objects. This is intended for use by instrumentation methods to ensure that they do not block foreground activities. To customize the action taken on reading the queue, derive a new class fromEventQueue.Entry
and pass it to theenqueue(Entry)
method. TheEventQueue.Entry.process()
method of your class will be called and executed in a background thread. This class is a Singleton.Example Usage: Given a class as follows:
public class someClass { public void doSomething() { // Do the work of the method. One result is a measurement of something. int measurement = doSomeWork(); // Make an update to the class state, based on this measurement. This work can take some // time, but can be done asynchronously, in the background. update(measurement); } public void update(int arg) { // do something } }
The work of calling
someClass.update()
can be executed in the backgound as follows:public class someClass { // Add a EventQueueEntry class that will process the update call. private static final class SomeClassUpdateEvent implements EventQueueEntry { private final SomeClass someClassInstance; private final int arg; SomeObjectUpdateEvent(SomeObject someClassInstance, int arg) { this.someClassInstance = someClassInstance; this.arg = arg; } @Override public void process() { someClassInstance.update(arg); } } public void doSomething() { int measurement = doSomeWork(); // Instead of calling update() directly, create an event to do the processing, and insert // it into the EventQueue. It will be processed in a background thread, and doSomething() // can return immediately. EventQueue.getInstance.enqueue(new SomeClassUpdateEvent(this, measurement)); } }
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
DisruptorEventQueue.DisruptorEnqueuer
private static class
DisruptorEventQueue.DisruptorEvent
private static class
DisruptorEventQueue.DisruptorEventFactory
private static class
DisruptorEventQueue.DisruptorEventHandler
Every event that gets added toEventQueue
will get processed here.-
Nested classes/interfaces inherited from interface io.opencensus.implcore.internal.EventQueue
EventQueue.Entry
-
-
Field Summary
Fields Modifier and Type Field Description private com.lmax.disruptor.dsl.Disruptor<DisruptorEventQueue.DisruptorEvent>
disruptor
private static int
DISRUPTOR_BUFFER_SIZE
private DisruptorEventQueue.DisruptorEnqueuer
enqueuer
private static DisruptorEventQueue
eventQueue
private static java.util.logging.Logger
logger
-
Constructor Summary
Constructors Modifier Constructor Description private
DisruptorEventQueue(com.lmax.disruptor.dsl.Disruptor<DisruptorEventQueue.DisruptorEvent> disruptor, DisruptorEventQueue.DisruptorEnqueuer enqueuer)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static DisruptorEventQueue
create()
void
enqueue(EventQueue.Entry entry)
Enqueues an event on theDisruptorEventQueue
.static DisruptorEventQueue
getInstance()
Returns theDisruptorEventQueue
instance.void
shutdown()
Shuts down the underlying disruptor.
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
DISRUPTOR_BUFFER_SIZE
private static final int DISRUPTOR_BUFFER_SIZE
- See Also:
- Constant Field Values
-
eventQueue
private static final DisruptorEventQueue eventQueue
-
disruptor
private final com.lmax.disruptor.dsl.Disruptor<DisruptorEventQueue.DisruptorEvent> disruptor
-
enqueuer
private volatile DisruptorEventQueue.DisruptorEnqueuer enqueuer
-
-
Constructor Detail
-
DisruptorEventQueue
private DisruptorEventQueue(com.lmax.disruptor.dsl.Disruptor<DisruptorEventQueue.DisruptorEvent> disruptor, DisruptorEventQueue.DisruptorEnqueuer enqueuer)
-
-
Method Detail
-
create
private static DisruptorEventQueue create()
-
getInstance
public static DisruptorEventQueue getInstance()
Returns theDisruptorEventQueue
instance.- Returns:
- the singleton
EventQueue
instance.
-
enqueue
public void enqueue(EventQueue.Entry entry)
Enqueues an event on theDisruptorEventQueue
.- Specified by:
enqueue
in interfaceEventQueue
- Parameters:
entry
- a class encapsulating the actions to be taken for event processing.
-
shutdown
public void shutdown()
Shuts down the underlying disruptor.- Specified by:
shutdown
in interfaceEventQueue
-
-