org.apache.zookeeper.server.quorum
Class Learner

java.lang.Object
  extended by org.apache.zookeeper.server.quorum.Learner
Direct Known Subclasses:
Follower, Observer

public class Learner
extends Object

This class is the superclass of two of the three main actors in a ZK ensemble: Followers and Observers. Both Followers and Observers share a good deal of code which is moved into Peer to avoid duplication.


Field Summary
protected  BufferedOutputStream bufferedOutput
           
protected  org.apache.jute.InputArchive leaderIs
           
protected  org.apache.jute.OutputArchive leaderOs
           
protected  int leaderProtocolVersion
          the protocol version of the leader
protected static org.slf4j.Logger LOG
           
protected  Socket sock
           
 
Constructor Summary
Learner()
           
 
Method Summary
protected  void connectToLeader(InetSocketAddress addr)
          Establish a connection with the Leader found by findLeader.
protected  InetSocketAddress findLeader()
          Returns the address of the node we think is the leader.
 int getPendingRevalidationsCount()
           
 Socket getSocket()
          Socket getter
protected  void ping(QuorumPacket qp)
           
protected  long registerWithLeader(int pktType)
          Once connected to the leader, perform the handshake protocol to establish a following / observing connection.
protected  void revalidate(QuorumPacket qp)
           
 void shutdown()
          Shutdown the Peer
protected  void syncWithLeader(long newLeaderZxid)
          Finally, synchronize our history with the Leader.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

bufferedOutput

protected BufferedOutputStream bufferedOutput

sock

protected Socket sock

leaderIs

protected org.apache.jute.InputArchive leaderIs

leaderOs

protected org.apache.jute.OutputArchive leaderOs

leaderProtocolVersion

protected int leaderProtocolVersion
the protocol version of the leader


LOG

protected static final org.slf4j.Logger LOG
Constructor Detail

Learner

public Learner()
Method Detail

getSocket

public Socket getSocket()
Socket getter

Returns:

getPendingRevalidationsCount

public int getPendingRevalidationsCount()

findLeader

protected InetSocketAddress findLeader()
Returns the address of the node we think is the leader.


connectToLeader

protected void connectToLeader(InetSocketAddress addr)
                        throws IOException,
                               ConnectException,
                               InterruptedException
Establish a connection with the Leader found by findLeader. Retries 5 times before giving up.

Parameters:
addr - - the address of the Leader to connect to.
Throws:
IOException - - if the socket connection fails on the 5th attempt
ConnectException
InterruptedException

registerWithLeader

protected long registerWithLeader(int pktType)
                           throws IOException
Once connected to the leader, perform the handshake protocol to establish a following / observing connection.

Parameters:
pktType -
Returns:
the zxid the Leader sends for synchronization purposes.
Throws:
IOException

syncWithLeader

protected void syncWithLeader(long newLeaderZxid)
                       throws IOException,
                              InterruptedException
Finally, synchronize our history with the Leader.

Parameters:
newLeaderZxid -
Throws:
IOException
InterruptedException

revalidate

protected void revalidate(QuorumPacket qp)
                   throws IOException
Throws:
IOException

ping

protected void ping(QuorumPacket qp)
             throws IOException
Throws:
IOException

shutdown

public void shutdown()
Shutdown the Peer



Copyright © 2011 The Apache Software Foundation