0

i learn that LMAX disruptor is a High Performance Inter-Thread Messaging Library. But when i try to use it ,i found that the eventhandler use a callback method to process the data.

void onEvent(T event,
       long sequence,
       boolean endOfBatch)
         throws java.lang.Exception

Called when a publisher has published an event to the RingBuffer

But if i don't use callback to get data, i write a while(true) to get data by my self, what should i do ?

thanks!

dwzhao
  • 87
  • 1
  • 9
  • Your question isn't all that clear - what are you trying to achieve? What do you mean by your "own method"? – Paolo Jan 21 '15 at 12:02
  • @Paolo, i don't want to use callback way to get data, i want use while(true) to get data, what should i do? thanks. – dwzhao Jan 21 '15 at 12:10
  • You should write your callback so it pushes the event into a queue. You can then loop over the queue. – OldCurmudgeon Jan 21 '15 at 12:20

1 Answers1

0

You should write your callback so it pushes the event into a queue. You can then iterate over the queue.

Queue<Event> queue = new ArrayBlockingQueue(10);

void onEvent(Event event,
        long sequence,
        boolean endOfBatch)
        throws java.lang.Exception {
    queue.add(event);
}

public void test() {
    for ( Event event : queue ) {
        // Your stuff here.
    }
}
OldCurmudgeon
  • 64,482
  • 16
  • 119
  • 213
  • would this way will slow down the process speed? – dwzhao Jan 21 '15 at 13:22
  • @davidzhao - Of course it could - if you need maximum speed go to the bare metal and use the callback - if you need to do some flim-flam like this on it you have to expect a downside. That said - there shouldn't be much speed hit - probably unmeasurable. – OldCurmudgeon Jan 21 '15 at 13:47