public class Publication
extends java.lang.Object
implements java.lang.AutoCloseable
Publications
are created via the Aeron.addPublication(String, int) method, and messages are sent via one of the
offer(DirectBuffer) methods, or a tryClaim(int, BufferClaim) and BufferClaim.commit()
method combination.
The APIs used try claim and offer are non-blocking.
Note: Publication instances are threadsafe and can be shared between publishing threads.Aeron.addPublication(String, int),
BufferClaim| Modifier and Type | Field and Description |
|---|---|
static long |
ADMIN_ACTION
The offer failed due to an administration action and should be retried.
|
static long |
BACK_PRESSURED
The offer failed due to back pressure from the subscribers preventing further transmission.
|
static long |
CLOSED
The
Publication has been closed and should no longer be used. |
static long |
NOT_CONNECTED
The publication is not yet connected to a subscriber.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addDestination(java.lang.String endpointChannel)
Add a destination manually to a multi-destination-cast Publication.
|
java.lang.String |
channel()
Media address for delivery to the channel.
|
void |
close()
Release resources used by this Publication when there are no more references.
|
int |
initialTermId()
The initial term id assigned when this
Publication was created. |
boolean |
isClosed()
Has this object been closed and should no longer be used?
|
boolean |
isConnected()
Has the
Publication seen an active Subscriber recently? |
int |
maxMessageLength()
Maximum message length supported in bytes.
|
int |
maxPayloadLength()
Maximum length of a message payload that fits within a message fragment.
|
long |
offer(org.agrona.DirectBuffer buffer)
Non-blocking publish of a buffer containing a message.
|
long |
offer(org.agrona.DirectBuffer buffer,
int offset,
int length)
Non-blocking publish of a partial buffer containing a message.
|
long |
offer(org.agrona.DirectBuffer buffer,
int offset,
int length,
ReservedValueSupplier reservedValueSupplier)
Non-blocking publish of a partial buffer containing a message.
|
long |
position()
Get the current position to which the publication has advanced for this stream.
|
long |
positionLimit()
Get the position limit beyond which this
Publication will be back pressured. |
long |
registrationId()
Return the registration id used to register this Publication with the media driver.
|
void |
removeDestination(java.lang.String endpointChannel)
Remove a previously added destination manually from a multi-destination-cast Publication.
|
int |
sessionId()
Session under which messages are published.
|
int |
streamId()
Stream identity for scoping within the channel media address.
|
int |
termBufferLength()
Get the length in bytes for each term partition in the log buffer.
|
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.
|
public static final long NOT_CONNECTED
public static final long BACK_PRESSURED
public static final long ADMIN_ACTION
public static final long CLOSED
Publication has been closed and should no longer be used.public int termBufferLength()
public java.lang.String channel()
public int streamId()
public int sessionId()
public int initialTermId()
Publication was created. This can be used to determine how many
terms have passed since creation.public int maxMessageLength()
public int maxPayloadLength()
public long registrationId()
public boolean isConnected()
Publication seen an active Subscriber recently?Publication has seen an active subscriber otherwise false.public void close()
close in interface java.lang.AutoCloseablepublic boolean isClosed()
public long position()
java.lang.IllegalStateException - if the publication is closed.public long positionLimit()
Publication will be back pressured.
This should only be used as a guide to determine when back pressure is likely to be applied.Publication will be back pressured.public long offer(org.agrona.DirectBuffer buffer)
buffer - containing message.NOT_CONNECTED, BACK_PRESSURED,
ADMIN_ACTION, or CLOSED.public long offer(org.agrona.DirectBuffer buffer,
int offset,
int length)
buffer - containing message.offset - offset in the buffer at which the encoded message begins.length - in bytes of the encoded message.NOT_CONNECTED,
BACK_PRESSURED, ADMIN_ACTION, or CLOSED.public long offer(org.agrona.DirectBuffer buffer,
int offset,
int length,
ReservedValueSupplier reservedValueSupplier)
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.NOT_CONNECTED,
BACK_PRESSURED, ADMIN_ACTION, or CLOSED.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.
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();
}
}
length - of the range to claim, in bytes..bufferClaim - to be populated if the claim succeeds.NOT_CONNECTED, BACK_PRESSURED,
ADMIN_ACTION, or CLOSED.java.lang.IllegalArgumentException - if the length is greater than maxPayloadLength() within an MTU.BufferClaim.commit(),
BufferClaim.abort()public void addDestination(java.lang.String endpointChannel)
endpointChannel - for the destination to addpublic void removeDestination(java.lang.String endpointChannel)
endpointChannel - for the destination to removeCopyright © 2014-2017 Real Logic Ltd. All Rights Reserved.