# Class ObserverMaster

java.lang.Object
org.apache.zookeeper.server.quorum.LearnerMaster
org.apache.zookeeper.server.quorum.ObserverMaster

All Implemented Interfaces:
  `Runnable`

public class ObserverMaster extends LearnerMaster implements Runnable
Used by Followers to host Observers. This reduces the network load on the Leader process by pushing the responsibility for keeping Observers in sync off the leading peer. It is expected that Observers will continue to perform the initial vetting of clients and requests. Observers send the request to the follower where it is received by an ObserverMaster. The ObserverMaster forwards a copy of the request to the ensemble Leader and inserts it into its own request processor pipeline where it can be matched with the response comes back. All commits received from the Leader will be forwarded along to every Learner connected to the ObserverMaster. New Learners connecting to a Follower will receive a LearnerHandler object and be party to its syncing logic to be brought up to date. The logic is quite a bit simpler than the corresponding logic in Leader because it only hosts observers.

## Method Summary

Modifier and Type
Method
Description
`void`
`addLearnerHandler(LearnerHandler learnerHandler)`
`Iterable<Map<String,Object>>`
`getActiveObservers()`
`long`
`getAndDecrementFollowerCounter()`
`int`
`getCurrentTick()`
`long`
`getEpochToPropose(long sid, long lastAcceptedEpoch)`
`long`
`getLastProposed()`
`String`
`getPeerInfo(long sid)`
`QuorumAuthServer`
`getQuorumAuthServer()`
`byte[]`
`getQuorumVerifierBytes()`
`long`
`getQuorumVerifierVersion()`
`int`
`getTickOfInitialAckDeadline()`
`int`
`getTickOfNextAckDeadline()`
`ZKDatabase`
`getZKDatabase()`
`void`
`processAck(long sid, long zxid, SocketAddress localSocketAddress)`
`void`
`registerLearnerHandlerBean(LearnerHandler learnerHandler, Socket socket)`
`void`
`removeLearnerHandler(LearnerHandler learnerHandler)`
`void`
`resetObserverConnectionStats()`
`void`
`revalidateSession(QuorumPacket qp, LearnerHandler learnerHandler)`
`void`
`run()`
`void`
`start()`
`long`
`startForwarding(LearnerHandler learnerHandler, long lastSeenZxid)`
`void`
`stop()`
`void`
`submitLearnerRequest(Request si)`
`int`
`syncTimeout()`
`void`
`touch(long sess, int to)`
`void`
`unregisterLearnerHandlerBean(LearnerHandler learnerHandler)`
`void`
`waitForEpochAck(long sid, StateSummary ss)`
`void`
`waitForNewLeaderAck(long sid, long zxid)`
`void`
`waitForStartup()`

### Methods inherited from class LearnerMaster

`getLearnerDiffSyncThrottler, getLearnerSnapSyncThrottler, getMaxConcurrentDiffSyncs, getMaxConcurrentSnapSyncs, setMaxConcurrentDiffSyncs, setMaxConcurrentSnapSyncs`

### Methods inherited from class Object

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

## Method Details

### addLearnerHandler

public void addLearnerHandler(LearnerHandler learnerHandler)

### removeLearnerHandler

public void removeLearnerHandler(LearnerHandler learnerHandler)

### syncTimeout

public int syncTimeout()

### getTickOfNextAckDeadline

public int getTickOfNextAckDeadline()

### getTickOfInitialAckDeadline

public int getTickOfInitialAckDeadline()

### getAndDecrementFollowerCounter

public long getAndDecrementFollowerCounter()

### waitForEpochAck

public void waitForEpochAck(long sid, StateSummary ss) throws IOException, InterruptedException

Throws:
  `IOException`
  `InterruptedException`

### waitForStartup

public void waitForStartup() throws InterruptedException

Throws:
  `InterruptedException`

### getLastProposed

public long getLastProposed()

### getEpochToPropose

public long getEpochToPropose(long sid, long lastAcceptedEpoch) throws InterruptedException, IOException

Throws:
  `InterruptedException`
  `IOException`

### getZKDatabase

public ZKDatabase getZKDatabase()

### waitForNewLeaderAck

public void waitForNewLeaderAck(long sid, long zxid) throws InterruptedException

Throws:
  `InterruptedException`

### getCurrentTick

public int getCurrentTick()

### processAck

public void processAck(long sid, long zxid, SocketAddress localSocketAddress)

### touch

public void touch(long sess, int to)

### revalidateSession

public void revalidateSession(QuorumPacket qp, LearnerHandler learnerHandler) throws IOException

Throws:
  `IOException`

### submitLearnerRequest

public void submitLearnerRequest(Request si)

### startForwarding

public long startForwarding(LearnerHandler learnerHandler, long lastSeenZxid)

### getQuorumVerifierVersion

public long getQuorumVerifierVersion()

### getPeerInfo

public String getPeerInfo(long sid)

### getQuorumVerifierBytes

public byte[] getQuorumVerifierBytes()

### getQuorumAuthServer

public QuorumAuthServer getQuorumAuthServer()

### start

public void start() throws IOException

Throws:
  `IOException`

### run

public void run()

Specified by:
  `run` in interface `Runnable`

### stop

public void stop()

### getActiveObservers

public Iterable<Map<String,Object>> getActiveObservers()

### resetObserverConnectionStats

public void resetObserverConnectionStats()

### registerLearnerHandlerBean

public void registerLearnerHandlerBean(LearnerHandler learnerHandler, Socket socket)

### unregisterLearnerHandlerBean

public void unregisterLearnerHandlerBean(LearnerHandler learnerHandler)