Class Image
Publication from a which matches a Subscription.
Each Image identifies a source Publication by sessionId().
By default, fragmented messages are not reassembled before delivery. If an application must
receive whole messages, whether they were fragmented or not, 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 Image for new messages.
Note:Images are not threadsafe and should not be shared between subscribers.
-
Constructor Summary
ConstructorsConstructorDescriptionImage(Subscription subscription, int sessionId, Position subscriberPosition, LogBuffers logBuffers, ErrorHandler errorHandler, String sourceIdentity, long correlationId) Construct a new image over a log to represent a stream of messages from aPublication. -
Method Summary
Modifier and TypeMethodDescriptionintCount of observed active transports within the image liveness timeout.intblockPoll(BlockHandler handler, int blockLengthLimit) Poll for new messages in a stream.intboundedControlledPoll(ControlledFragmentHandler handler, long limitPosition, int fragmentLimit) Poll for new messages in a stream.intboundedPoll(FragmentHandler handler, long limitPosition, int fragmentLimit) Poll for new messages in a stream.longcontrolledPeek(long initialPosition, ControlledFragmentHandler handler, long limitPosition) Peek for new messages in a stream by scanning forward from an initial position.intcontrolledPoll(ControlledFragmentHandler handler, int fragmentLimit) Poll for new messages in a stream.longThe correlationId for identification of the image with the media driver.longThe position the stream reached when EOS was received from the publisher.TheFileChannelto the raw log of the Image.intThe initial term at which the stream started for this session.booleanisClosed()Has this object been closed and should no longer be used?booleanIs the current consumed position at the end of the stream?booleanHas the associated publication been revoked?longGet the position the subscriber joined this stream at.intThe length in bytes of the MTU (Maximum Transmission Unit) the Sender used for the datagram.intpoll(FragmentHandler fragmentHandler, int fragmentLimit) Poll for new messages in a stream.longposition()The position thisImagehas been consumed to by the subscriber.voidposition(long newPosition) Set the subscriber position for thisImageto indicate where it has been consumed to.intNumber of bits to right shift a position to get a term count for how far the stream has progressed.intrawPoll(RawBlockHandler handler, int blockLengthLimit) Poll for new messages in a stream.voidReject this image.intThe sessionId for the steam of messages.The source identity of the sending publisher as an abstract concept appropriate for the media.intThe counter id for the subscriber position counter.Get theSubscriptionto which thisImagebelongs.intGet the length in bytes for each term partition in the log buffer.toString()
-
Constructor Details
-
Image
public Image(Subscription subscription, int sessionId, Position subscriberPosition, LogBuffers logBuffers, ErrorHandler errorHandler, String sourceIdentity, long correlationId) Construct a new image over a log to represent a stream of messages from aPublication.- Parameters:
subscription- to which thisImagebelongs.sessionId- of the stream of messages.subscriberPosition- for indicating the position of the subscriber in the stream.logBuffers- containing the stream of messages.errorHandler- to be called if an error occurs when polling for messages.sourceIdentity- of the source sending the stream of messages.correlationId- of the request to the media driver.
-
-
Method Details
-
positionBitsToShift
public int positionBitsToShift()Number of bits to right shift a position to get a term count for how far the stream has progressed.- Returns:
- of bits to right shift a position to get a term count for how far the stream has progressed.
-
termBufferLength
public int termBufferLength()Get the length in bytes for each term partition in the log buffer.- Returns:
- the length in bytes for each term partition in the log buffer.
-
sessionId
public int sessionId()The sessionId for the steam of messages. Sessions are unique within aSubscriptionand unique across allPublications from asourceIdentity().- Returns:
- the sessionId for the steam of messages.
-
sourceIdentity
The source identity of the sending publisher as an abstract concept appropriate for the media.- Returns:
- source identity of the sending publisher as an abstract concept appropriate for the media.
-
mtuLength
public int mtuLength()The length in bytes of the MTU (Maximum Transmission Unit) the Sender used for the datagram.- Returns:
- length in bytes of the MTU (Maximum Transmission Unit) the Sender used for the datagram.
-
initialTermId
public int initialTermId()The initial term at which the stream started for this session.- Returns:
- the initial term id.
-
correlationId
public long correlationId()The correlationId for identification of the image with the media driver.- Returns:
- the correlationId for identification of the image with the media driver.
-
subscription
Get theSubscriptionto which thisImagebelongs.- Returns:
- the
Subscriptionto which thisImagebelongs.
-
isClosed
public boolean isClosed()Has this object been closed and should no longer be used?- Returns:
- true if it has been closed otherwise false.
-
joinPosition
public long joinPosition()Get the position the subscriber joined this stream at.- Returns:
- the position the subscriber joined this stream at.
-
position
public long position()The position thisImagehas been consumed to by the subscriber.- Returns:
- the position this
Imagehas been consumed to by the subscriber.
-
position
public void position(long newPosition) Set the subscriber position for thisImageto indicate where it has been consumed to.- Parameters:
newPosition- for the consumption point.
-
subscriberPositionId
public int subscriberPositionId()The counter id for the subscriber position counter.- Returns:
- the id for the subscriber position counter.
-
isEndOfStream
public boolean isEndOfStream()Is the current consumed position at the end of the stream?- Returns:
- true if at the end of the stream or false if not.
-
endOfStreamPosition
public long endOfStreamPosition()The position the stream reached when EOS was received from the publisher. The position will beLong.MAX_VALUEuntil the stream ends and EOS is set.- Returns:
- position the stream reached when EOS was received from the publisher.
-
activeTransportCount
public int activeTransportCount()Count of observed active transports within the image liveness timeout.If the image is closed, then this is 0. This may also be 0 if no actual datagrams have arrived. IPC Images also will be 0.
- Returns:
- count of active transports - 0 if Image is closed, no datagrams yet, or IPC.
-
isPublicationRevoked
public boolean isPublicationRevoked()Has the associated publication been revoked?- Returns:
- true if the associated publication was revoked otherwise false.
-
fileChannel
TheFileChannelto the raw log of the Image.- Returns:
- the
FileChannelto the raw log of the Image.
-
poll
Poll for new messages in a stream. If new messages are found beyond the last consumed position then they will be delivered to theFragmentHandlerup to a limited number of fragments as specified.Use a
FragmentAssemblerto assemble messages which span multiple fragments.- Parameters:
fragmentHandler- to which message fragments are delivered.fragmentLimit- for the number of fragments to be consumed during one polling operation.- Returns:
- the number of fragments that have been consumed.
- See Also:
-
controlledPoll
Poll for new messages in a stream. If new messages are found beyond the last consumed position then they will be delivered to theControlledFragmentHandlerup to a limited number of fragments as specified.Use a
ControlledFragmentAssemblerto assemble messages which span multiple fragments.- Parameters:
handler- to which message fragments are delivered.fragmentLimit- for the number of fragments to be consumed during one polling operation.- Returns:
- the number of fragments that have been consumed.
- See Also:
-
boundedPoll
Poll for new messages in a stream. If new messages are found beyond the last consumed position then they will be delivered to theFragmentHandlerup to a limited number of fragments as specified or the maximum position specified.Use a
FragmentAssemblerto assemble messages which span multiple fragments.- Parameters:
handler- to which message fragments are delivered.limitPosition- to consume messages up to.fragmentLimit- for the number of fragments to be consumed during one polling operation.- Returns:
- the number of fragments that have been consumed.
- See Also:
-
boundedControlledPoll
public int boundedControlledPoll(ControlledFragmentHandler handler, long limitPosition, int fragmentLimit) Poll for new messages in a stream. If new messages are found beyond the last consumed position then they will be delivered to theControlledFragmentHandlerup to a limited number of fragments as specified or the maximum position specified.Use a
ControlledFragmentAssemblerto assemble messages which span multiple fragments.- Parameters:
handler- to which message fragments are delivered.limitPosition- to consume messages up to.fragmentLimit- for the number of fragments to be consumed during one polling operation.- Returns:
- the number of fragments that have been consumed.
- See Also:
-
controlledPeek
public long controlledPeek(long initialPosition, ControlledFragmentHandler handler, long limitPosition) Peek for new messages in a stream by scanning forward from an initial position. If new messages are found then they will be delivered to theControlledFragmentHandlerup to a limited position.Use a
ControlledFragmentAssemblerto assemble messages which span multiple fragments. Scans must also start at the beginning of a message so that the assembler is reset.- Parameters:
initialPosition- from which to peek forward.handler- to which message fragments are delivered.limitPosition- up to which can be scanned.- Returns:
- the resulting position after the scan terminates which is a complete message.
- See Also:
-
blockPoll
Poll for new messages in a stream. If new messages are found beyond the last consumed position then they will be delivered to theBlockHandlerup to a limited number of bytes.A scan will terminate if a padding frame is encountered. If first frame in a scan is padding then a block for the padding is notified. If the padding comes after the first frame in a scan then the scan terminates at the offset the padding frame begins. Padding frames are delivered singularly in a block.
Padding frames may be for a greater range than the limit offset but only the header needs to be valid so relevant length of the frame is
DataHeaderFlyweight.HEADER_LENGTH.- Parameters:
handler- to which block is delivered.blockLengthLimit- up to which a block may be in length.- Returns:
- the number of bytes that have been consumed.
-
rawPoll
Poll for new messages in a stream. If new messages are found beyond the last consumed position then they will be delivered to theRawBlockHandlerup to a limited number of bytes.This method is useful for operations like bulk archiving a stream to file.
A scan will terminate if a padding frame is encountered. If first frame in a scan is padding then a block for the padding is notified. If the padding comes after the first frame in a scan then the scan terminates at the offset the padding frame begins. Padding frames are delivered singularly in a block.
Padding frames may be for a greater range than the limit offset but only the header needs to be valid so relevant length of the frame is
DataHeaderFlyweight.HEADER_LENGTH.- Parameters:
handler- to which block is delivered.blockLengthLimit- up to which a block may be in length.- Returns:
- the number of bytes that have been consumed.
-
reject
Reject this image.- Parameters:
reason- a String indicating the reason why this image is being rejected.
-
toString
-