Package io.aeron
Class ConcurrentPublication
java.lang.Object
io.aeron.Publication
io.aeron.ConcurrentPublication
- All Implemented Interfaces:
AutoCloseable
Aeron publisher API for sending messages to subscribers of a given channel and streamId pair.
Publications
are created via the Aeron.addPublication(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.
The APIs for tryClaim and offer are non-blocking and thread safe.
Note: Instances are threadsafe and can be shared between publishing threads.
- See Also:
-
Field Summary
Fields inherited from class io.aeron.Publication
ADMIN_ACTION, BACK_PRESSURED, CLOSED, MAX_POSITION_EXCEEDED, NOT_CONNECTED -
Method Summary
Modifier and TypeMethodDescriptionlongAvailable 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.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, position, positionBitsToShift, positionLimit, positionLimitId, registrationId, removeDestination, removeDestination, sessionId, streamId, termBufferLength, toString
-
Method Details
-
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.
-
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 for more than the aeron.publication.unblock.timeout system property then the driver will assume the publication thread is dead and will unblock the claim thus allowing other threads to make progress or to reach end-of-stream (EOS).
final BufferClaim bufferClaim = new BufferClaim(); // Can be stored and reused to avoid allocation 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:
-