java - Disruptor how to use his ring buffer to read a file? -
i looking use dirsuptor ring buffer parse file. not see how set range of value ring buffer.
in example below seem. loop each item assign buffer. me, assign directly x items.
when fileinputstream.read( byte[] bytes ), put these bytes ring buffer.
usually buffer twice bigger bytes read. read page while computing 1 ( eg bytes array length == buffer / 2 ):
executorservice exec = executors.newcachedthreadpool(); // preallocate ringbuffer 1024 valueevents disruptor<valueevent> disruptor = new disruptor<valueevent>(valueevent.event_factory, 1024, exec); // build dependency graph ringbuffer<valueevent> ringbuffer = disruptor.start(); (long = 10; < 2000; i++) { string uuid = uuid.randomuuid().tostring(); // 2 phase commit. grab 1 of 1024 slots long seq = ringbuffer.next(); valueevent valueevent = ringbuffer.get(seq); valueevent.setvalue(uuid); ringbuffer.publish(seq); }
thanks
since version 3.0.0 of disruptor has supported batch publication.
there variety of publishevents
methods on ringbuffer
depending on how wish transform events.
given sample code suspect want @ this version, , supply array of uuid
s. there multiple versions depending on how many arguments wish pass translator.
the alternative version capture uuid in eventtranslator
self.
Comments
Post a Comment