@ThreadSafe public final class DisruptorEventQueue extends Object implements io.opencensus.implcore.internal.EventQueue
EventQueue.Entry and pass it to the EventQueue.enqueue(Entry) method. The 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));
}
}
| Modifier and Type | Method and Description |
|---|---|
void |
enqueue(io.opencensus.implcore.internal.EventQueue.Entry entry)
Enqueues an event on the
DisruptorEventQueue. |
static DisruptorEventQueue |
getInstance()
Returns the
DisruptorEventQueue instance. |
void |
shutdown()
Shuts down the underlying disruptor.
|
public static DisruptorEventQueue getInstance()
DisruptorEventQueue instance.EventQueue instance.public void enqueue(io.opencensus.implcore.internal.EventQueue.Entry entry)
DisruptorEventQueue.enqueue in interface io.opencensus.implcore.internal.EventQueueentry - a class encapsulating the actions to be taken for event processing.public void shutdown()
shutdown in interface io.opencensus.implcore.internal.EventQueue