Disruptor

Creates an object which uses an LMAX Disruptor to store data in shared memory.

new Disruptor(shm_name: string, num_elements: integer, element_size: integer, num_consumers: integer, consumer: integer, init: boolean, spin: boolean)
Parameters
shm_name (string) Name of shared memory object to use (see shm_open ).
num_elements (integer) Number of elements in the Disruptor (i.e. its capacity).
element_size (integer) Size of each element in bytes.
num_consumers (integer) Total number of objects that will be reading data from the Disruptor.
consumer (integer) Each object that reads data from the Disruptor must have a unique ID. This should be a number between 0 and num_consumers - 1 . If the object is only going to write data, consumer can be anything.
init (boolean) Whether to create and initialize the shared memory backing the Disruptor. You should arrange your application so this is done once, at the start.
spin (boolean) If true then methods on this object which read from the Disruptor won't return to your application until a value is ready. Methods which write to the Disruptor won't return while the Disruptor is full. The *Sync methods will block Node's main thread and the asynchronous methods will repeatedly post tasks to the thread pool, in order to let other tasks get a look in. If you want to implement your own retry algorithm (or use some out-of-band notification mechanism), specify spin as false and check method return values.
Instance Members
produceClaim(cb?)
produceClaimSync()
produceClaimMany(n, cb?)
produceClaimManySync(n)
produceClaimAvail(max, cb?)
produceClaimAvailSync(max)
produceCommit(claimStart?, claimEnd?, cb?)
produceCommitSync(claimStart?, claimEnd?)
consumeNew(cb?)
consumeNewSync()
consumeCommit()
produceRecover(claimStart, claimEnd)
release(mark_ignore)
prevClaimStart
prevClaimEnd
prevConsumeStart
elementSize
spin

produceClaimCallback

Callback type for reserving a single element in the Disruptor for writing.

produceClaimCallback(err: Error?, buf: Buffer, claimStart: integer, claimEnd: integer)
Parameters
err (Error?) Error, if one occurred.
buf (Buffer) Buffer for writing data to the Disruptor. If the Disruptor was full and spin (see the constructor ) is false , buf will be empty. Otherwise its length will be element_size . buf is backed by shared memory so may be overwritten after you call produceCommit or produceCommitSync .
claimStart (integer) The Disruptor maintains a strictly increasing count of the total number of elements produced since it was created. This is how many elements were produced before buf was reserved.
claimEnd (integer) The Disruptor maintains a strictly increasing count of the total number of elements produced since it was created. This is how many elements were produced after buf was reserved, minus 1.

produceClaimManyCallback

Callback type for reserving a number of elements in the Disruptor for writing.

produceClaimManyCallback(err: Error?, bufs: Array<Buffer>, claimStart: integer, claimEnd: integer)
Parameters
err (Error?) Error, if one occurred.
bufs (Array<Buffer>) Array of buffers for writing data to the Disruptor. If the Disruptor didn't have enought free elements and spin (see the constructor ) is false , bufs will be empty. Otherwise, it will contain at least one buffer and each buffer will be a multiple of element_size in length. The maximum length of all buffers will be element_size * num_elements bytes. The buffers are backed by shared memory so may be overwritten after you call produceCommit or produceCommitSync .
claimStart (integer) The Disruptor maintains a strictly increasing count of the total number of elements produced since it was created. This is how many elements were produced before bufs was reserved.
claimEnd (integer) The Disruptor maintains a strictly increasing count of the total number of elements produced since it was created. This is how many elements were produced after bufs was reserved, minus 1.

produceCommitCallback

Callback type for commiting data to the Disruptor

produceCommitCallback(err: Error?, committed: boolean)
Parameters
err (Error?) Error, if one occurred.
committed (boolean) Whether the data was committed to the Disruptor. If some elements reserved before claimStart remain uncommitted and spin (see the constructor ) is false , committed will be false . Otherwise the data was committed and committed will be true .

consumeNewCallback

Callback type for reading new data from the Disruptor

consumeNewCallback(err: Error?, bufs: Array<Buffer>, start: integer)
Parameters
err (Error?) Error, if one occurred.
bufs (Array<Buffer>) Array of buffers containing new data ready to read from the Disruptor. If no new data was available and spin (see the constructor ) is false , the array will be empty. Otherwise it will contain at least one buffer and each buffer will be a multiple of element_size in length. The buffers are backed by shared memory so may be overwritten after you call consumeCommit .
start (integer) The Disruptor maintains a strictly increasing count of the total number of elements consumed since it was created. This is how many elements were consumed before bufs was read (if bufs isn't empty).

DisruptorReadStream

Creates a stream which reads from a disruptor.

new DisruptorReadStream(disruptor: Disruptor, options: Object)

Extends stream.Readable

Parameters
disruptor (Disruptor) Disruptor to read from. Its element_size must be 1 byte and it must not spin .
options (Object) Passed to stream.Readable .

DisruptorWriteStream

Creates a stream which writes to a disruptor.

new DisruptorWriteStream(disruptor: Disruptor, options: Object)

Extends stream.Writable

Parameters
disruptor (Disruptor) Distruptor to write to. Its element_size must be 1 byte and it must not spin .
options (Object) Passed to stream.Writable .