Class SlicedMessageState<T>
java.lang.Object
org.opendaylight.controller.cluster.messaging.SlicedMessageState<T>
- All Implemented Interfaces:
AutoCloseable
Maintains the state of a sliced message. This class is NOT thread-safe.
- Author:
- Thomas Pantelis
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionSlicedMessageState
(Identifier identifier, FileBackedOutputStream fileBackedStream, int messageSliceSize, int maxRetries, T replyTarget, Consumer<Throwable> onFailureCallback, String logContext) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionboolean
canRetry()
Determines if the slicing can be retried.void
close()
int
Returns the current slice index that has been sent.Returns the identifier of this instance.int
Returns the hash code of the last slice that was sent.byte[]
Reads and returns the next slice of data.Returns the callback to notify on failure.Returns the user-defined target for sliced message replies.int
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 Details
-
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 Details
-
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
Returns the identifier of this instance.- Returns:
- the identifier
-
getReplyTarget
Returns the user-defined target for sliced message replies.- Returns:
- the user-defined target
-
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
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
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
-