public class FragmentAssembler extends java.lang.Object implements FragmentHandler
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 and Description |
---|
FragmentAssembler(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.
|
Modifier and Type | Method and Description |
---|---|
void |
clear()
Clear down the cache of buffers by session for reassembling messages.
|
FragmentHandler |
delegate()
Get the delegate unto which assembled messages are delegated.
|
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.
|
boolean |
isDirectByteBuffer()
Is the underlying buffer used to assemble fragments a direct
ByteBuffer ? |
void |
onFragment(org.agrona.DirectBuffer buffer,
int offset,
int length,
Header header)
The implementation of
FragmentHandler that reassembles and forwards whole messages. |
public FragmentAssembler(FragmentHandler delegate)
delegate
- onto which whole messages are forwarded.public FragmentAssembler(FragmentHandler delegate, int initialBufferLength)
delegate
- onto which whole messages are forwarded.initialBufferLength
- to be used for each session.public FragmentAssembler(FragmentHandler delegate, int initialBufferLength, boolean isDirectByteBuffer)
delegate
- onto which whole messages are forwarded.initialBufferLength
- to be used for each session.isDirectByteBuffer
- is the underlying buffer to be a direct ByteBuffer
?public FragmentHandler delegate()
public boolean isDirectByteBuffer()
ByteBuffer
?ByteBuffer
public void onFragment(org.agrona.DirectBuffer buffer, int offset, int length, Header header)
FragmentHandler
that reassembles and forwards whole messages.onFragment
in interface FragmentHandler
buffer
- containing the data.offset
- at which the data begins.length
- of the data in bytes.header
- representing the meta data for the data.public boolean freeSessionBuffer(int sessionId)
sessionId
- to have its buffer freedpublic void clear()
Copyright © 2014-2018 Real Logic Ltd. All Rights Reserved.