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:
  • 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 instance
      fileBackedStream - the FileBackedOutputStream containing the serialized data to slice
      messageSliceSize - the maximum size (in bytes) for a message slice
      maxRetries - the maximum number of retries
      replyTarget - the user-defined target for sliced message replies
      onFailureCallback - the callback to notify on failure
      logContext - 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

      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 interface AutoCloseable