# Class LearnerSyncThrottler

java.lang.Object
org.apache.zookeeper.server.quorum.LearnerSyncThrottler

public class LearnerSyncThrottler extends Object
Utility class to limit the number of concurrent syncs from a leader to observers and followers or from a follower to observers. `LearnerHandler` objects should call `beginSync(boolean)` before sending a sync and `endSync()` after finishing, successfully or not.

## Nested Class Summary

Nested Classes
Modifier and Type
Class
Description
`static enum`
`LearnerSyncThrottler.SyncType`

## Constructor Summary

Constructors
Constructor
Description
`LearnerSyncThrottler(int maxConcurrentSyncs, LearnerSyncThrottler.SyncType syncType)`
Constructs a new instance limiting the concurrent number of syncs to `maxConcurrentSyncs`.

## Method Summary

Modifier and Type
Method
Description
`protected void`
`beginSync(boolean essential)`
Indicates that a new sync is about to be sent.
`void`
`endSync()`
Indicates that a sync has been completed.
`int`
`getSyncInProgress()`
`void`
`setMaxConcurrentSyncs(int maxConcurrentSyncs)`

### Methods inherited from class Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### LearnerSyncThrottler

public LearnerSyncThrottler(int maxConcurrentSyncs, LearnerSyncThrottler.SyncType syncType) throws IllegalArgumentException
Constructs a new instance limiting the concurrent number of syncs to `maxConcurrentSyncs`.

Parameters:
  `maxConcurrentSyncs` - maximum concurrent number of syncs
  `syncType` - either a snapshot sync or a txn-based diff sync
Throws:
  `IllegalArgumentException` - when `maxConcurrentSyncs` is less than 1

## Method Details

### beginSync

protected void beginSync(boolean essential) throws SyncThrottleException, InterruptedException
Indicates that a new sync is about to be sent.

Parameters:
  `essential` - if `true`, do not throw an exception even if throttling limit is reached
Throws:
  `SyncThrottleException` - if throttling limit has been exceeded and `essential == false`, even after waiting for the timeout period, if any
  `InterruptedException` - if thread is interrupted while trying to start a sync; cannot happen if timeout is zero

### endSync

public void endSync()
Indicates that a sync has been completed.

### setMaxConcurrentSyncs

public void setMaxConcurrentSyncs(int maxConcurrentSyncs)

### getSyncInProgress

public int getSyncInProgress()