Class AssembledMessageState
java.lang.Object
org.opendaylight.controller.cluster.messaging.AssembledMessageState
- All Implemented Interfaces:
AutoCloseable
Maintains the state of an assembled message. This class is NOT thread-safe.
- Author:
- Thomas Pantelis
-
Constructor Summary
ConstructorsConstructorDescriptionAssembledMessageState
(Identifier identifier, int totalSlices, FileBackedOutputStreamFactory fileBackedStreamFactory, String logContext) Constructor. -
Method Summary
-
Constructor Details
-
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 Details
-
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
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
-