4.2.0
Creates an object which uses an LMAX Disruptor to store data in shared memory.
(integer)
Number of elements in the Disruptor (i.e. its capacity).
(integer)
Size of each element in bytes.
(integer)
Total number of objects that will be reading data from the Disruptor.
(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.
(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.
(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.
Reserve the next element in the Disruptor for writing data into.
(produceClaimCallback?)
Called once an element has been reserved, or
spin
(see the
constructor
) is
false
and the Disruptor is full. If you don't pass
cb
then a
Promise
.
(undefined | Promise)
:
If
cb
is
not
supplied then a
Promise
is returned which resolves to the data that would have been passed to it.
Reserve the next element in the Disruptor for writing data into.
Buffer
:
Buffer for writing data to the Disruptor. If the Disruptor was full and
spin
(see the
constructor
) is
false
, the buffer will be empty. Otherwise its length will be
element_size
. The buffer is backed by shared memory so may be overwitten after you call
produceCommit
or
produceCommitSync
.
Reserve a number of elements in the Disruptor for writing data into.
(integer)
Number of elements to reserve.
(produceClaimManyCallback?)
Called once the elements have been reserved, or
spin
(see the
constructor
) is
false
and the Disruptor didn't have enough free elements.
(undefined | Promise)
:
If
cb
is
not
supplied then a
Promise
is returned which resolves to the data that would have been passed to it.
Reserve a number of elements in the Disruptor for writing data into.
(integer)
Number of elements to reserve.
Array<Buffer>
:
Array of buffers for writing data to the Disruptor. If the Disruptor didn't have enough free elements 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 total size of the buffers in the array will be
n * element_size
. The buffers are backed by shared memory so may be overwritten after you call
produceCommit
or
produceCommitSync
.
Reserve all free elements in the Disruptor for writing data into.
(integer)
Maximum number of free elements to reserve.
(produceClaimManyCallback?)
Called once elements have been reserved, or
spin
(see the
constructor
) is
false
and the Disruptor didn't have any free elements.
(undefined | Promise)
:
If
cb
is
not
supplied then a
Promise
is returned which resolves to the data that would have been passed to it.
Reserve all free elements in the Disruptor for writing data into.
(integer)
Maximum number of free elements to reserve.
Array<Buffer>
:
Array of buffers for writing data to the Disruptor. If the Disruptor didn't have any free elements 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
is length. The buffers are backed by shared memory so may be overwritten after you call
produceCommit
or
produceCommitSync
.
Commit data to the Disruptor. Call this once you've finished writing data to buffers you reserved.
(integer?)
Specifies the start of the buffer you want to commit. You can pass a value you received via
produceClaimCallback
,
produceClaimManyCallback
or
produceClaimAvailCallback
. If you don't specify a value,
prevClaimStart
is used.
(integer?)
Specifies the end of the buffer you want to commit. You can pass a value you received via
produceClaimCallback
,
produceClaimManyCallback
or
produceClaimAvailCallback
. If you don't specify a value,
prevClaimEnd
is used.
(produceCommitCallback?)
Called once the elements in the buffers have been committed to the Disruptor, or
spin
(see the
constructor
) is
false
and the elements couldn't be committed (because other producers haven't committed their data yet). No copying occurs during the operation.
(undefined | Promise)
:
If
cb
is
not
supplied then a
Promise
is returned which resolves to the data that would have been passed to it.
Commit data to the Disruptor. Call this once you've finished writing data to buffers you reserved.
(integer?)
Specifies the start of the buffer you want to commit. You can pass a value you received via
produceClaimCallback
,
produceClaimManyCallback
or
produceClaimAvailCallback
. If you don't specify a value,
prevClaimStart
is used.
(integer?)
Specifies the end of the buffer you want to commit. You can pass a value you received via
produceClaimCallback
,
produceClaimManyCallback
or
produceClaimAvailCallback
. If you don't specify a value,
prevClaimEnd
is used.
boolean
:
Whether the data was committed to the Disruptor. If some elements reserved before
claimStart
remain uncommitted and
spin
(see the
constructor
) is
false
, the return value will be
false
. Otherwise the data was committed and the return value will be
true
.
Read new data from the Disruptor.
Elements written to since consumeNew, consumeNewSync or
consumeCommit were called on this object are passed to cb
.
A call to consumeCommit is made before checking for new data.
(consumeNewCallback?)
Called once new elements are ready, or
spin
(see the
constructor
) is
false
and no elements have been written to the Disruptor.
(undefined | Promise)
:
If
cb
is
not
supplied then a
Promise
is returned which resolves to the data that would have been passed to it.
Read new data from the Disruptor.
Elements written to since consumeNew, consumeNewSync or consumeCommit were called on this object are returned.
A call to consumeCommit is made before checking for new data.
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
.
Tell the Disruptor you've finished reading data. Call this once you've finished with buffers returned by consumeNew or consumeNewSync.
This is called by consumeNew and consumeNewSync before they check for new data.
boolean
:
Whether the Disruptor was in the expected state. This will always return
true
unless your application incorrectly uses objects with the same consumer ID to access the Disruptor concurrently.
Reserve elements you've reserved before.
(integer)
Specifies the start of the buffer you want to reserve. You can pass a value you received via
produceClaimCallback
,
produceClaimManyCallback
,
produceClaimAvailCallback
or
prevClaimStart
.
(integer)
Specifies the end of the buffer you want to reserve. You can pass a value you received via
produceClaimCallback
,
produceClaimManyCallback
,
produceClaimAvailCallback
or
prevClaimEnd
.
Detaches from the shared memory backing the Disruptor.
Although this will be called when the object is garbage collected, you can force the shared memory to be unmapped by calling this function.
Don't use the object again afterwards!
(boolean
= false
)
Whether publishers should ignore consumers that have this Disruptor's unique ID.
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
the previous call to
produceClaim
,
produceClaimSync
,
produceClaimMany
,
produceClaimManySync
,
produceClaimAvail
or
produceClaimAvailSync
.
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
the previous call to
produceClaim
,
produceClaimSync
,
produceClaimMany
,
produceClaimManySync
,
produceClaimAvail
or
produceClaimAvailSync
, minus 1.
integer
:
The Disruptor maintains a strictly increasing count of the total number of elements consumed since it was created. This is the how many elements were consumed
before
the previous call to
consumeNew
or
consumeNewSync
.
integer
:
Size of each element in the Disruptor in bytes.
Callback type for reserving a single element in the Disruptor for writing.
(Error?)
Error, if one occurred.
(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
.
(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.
(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.
Callback type for reserving a number of elements in the Disruptor for writing.
(Error?)
Error, if one occurred.
(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
.
(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.
(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.
Callback type for commiting data to the Disruptor
(Error?)
Error, if one occurred.
(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
.
Callback type for reading new data from the Disruptor
(Error?)
Error, if one occurred.
(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
.
(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).
Creates a stream which reads from a disruptor.
Extends stream.Readable
Creates a stream which writes to a disruptor.
Extends stream.Writable
(Disruptor)
Distruptor
to write to. Its
element_size
must be 1 byte and it must not
spin
.