Class SlicedMessageState<T>
- java.lang.Object
-
- org.opendaylight.controller.cluster.messaging.SlicedMessageState<T>
-
- All Implemented Interfaces:
AutoCloseable
public class SlicedMessageState<T> extends Object implements AutoCloseable
Maintains the state of a sliced message. This class is NOT thread-safe.- Author:
- Thomas Pantelis
- See Also:
MessageSlicer
-
-
Constructor Summary
Constructors Constructor Description SlicedMessageState(Identifier identifier, FileBackedOutputStream fileBackedStream, int messageSliceSize, int maxRetries, T replyTarget, Consumer<Throwable> onFailureCallback, String logContext)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canRetry()
Determines if the slicing can be retried.void
close()
int
getCurrentSliceIndex()
Returns the current slice index that has been sent.Identifier
getIdentifier()
Returns the identifier of this instance.int
getLastSliceHashCode()
Returns the hash code of the last slice that was sent.byte[]
getNextSlice()
Reads and returns the next slice of data.Consumer<Throwable>
getOnFailureCallback()
Returns the callback to notify on failure.T
getReplyTarget()
Returns the user-defined target for sliced message replies.int
getTotalSlices()
Returns the total number of slices to send.boolean
isLastSlice(int index)
Determines if the given index is the last slice to send.void
reset()
Resets this instance to restart slicing from the beginning.
-
-
-
Constructor Detail
-
SlicedMessageState
public SlicedMessageState(Identifier identifier, FileBackedOutputStream fileBackedStream, int messageSliceSize, int maxRetries, T replyTarget, Consumer<Throwable> onFailureCallback, String logContext) throws IOException
Constructor.- Parameters:
identifier
- the identifier for this instancefileBackedStream
- the FileBackedOutputStream containing the serialized data to slicemessageSliceSize
- the maximum size (in bytes) for a message slicemaxRetries
- the maximum number of retriesreplyTarget
- the user-defined target for sliced message repliesonFailureCallback
- the callback to notify on failurelogContext
- the context for log messages- Throws:
IOException
- if an error occurs opening the input stream
-
-
Method Detail
-
getCurrentSliceIndex
public int getCurrentSliceIndex()
Returns the current slice index that has been sent.- Returns:
- the current slice index that has been sent
-
getLastSliceHashCode
public int getLastSliceHashCode()
Returns the hash code of the last slice that was sent.- Returns:
- the hash code of the last slice that was sent
-
getTotalSlices
public int getTotalSlices()
Returns the total number of slices to send.- Returns:
- the total number of slices to send
-
getIdentifier
public Identifier getIdentifier()
Returns the identifier of this instance.- Returns:
- the identifier
-
getReplyTarget
public T getReplyTarget()
Returns the user-defined target for sliced message replies.- Returns:
- the user-defined target
-
getOnFailureCallback
public Consumer<Throwable> getOnFailureCallback()
Returns the callback to notify on failure.- Returns:
- the callback to notify on failure
-
canRetry
public boolean canRetry()
Determines if the slicing can be retried.- Returns:
- true if the slicing can be retried, false if the maximum number of retries has been reached
-
isLastSlice
public boolean isLastSlice(int index)
Determines if the given index is the last slice to send.- Parameters:
index
- the slice index to test- Returns:
- true if the index is the last slice, false otherwise
-
getNextSlice
public byte[] getNextSlice() throws IOException
Reads and returns the next slice of data.- Returns:
- the next slice of data as a byte[]
- Throws:
IOException
- if an error occurs reading the data
-
reset
public void reset() throws IOException
Resets this instance to restart slicing from the beginning.- Throws:
IOException
- if an error occurs resetting the input stream
-
close
public void close()
- Specified by:
close
in interfaceAutoCloseable
-
-