public class ExclusivePublication extends Publication
ExclusivePublication
s are created via the Aeron.addExclusivePublication(String, int)
method,
and messages are sent via one of the Publication.offer(DirectBuffer)
methods, or a
tryClaim(int, BufferClaim)
and BufferClaim.commit()
method combination.
ExclusivePublication
s have the potential to provide greater throughput than the default Publication
which supports concurrent access.
The APIs used for tryClaim and offer are non-blocking.
Note: Instances are NOT threadsafe for offer and tryClaim methods but are for the others.
ADMIN_ACTION, BACK_PRESSURED, channel, channelStatusId, CLOSED, conductor, headerWriter, initialTermId, isClosed, logBuffers, logMetaDataBuffer, MAX_POSITION_EXCEEDED, maxMessageLength, maxPayloadLength, maxPossiblePosition, NOT_CONNECTED, originalRegistrationId, positionBitsToShift, positionLimit, registrationId, sessionId, streamId, termBufferLength
Modifier and Type | Method and Description |
---|---|
long |
appendPadding(int length)
Append a padding record log of a given length to make up the log to a position.
|
long |
availableWindow()
Available window for offering into a publication before the
Publication.positionLimit() is reached. |
long |
offer(DirectBuffer bufferOne,
int offsetOne,
int lengthOne,
DirectBuffer bufferTwo,
int offsetTwo,
int lengthTwo,
ReservedValueSupplier reservedValueSupplier)
Non-blocking publish of a message composed of two parts, e.g.
|
long |
offer(DirectBuffer buffer,
int offset,
int length,
ReservedValueSupplier reservedValueSupplier)
Non-blocking publish of a partial buffer containing a message.
|
long |
offer(DirectBufferVector[] vectors,
ReservedValueSupplier reservedValueSupplier)
Non-blocking publish by gathering buffer vectors into a message.
|
long |
offerBlock(MutableDirectBuffer buffer,
int offset,
int length)
Offer a block of pre-formatted message fragments directly into the current term.
|
long |
position()
Get the current position to which the publication has advanced for this stream.
|
int |
termId()
The current term-id of the publication.
|
int |
termOffset()
The current term-offset of the publication.
|
long |
tryClaim(int length,
BufferClaim bufferClaim)
Try to claim a range in the publication log into which a message can be written with zero copy semantics.
|
addDestination, asyncAddDestination, asyncRemoveDestination, channel, channelStatus, channelStatusId, close, initialTermId, isClosed, isConnected, isOriginal, maxMessageLength, maxPayloadLength, maxPossiblePosition, offer, offer, offer, offer, originalRegistrationId, positionBitsToShift, positionLimit, positionLimitId, registrationId, removeDestination, sessionId, streamId, termBufferLength, toString
public long position()
Publication
position
in class Publication
Publication.CLOSED
.public long availableWindow()
Publication
Publication.positionLimit()
is reached.availableWindow
in class Publication
Publication.positionLimit()
is reached. If
the publication is closed then Publication.CLOSED
will be returned.public int termId()
public int termOffset()
public long offer(DirectBuffer buffer, int offset, int length, ReservedValueSupplier reservedValueSupplier)
offer
in class Publication
buffer
- containing message.offset
- offset in the buffer at which the encoded message begins.length
- in bytes of the encoded message.reservedValueSupplier
- ReservedValueSupplier
for the frame.Publication.NOT_CONNECTED
,
Publication.BACK_PRESSURED
, Publication.ADMIN_ACTION
, Publication.CLOSED
, or Publication.MAX_POSITION_EXCEEDED
.public long offer(DirectBuffer bufferOne, int offsetOne, int lengthOne, DirectBuffer bufferTwo, int offsetTwo, int lengthTwo, ReservedValueSupplier reservedValueSupplier)
offer
in class Publication
bufferOne
- containing the first part of the message.offsetOne
- at which the first part of the message begins.lengthOne
- of the first part of the message.bufferTwo
- containing the second part of the message.offsetTwo
- at which the second part of the message begins.lengthTwo
- of the second part of the message.reservedValueSupplier
- ReservedValueSupplier
for the frame.Publication.NOT_CONNECTED
,
Publication.BACK_PRESSURED
, Publication.ADMIN_ACTION
, Publication.CLOSED
, or Publication.MAX_POSITION_EXCEEDED
.public long offer(DirectBufferVector[] vectors, ReservedValueSupplier reservedValueSupplier)
offer
in class Publication
vectors
- which make up the message.reservedValueSupplier
- ReservedValueSupplier
for the frame.Publication.NOT_CONNECTED
,
Publication.BACK_PRESSURED
, Publication.ADMIN_ACTION
, Publication.CLOSED
, or Publication.MAX_POSITION_EXCEEDED
.public long tryClaim(int length, BufferClaim bufferClaim)
BufferClaim.commit()
should be called thus making it
available.
Note: This method can only be used for message lengths less than MTU length minus header. If the claim is held after the publication is closed, or the client dies, then it will be unblocked to reach end-of-stream (EOS).
final BufferClaim bufferClaim = new BufferClaim();
if (publication.tryClaim(messageLength, bufferClaim) > 0L)
{
try
{
final MutableDirectBuffer buffer = bufferClaim.buffer();
final int offset = bufferClaim.offset();
// Work with buffer directly or wrap with a flyweight
}
finally
{
bufferClaim.commit();
}
}
tryClaim
in class Publication
length
- of the range to claim, in bytes..bufferClaim
- to be populated if the claim succeeds.Publication.NOT_CONNECTED
,
Publication.BACK_PRESSURED
, Publication.ADMIN_ACTION
, Publication.CLOSED
, or Publication.MAX_POSITION_EXCEEDED
.IllegalArgumentException
- if the length is greater than Publication.maxPayloadLength()
within an MTU.BufferClaim.commit()
,
BufferClaim.abort()
public long appendPadding(int length)
length
- of the range to claim, in bytes..Publication.NOT_CONNECTED
,
Publication.BACK_PRESSURED
, Publication.ADMIN_ACTION
, Publication.CLOSED
, or Publication.MAX_POSITION_EXCEEDED
.IllegalArgumentException
- if the length is greater than Publication.maxMessageLength()
.public long offerBlock(MutableDirectBuffer buffer, int offset, int length)
buffer
- containing the pre-formatted block of message fragments.offset
- offset in the buffer at which the first fragment begins.length
- in bytes of the encoded block.Publication.NOT_CONNECTED
,
Publication.BACK_PRESSURED
, Publication.ADMIN_ACTION
, Publication.CLOSED
, or Publication.MAX_POSITION_EXCEEDED
.IllegalArgumentException
- if the length is greater than remaining size of the current term.IllegalArgumentException
- if the first frame within the block is not properly formatted, i.e. if the
streamId
is not equal to the value returned by the Publication.streamId()
method or if the sessionId
is not equal to the value returned by the
Publication.sessionId()
method or if the frame type is not equal to the
HeaderFlyweight.HDR_TYPE_DATA
.Copyright © 2014-2020 Real Logic Limited. All Rights Reserved.