public class Image
extends java.lang.Object
Image
from a publisher to a Subscription
.
Each Image
identifies a source publisher by session id.
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 Image
for new messages.
Note:Images are not threadsafe and should not be shared between subscribers.
Constructor and Description |
---|
Image(Subscription subscription,
int sessionId,
org.agrona.concurrent.status.Position subscriberPosition,
LogBuffers logBuffers,
org.agrona.ErrorHandler errorHandler,
java.lang.String sourceIdentity,
long correlationId)
Construct a new image over a log to represent a stream of messages from a
Publication . |
Modifier and Type | Method and Description |
---|---|
int |
blockPoll(BlockHandler handler,
int blockLengthLimit)
Poll for new messages in a stream.
|
int |
boundedControlledPoll(ControlledFragmentHandler handler,
long maxPosition,
int fragmentLimit)
Poll for new messages in a stream.
|
long |
controlledPeek(long initialPosition,
ControlledFragmentHandler handler,
long limitPosition)
Peek for new messages in a stream by scanning forward from an initial position.
|
int |
controlledPoll(ControlledFragmentHandler handler,
int fragmentLimit)
Poll for new messages in a stream.
|
long |
correlationId()
The correlationId for identification of the image with the media driver.
|
java.nio.channels.FileChannel |
fileChannel()
The
FileChannel to the raw log of the Image. |
int |
initialTermId()
The initial term at which the stream started for this session.
|
boolean |
isClosed()
Has this object been closed and should no longer be used?
|
boolean |
isEndOfStream()
Is the current consumed position at the end of the stream?
|
long |
joinPosition()
Get the position the subscriber joined this stream at.
|
int |
mtuLength()
The length in bytes of the MTU (Maximum Transmission Unit) the Sender used for the datagram.
|
int |
poll(FragmentHandler fragmentHandler,
int fragmentLimit)
Poll for new messages in a stream.
|
long |
position()
The position this
Image has been consumed to by the subscriber. |
void |
position(long newPosition)
Set the subscriber position for this
Image to indicate where it has been consumed to. |
int |
positionBitsToShift()
Number of bits to right shift a position to get a term count for how far the stream has progressed.
|
int |
rawPoll(RawBlockHandler handler,
int blockLengthLimit)
Poll for new messages in a stream.
|
int |
sessionId()
The sessionId for the steam of messages.
|
java.lang.String |
sourceIdentity()
The source identity of the sending publisher as an abstract concept appropriate for the media.
|
int |
subscriberPositionId()
The counter id for the subscriber position counter.
|
Subscription |
subscription()
Get the
Subscription to which this Image belongs. |
int |
termBufferLength()
Get the length in bytes for each term partition in the log buffer.
|
java.lang.String |
toString() |
public Image(Subscription subscription, int sessionId, org.agrona.concurrent.status.Position subscriberPosition, LogBuffers logBuffers, org.agrona.ErrorHandler errorHandler, java.lang.String sourceIdentity, long correlationId)
Publication
.subscription
- to which this Image
belongs.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.public int positionBitsToShift()
public int termBufferLength()
public int sessionId()
Subscription
and unique across
all Publication
s from a sourceIdentity()
.public java.lang.String sourceIdentity()
public int mtuLength()
public int initialTermId()
public long correlationId()
public Subscription subscription()
Subscription
to which this Image
belongs.Subscription
to which this Image
belongs.public boolean isClosed()
public long joinPosition()
public long position()
Image
has been consumed to by the subscriber.Image
has been consumed to by the subscriber.public void position(long newPosition)
Image
to indicate where it has been consumed to.newPosition
- for the consumption point.public int subscriberPositionId()
public boolean isEndOfStream()
public java.nio.channels.FileChannel fileChannel()
FileChannel
to the raw log of the Image.FileChannel
to the raw log of the Image.public int poll(FragmentHandler fragmentHandler, int fragmentLimit)
FragmentHandler
up to a limited number of fragments as specified.
Use a FragmentAssembler
to assemble messages which span multiple fragments.
fragmentHandler
- to which message fragments are delivered.fragmentLimit
- for the number of fragments to be consumed during one polling operation.FragmentAssembler
,
ImageFragmentAssembler
public int controlledPoll(ControlledFragmentHandler handler, int fragmentLimit)
ControlledFragmentHandler
up to a limited number of fragments as specified.
Use a ControlledFragmentAssembler
to assemble messages which span multiple fragments.
handler
- to which message fragments are delivered.fragmentLimit
- for the number of fragments to be consumed during one polling operation.ControlledFragmentAssembler
,
ImageControlledFragmentAssembler
public int boundedControlledPoll(ControlledFragmentHandler handler, long maxPosition, int fragmentLimit)
ControlledFragmentHandler
up to a limited number of fragments as specified or
the maximum position specified.
Use a ControlledFragmentAssembler
to assemble messages which span multiple fragments.
handler
- to which message fragments are delivered.maxPosition
- to consume messages up to.fragmentLimit
- for the number of fragments to be consumed during one polling operation.ControlledFragmentAssembler
,
ImageControlledFragmentAssembler
public long controlledPeek(long initialPosition, ControlledFragmentHandler handler, long limitPosition)
ControlledFragmentHandler
up to a limited position.
Use a ControlledFragmentAssembler
to assemble messages which span multiple fragments. Scans must also
start at the beginning of a message so that the assembler is reset.
initialPosition
- from which to peek forward.handler
- to which message fragments are delivered.limitPosition
- up to which can be scanned.ControlledFragmentAssembler
,
ImageControlledFragmentAssembler
public int blockPoll(BlockHandler handler, int blockLengthLimit)
BlockHandler
up 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
.
handler
- to which block is delivered.blockLengthLimit
- up to which a block may be in length.public int rawPoll(RawBlockHandler handler, int blockLengthLimit)
RawBlockHandler
up 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
.
handler
- to which block is delivered.blockLengthLimit
- up to which a block may be in length.public java.lang.String toString()
toString
in class java.lang.Object
Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.