public class ExclusivePublication
extends java.lang.Object
implements java.lang.AutoCloseable
ExclusivePublications are created via the Aeron.addExclusivePublication(String, int) method,
and messages are sent via one of the offer(DirectBuffer) methods, or a
tryClaim(int, ExclusiveBufferClaim) and ExclusiveBufferClaim.commit() method combination.
ExclusivePublications have the potential to provide greater throughput than Publications.
The APIs used try claim and offer are non-blocking.
Note: ExclusivePublication instances are NOT threadsafe for offer and try claim method but are for position.| 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
ExclusivePublication 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.
|
int |
initialTermId()
The initial term id assigned when this
ExclusivePublication was created. |
boolean |
isClosed()
Has this object been closed and should no longer be used?
|
boolean |
isConnected()
Has the
ExclusivePublication 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
ExclusivePublication 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,
ExclusiveBufferClaim 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
ExclusivePublication has been closed and should no longer be used.public int termBufferLength()
public java.lang.String channel()
public int streamId()
public int sessionId()
ExclusivePublication instance.public int initialTermId()
ExclusivePublication 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()
ExclusivePublication seen an active Subscriber recently?ExclusivePublication 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()
ExclusivePublication will be back pressured.
This should only be used as a guide to determine when back pressure is likely to be applied.ExclusivePublication 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,
ExclusiveBufferClaim bufferClaim)
ExclusiveBufferClaim.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 ExclusiveBufferClaim bufferClaim = new ExclusiveBufferClaim();
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.ExclusiveBufferClaim.commit(),
ExclusiveBufferClaim.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.