Class DisruptorEventQueue
java.lang.Object
io.opencensus.impl.internal.DisruptorEventQueue
- All Implemented Interfaces:
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 from
EventQueue.Entry and pass it to the enqueue(Entry) method. The EventQueue.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 ClassesModifier and TypeClassDescriptionprivate static classprivate static final classprivate static enumprivate static enumEvery event that gets added toEventQueuewill get processed here.Nested classes/interfaces inherited from interface EventQueue
EventQueue.Entry -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final com.lmax.disruptor.dsl.Disruptor<DisruptorEventQueue.DisruptorEvent> private static final intprivate static final DisruptorEventQueueprivate static final Logger -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateDisruptorEventQueue(com.lmax.disruptor.dsl.Disruptor<DisruptorEventQueue.DisruptorEvent> disruptor, DisruptorEventQueue.DisruptorEnqueuer enqueuer) -
Method Summary
Modifier and TypeMethodDescriptionprivate static DisruptorEventQueuecreate()voidenqueue(EventQueue.Entry entry) Enqueues an event on theDisruptorEventQueue.static DisruptorEventQueueReturns theDisruptorEventQueueinstance.voidshutdown()Shuts down the underlying disruptor.
-
Field Details
-
logger
-
DISRUPTOR_BUFFER_SIZE
private static final int DISRUPTOR_BUFFER_SIZE- See Also:
-
eventQueue
-
disruptor
-
enqueuer
-
-
Constructor Details
-
DisruptorEventQueue
private DisruptorEventQueue(com.lmax.disruptor.dsl.Disruptor<DisruptorEventQueue.DisruptorEvent> disruptor, DisruptorEventQueue.DisruptorEnqueuer enqueuer)
-
-
Method Details
-
create
-
getInstance
Returns theDisruptorEventQueueinstance.- Returns:
- the singleton
EventQueueinstance.
-
enqueue
Enqueues an event on theDisruptorEventQueue.- Specified by:
enqueuein 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:
shutdownin interfaceEventQueue
-