Class ExclusivePublication
- All Implemented Interfaces:
AutoCloseable
ExclusivePublications 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.
ExclusivePublications have the potential to provide greater throughput than the default Publication
which supports concurrent access.
The APIs for tryClaim and offer are non-blocking.
Note: Instances are NOT threadsafe for offer and tryClaim methods but are for the others.
-
Field Summary
Fields inherited from class io.aeron.Publication
ADMIN_ACTION, BACK_PRESSURED, CLOSED, MAX_POSITION_EXCEEDED, NOT_CONNECTED -
Method Summary
Modifier and TypeMethodDescriptionlongappendPadding(int length) Append a padding record to log of a given length to make up the log to a position.longAvailable window for offering into a publication before thePublication.positionLimit()is reached.longoffer(DirectBufferVector[] vectors, ReservedValueSupplier reservedValueSupplier) Non-blocking publish by gathering buffer vectors into a message.longoffer(DirectBuffer buffer, int offset, int length, ReservedValueSupplier reservedValueSupplier) Non-blocking publish of a partial buffer containing a message.longoffer(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.longofferBlock(MutableDirectBuffer buffer, int offset, int length) Offer a block of pre-formatted message fragments directly into the current term.longposition()Get the current position to which the publication has advanced for this stream.voidrevoke()Immediately revoke andPublication.close()the publication.voidMark the publication to be revoked whenPublication.close()is called.inttermId()The current term-id of the publication.intThe current term-offset of the publication.longtryClaim(int length, BufferClaim bufferClaim) Try to claim a range in the publication log into which a message can be written with zero copy semantics.Methods inherited from class io.aeron.Publication
addDestination, asyncAddDestination, asyncRemoveDestination, asyncRemoveDestination, channel, channelStatus, channelStatusId, close, errorString, initialTermId, isClosed, isConnected, isOriginal, localSocketAddresses, maxMessageLength, maxPayloadLength, maxPossiblePosition, offer, offer, offer, offer, originalRegistrationId, positionBitsToShift, positionLimit, positionLimitId, registrationId, removeDestination, removeDestination, sessionId, streamId, termBufferLength, toString
-
Method Details
-
revokeOnClose
public void revokeOnClose()Mark the publication to be revoked whenPublication.close()is called. Seerevoke() -
revoke
public void revoke()Immediately revoke andPublication.close()the publication. Revoking disposes of resources as soon as possible. On the publication side the log buffer won't linger, while on the subscription side the image will go unavailable without requiring all data to be drained. Hence, it should be used only when it's known that all subscribers have received all the data, or if it doesn't matter if they have. -
position
public long position()Get the current position to which the publication has advanced for this stream.- Overrides:
positionin classPublication- Returns:
- the current position to which the publication has advanced for this stream or
Publication.CLOSED.
-
availableWindow
public long availableWindow()Available window for offering into a publication before thePublication.positionLimit()is reached.- Specified by:
availableWindowin classPublication- Returns:
- window for offering into a publication before the
Publication.positionLimit()is reached. If the publication is closed thenPublication.CLOSEDwill be returned.
-
termId
public int termId()The current term-id of the publication.- Returns:
- the current term-id of the publication.
-
termOffset
public int termOffset()The current term-offset of the publication.- Returns:
- the current term-offset of the publication.
-
offer
public long offer(DirectBuffer buffer, int offset, int length, ReservedValueSupplier reservedValueSupplier) Non-blocking publish of a partial buffer containing a message.- Specified by:
offerin classPublication- Parameters:
buffer- containing message.offset- offset in the buffer at which the encoded message begins.length- in bytes of the encoded message.reservedValueSupplier-ReservedValueSupplierfor the frame.- Returns:
- The new stream position, otherwise a negative error value of
Publication.NOT_CONNECTED,Publication.BACK_PRESSURED,Publication.ADMIN_ACTION,Publication.CLOSED, orPublication.MAX_POSITION_EXCEEDED.
-
offer
public 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. a header and encapsulated payload.- Specified by:
offerin classPublication- Parameters:
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-ReservedValueSupplierfor the frame.- Returns:
- The new stream position, otherwise a negative error value of
Publication.NOT_CONNECTED,Publication.BACK_PRESSURED,Publication.ADMIN_ACTION,Publication.CLOSED, orPublication.MAX_POSITION_EXCEEDED.
-
offer
Non-blocking publish by gathering buffer vectors into a message.- Specified by:
offerin classPublication- Parameters:
vectors- which make up the message.reservedValueSupplier-ReservedValueSupplierfor the frame.- Returns:
- The new stream position, otherwise a negative error value of
Publication.NOT_CONNECTED,Publication.BACK_PRESSURED,Publication.ADMIN_ACTION,Publication.CLOSED, orPublication.MAX_POSITION_EXCEEDED.
-
tryClaim
Try to claim a range in the publication log into which a message can be written with zero copy semantics. Once the message has been written thenBufferClaim.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(); } }- Specified by:
tryClaimin classPublication- Parameters:
length- of the range to claim, in bytes.bufferClaim- to be populated if the claim succeeds.- Returns:
- The new stream position, otherwise a negative error value of
Publication.NOT_CONNECTED,Publication.BACK_PRESSURED,Publication.ADMIN_ACTION,Publication.CLOSED, orPublication.MAX_POSITION_EXCEEDED. - Throws:
IllegalArgumentException- if the length is greater thanPublication.maxPayloadLength()within an MTU.- See Also:
-
appendPadding
public long appendPadding(int length) Append a padding record to log of a given length to make up the log to a position.- Parameters:
length- of the range to claim, in bytes.- Returns:
- The new stream position, otherwise a negative error value of
Publication.NOT_CONNECTED,Publication.BACK_PRESSURED,Publication.ADMIN_ACTION,Publication.CLOSED, orPublication.MAX_POSITION_EXCEEDED. - Throws:
IllegalArgumentException- if the length is greater thanframed.
-
offerBlock
Offer a block of pre-formatted message fragments directly into the current term.- Parameters:
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.- Returns:
- The new stream position, otherwise a negative error value of
Publication.NOT_CONNECTED,Publication.BACK_PRESSURED,Publication.ADMIN_ACTION,Publication.CLOSED, orPublication.MAX_POSITION_EXCEEDED. - Throws:
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 thestreamIdis not equal to the value returned by thePublication.streamId()method or if thesessionIdis not equal to the value returned by thePublication.sessionId()method or if the frame type is not equal to theHeaderFlyweight.HDR_TYPE_DATA.
-