Class LearnerSnapshotThrottler


  • public class LearnerSnapshotThrottler
    extends java.lang.Object
    Utility class to limit the number of concurrent snapshots from a leader to observers and followers. LearnerHandler objects should call beginSnapshot(boolean) before sending a snapshot and endSnapshot() after finishing, successfully or not.
    • Constructor Summary

      Constructors 
      Constructor Description
      LearnerSnapshotThrottler​(int maxConcurrentSnapshots)  
      LearnerSnapshotThrottler​(int maxConcurrentSnapshots, long timeoutMillis)
      Constructs a new instance limiting the concurrent number of snapshots to maxConcurrentSnapshots.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      LearnerSnapshot beginSnapshot​(boolean essential)
      Indicates that a new snapshot is about to be sent.
      void endSnapshot()
      Indicates that a snapshot has been completed.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • LearnerSnapshotThrottler

        public LearnerSnapshotThrottler​(int maxConcurrentSnapshots,
                                        long timeoutMillis)
        Constructs a new instance limiting the concurrent number of snapshots to maxConcurrentSnapshots.
        Parameters:
        maxConcurrentSnapshots - maximum concurrent number of snapshots
        timeoutMillis - milliseconds to attempt to wait when attempting to begin a snapshot that would otherwise be throttled; a value of zero means no waiting will be attempted
        Throws:
        java.lang.IllegalArgumentException - when timeoutMillis is negative or maxConcurrentSnaphots is less than 1
      • LearnerSnapshotThrottler

        public LearnerSnapshotThrottler​(int maxConcurrentSnapshots)
    • Method Detail

      • beginSnapshot

        public LearnerSnapshot beginSnapshot​(boolean essential)
                                      throws SnapshotThrottleException,
                                             java.lang.InterruptedException
        Indicates that a new snapshot is about to be sent.
        Parameters:
        essential - if true, do not throw an exception even if throttling limit is reached
        Throws:
        SnapshotThrottleException - if throttling limit has been exceeded and essential == false, even after waiting for the timeout period, if any
        java.lang.InterruptedException - if thread is interrupted while trying to start a snapshot; cannot happen if timeout is zero
      • endSnapshot

        public void endSnapshot()
        Indicates that a snapshot has been completed.