Class 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 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));
       }
     }