public class Subscription
extends java.lang.Object
implements java.lang.AutoCloseable
Image
for a stream of messages from publishers on
a given channel and streamId pair. Image
s are aggregated under a Subscription
.
Subscription
s are created via an Aeron
object, and received messages are delivered
to the FragmentHandler
.
By default fragmented messages are not reassembled before delivery. If an application must
receive whole messages, whether or not they were fragmented, then the Subscriber
should be created with a FragmentAssembler
or a custom implementation.
It is an application's responsibility to poll(io.aeron.logbuffer.FragmentHandler, int)
the Subscription
for new messages.
Note:Subscriptions are not threadsafe and should not be shared between subscribers.
Modifier and Type | Field and Description |
---|---|
protected AvailableImageHandler |
availableImageHandler |
protected java.lang.String |
channel |
protected int |
channelStatusId |
protected io.aeron.ClientConductor |
conductor |
protected static Image[] |
EMPTY_ARRAY |
protected Image[] |
images |
protected boolean |
isClosed |
protected long |
p1 |
protected long |
p10 |
protected long |
p11 |
protected long |
p12 |
protected long |
p13 |
protected long |
p14 |
protected long |
p15 |
protected long |
p16 |
protected long |
p17 |
protected long |
p18 |
protected long |
p19 |
protected long |
p2 |
protected long |
p20 |
protected long |
p21 |
protected long |
p22 |
protected long |
p23 |
protected long |
p24 |
protected long |
p25 |
protected long |
p26 |
protected long |
p27 |
protected long |
p28 |
protected long |
p29 |
protected long |
p3 |
protected long |
p30 |
protected long |
p4 |
protected long |
p5 |
protected long |
p6 |
protected long |
p7 |
protected long |
p8 |
protected long |
p9 |
protected long |
registrationId |
protected int |
roundRobinIndex |
protected int |
streamId |
protected UnavailableImageHandler |
unavailableImageHandler |
Modifier and Type | Method and Description |
---|---|
void |
addDestination(java.lang.String endpointChannel)
Add a destination manually to a multi-destination Subscription.
|
AvailableImageHandler |
availableImageHandler()
Callback used to indicate when an
Image becomes available under this Subscription . |
long |
blockPoll(BlockHandler blockHandler,
int blockLengthLimit)
Poll the
Image s under the subscription for available message fragments in blocks. |
java.lang.String |
channel()
Media address for delivery to the channel.
|
long |
channelStatus()
Get the status of the media channel for this Subscription.
|
void |
close()
Close the Subscription so that associated
Image s can be released. |
int |
controlledPoll(ControlledFragmentHandler fragmentHandler,
int fragmentLimit)
Poll in a controlled manner the
Image s under the subscription for available message fragments. |
void |
forEachImage(java.util.function.Consumer<Image> consumer)
Iterate over the
Image s for this subscription. |
boolean |
hasNoImages()
Has this subscription currently no
Image s? |
Image |
imageAtIndex(int index)
Get the
Image at the given index from the images array. |
Image |
imageBySessionId(int sessionId)
Return the
Image associated with the given sessionId. |
int |
imageCount()
Count of
Image s associated to this subscription. |
java.util.List<Image> |
images()
Get a
List of active Image s that match this subscription. |
boolean |
isClosed()
Has this object been closed and should no longer be used?
|
boolean |
isConnected()
Is this subscription connected by having at least one open publication
Image . |
int |
poll(FragmentHandler fragmentHandler,
int fragmentLimit)
Poll the
Image s under the subscription for available message fragments. |
int |
pollEndOfStreams(EndOfStreamHandler endOfStreamHandler)
Deprecated.
|
long |
rawPoll(RawBlockHandler rawBlockHandler,
int blockLengthLimit)
Poll the
Image s under the subscription for available message fragments in blocks. |
long |
registrationId()
Return the registration id used to register this Subscription with the media driver.
|
void |
removeDestination(java.lang.String endpointChannel)
Remove a previously added destination from a multi-destination Subscription.
|
int |
streamId()
Stream identity for scoping within the channel media address.
|
java.lang.String |
toString() |
UnavailableImageHandler |
unavailableImageHandler()
Callback used to indicate when an
Image goes unavailable under this Subscription . |
protected long p16
protected long p17
protected long p18
protected long p19
protected long p20
protected long p21
protected long p22
protected long p23
protected long p24
protected long p25
protected long p26
protected long p27
protected long p28
protected long p29
protected long p30
protected static final Image[] EMPTY_ARRAY
protected final long registrationId
protected int roundRobinIndex
protected final int streamId
protected volatile boolean isClosed
protected volatile Image[] images
protected final io.aeron.ClientConductor conductor
protected final java.lang.String channel
protected final AvailableImageHandler availableImageHandler
protected final UnavailableImageHandler unavailableImageHandler
protected int channelStatusId
protected long p1
protected long p2
protected long p3
protected long p4
protected long p5
protected long p6
protected long p7
protected long p8
protected long p9
protected long p10
protected long p11
protected long p12
protected long p13
protected long p14
protected long p15
public java.lang.String channel()
public int streamId()
public long registrationId()
public AvailableImageHandler availableImageHandler()
Image
becomes available under this Subscription
.Image
becomes available under this Subscription
.public UnavailableImageHandler unavailableImageHandler()
Image
goes unavailable under this Subscription
.Image
goes unavailable under this Subscription
.@Deprecated public int pollEndOfStreams(EndOfStreamHandler endOfStreamHandler)
Image
s under the subscription for having reached End of Stream (EOS). This method will miss
Image
s that have gone unavailable between calls unless using the Aeron.conductorAgentInvoker()
.endOfStreamHandler
- callback for handling end of stream indication.Image
that have reached End of Stream.public int poll(FragmentHandler fragmentHandler, int fragmentLimit)
Image
s under the subscription for available message fragments.
Each fragment read will be a whole message if it is under MTU length. If larger than MTU then it will come as a series of fragments ordered within a session.
To assemble messages that span multiple fragments then use FragmentAssembler
.
fragmentHandler
- callback for handling each message fragment as it is read.fragmentLimit
- number of message fragments to limit for the poll operation across multiple Image
s.public int controlledPoll(ControlledFragmentHandler fragmentHandler, int fragmentLimit)
Image
s under the subscription for available message fragments.
Control is applied to fragments in the stream. If more fragments can be read on another stream
they will even if BREAK or ABORT is returned from the fragment handler.
Each fragment read will be a whole message if it is under MTU length. If larger than MTU then it will come as a series of fragments ordered within a session.
To assemble messages that span multiple fragments then use ControlledFragmentAssembler
.
fragmentHandler
- callback for handling each message fragment as it is read.fragmentLimit
- number of message fragments to limit for the poll operation across multiple Image
s.ControlledFragmentHandler
public long blockPoll(BlockHandler blockHandler, int blockLengthLimit)
Image
s under the subscription for available message fragments in blocks.
This method is useful for operations like bulk archiving and messaging indexing.
public long rawPoll(RawBlockHandler rawBlockHandler, int blockLengthLimit)
Image
s under the subscription for available message fragments in blocks.
This method is useful for operations like bulk archiving a stream to file.
public boolean isConnected()
Image
.Image
.public boolean hasNoImages()
Image
s?Image
s?public int imageCount()
Image
s associated to this subscription.Image
s associated to this subscription.public Image imageBySessionId(int sessionId)
Image
associated with the given sessionId.sessionId
- associated with the Image
.public Image imageAtIndex(int index)
Image
at the given index from the images array.index
- in the arrayjava.lang.ArrayIndexOutOfBoundsException
- if the index is not valid.public java.util.List<Image> images()
List
of active Image
s that match this subscription.List
of active Image
s that match this subscription.public void forEachImage(java.util.function.Consumer<Image> consumer)
Image
s for this subscription.consumer
- to handle each Image
.public void close()
Image
s can be released.
This method is idempotent.
close
in interface java.lang.AutoCloseable
public boolean isClosed()
public long channelStatus()
The status will be ChannelEndpointStatus.ERRORED
if a socket exception occurs on setup
and ChannelEndpointStatus.ACTIVE
if all is well.
ChannelEndpointStatus
with it being
ChannelEndpointStatus.NO_ID_ALLOCATED
if the subscription is closed.ChannelEndpointStatus
public void addDestination(java.lang.String endpointChannel)
endpointChannel
- for the destination to addpublic void removeDestination(java.lang.String endpointChannel)
endpointChannel
- for the destination to removepublic java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.