Package io.aeron
Class FragmentAssembler
java.lang.Object
io.aeron.FragmentAssembler
- All Implemented Interfaces:
FragmentHandler
A
FragmentHandler that sits in a chain-of-responsibility pattern that reassembles fragmented messages
so that the next handler in the chain only sees whole messages.
Unfragmented messages are delegated without copy. Fragmented messages are copied to a temporary buffer for reassembly before delegation.
The Header passed to the delegate on assembling a message will be that of the last fragment.
Session based buffers will be allocated and grown as necessary based on the length of messages to be assembled.
When sessions go inactive see UnavailableImageHandler, it is possible to free the buffer by calling
freeSessionBuffer(int).
-
Constructor Summary
ConstructorsConstructorDescriptionFragmentAssembler(FragmentHandler delegate) Construct an adapter to reassemble message fragments and delegate on whole messages.FragmentAssembler(FragmentHandler delegate, int initialBufferLength) Construct an adapter to reassemble message fragments and delegate on whole messages.FragmentAssembler(FragmentHandler delegate, int initialBufferLength, boolean isDirectByteBuffer) Construct an adapter to reassemble message fragments and delegate on whole messages. -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clear down the cache of buffers by session for reassembling messages.delegate()Get the delegate unto which assembled messages are delegated.booleanfreeSessionBuffer(int sessionId) Free an existing session buffer to reduce memory pressure when an image goes inactive or no more large messages are expected.booleanIs the underlying buffer used to assemble fragments a directByteBuffer?voidonFragment(DirectBuffer buffer, int offset, int length, Header header) The implementation ofFragmentHandlerthat reassembles and forwards whole messages.
-
Constructor Details
-
FragmentAssembler
Construct an adapter to reassemble message fragments and delegate on whole messages.- Parameters:
delegate- onto which whole messages are forwarded.
-
FragmentAssembler
Construct an adapter to reassemble message fragments and delegate on whole messages.- Parameters:
delegate- onto which whole messages are forwarded.initialBufferLength- to be used for each session.
-
FragmentAssembler
public FragmentAssembler(FragmentHandler delegate, int initialBufferLength, boolean isDirectByteBuffer) Construct an adapter to reassemble message fragments and delegate on whole messages.- Parameters:
delegate- onto which whole messages are forwarded.initialBufferLength- to be used for each session.isDirectByteBuffer- is the underlying buffer to be a directByteBuffer?
-
-
Method Details
-
delegate
Get the delegate unto which assembled messages are delegated.- Returns:
- the delegate unto which assembled messages are delegated.
-
isDirectByteBuffer
public boolean isDirectByteBuffer()Is the underlying buffer used to assemble fragments a directByteBuffer?- Returns:
- true if the underlying buffer used to assemble fragments is a direct
ByteBuffer
-
onFragment
The implementation ofFragmentHandlerthat reassembles and forwards whole messages.- Specified by:
onFragmentin interfaceFragmentHandler- Parameters:
buffer- containing the data.offset- at which the data begins.length- of the data in bytes.header- representing the metadata for the data.
-
freeSessionBuffer
public boolean freeSessionBuffer(int sessionId) Free an existing session buffer to reduce memory pressure when an image goes inactive or no more large messages are expected.- Parameters:
sessionId- to have its buffer freed- Returns:
- true if a buffer has been freed otherwise false.
-
clear
public void clear()Clear down the cache of buffers by session for reassembling messages.
-