Class AssembledMessageState
- java.lang.Object
-
- org.opendaylight.controller.cluster.messaging.AssembledMessageState
-
- All Implemented Interfaces:
AutoCloseable
public class AssembledMessageState extends Object implements AutoCloseable
Maintains the state of an assembled message. This class is NOT thread-safe.- Author:
- Thomas Pantelis
-
-
Constructor Summary
Constructors Constructor Description AssembledMessageState(Identifier identifier, int totalSlices, FileBackedOutputStreamFactory fileBackedStreamFactory, String logContext)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addSlice(int sliceIndex, byte[] data, int lastSliceHashCode)
Adds a slice to the assembled stream.void
close()
ByteSource
getAssembledBytes()
Returns the assembled bytes as a ByteSource.Identifier
getIdentifier()
Returns the identifier of this instance.
-
-
-
Constructor Detail
-
AssembledMessageState
public AssembledMessageState(Identifier identifier, int totalSlices, FileBackedOutputStreamFactory fileBackedStreamFactory, String logContext)
Constructor.- Parameters:
identifier
- the identifier for this instancetotalSlices
- the total number of slices to expectfileBackedStreamFactory
- factory for creating the FileBackedOutputStream instance used for streaminglogContext
- the context for log messages
-
-
Method Detail
-
getIdentifier
public Identifier getIdentifier()
Returns the identifier of this instance.- Returns:
- the identifier
-
addSlice
public boolean addSlice(int sliceIndex, byte[] data, int lastSliceHashCode) throws MessageSliceException
Adds a slice to the assembled stream.- Parameters:
sliceIndex
- the index of the slicedata
- the sliced datalastSliceHashCode
- the hash code of the last slice sent- Returns:
- true if this is the last slice received, false otherwise
- Throws:
MessageSliceException
-- if the slice index is invalid
- if the last slice hash code is invalid
- if an error occurs writing the data to the stream
AssemblerSealedException
- if this instance is already sealed (ie has received all the slices)AssemblerClosedException
- if this instance is already closed
-
getAssembledBytes
public ByteSource getAssembledBytes() throws IOException
Returns the assembled bytes as a ByteSource. This method must only be called after this instance is sealed.- Returns:
- a ByteSource containing the assembled bytes
- Throws:
IOException
- if an error occurs obtaining the assembled bytesIllegalStateException
- is this instance is not sealed
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
-