Class Learner
- java.lang.Object
-
- org.apache.zookeeper.server.quorum.Learner
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.BufferedOutputStreambufferedOutputprotected org.apache.jute.InputArchiveleaderIsprotected org.apache.jute.OutputArchiveleaderOsprotected intleaderProtocolVersionthe protocol version of the leaderprotected static org.slf4j.LoggerLOGprotected java.net.Socketsock
-
Constructor Summary
Constructors Constructor Description Learner()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidconnectToLeader(java.net.InetSocketAddress addr, java.lang.String hostname)Establish a connection with the Leader found by findLeader.protected QuorumPeer.QuorumServerfindLeader()Returns the address of the node we think is the leader.intgetPendingRevalidationsCount()java.net.SocketgetSocket()Socket getterprotected voidping(QuorumPacket qp)protected longregisterWithLeader(int pktType)Once connected to the leader, perform the handshake protocol to establish a following / observing connection.protected voidrevalidate(QuorumPacket qp)voidshutdown()Shutdown the Peerprotected voidsyncWithLeader(long newLeaderZxid)Finally, synchronize our history with the Leader.
-
-
-
Field Detail
-
bufferedOutput
protected java.io.BufferedOutputStream bufferedOutput
-
sock
protected java.net.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
-
-
Method Detail
-
getSocket
public java.net.Socket getSocket()
Socket getter- Returns:
-
getPendingRevalidationsCount
public int getPendingRevalidationsCount()
-
findLeader
protected QuorumPeer.QuorumServer findLeader()
Returns the address of the node we think is the leader.
-
connectToLeader
protected void connectToLeader(java.net.InetSocketAddress addr, java.lang.String hostname) throws java.io.IOException, java.net.ConnectException, java.lang.InterruptedExceptionEstablish 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:
java.io.IOException-- if the socket connection fails on the 5th attempt
- if there is an authentication failure while connecting to leader
java.net.ConnectExceptionjava.lang.InterruptedException
-
registerWithLeader
protected long registerWithLeader(int pktType) throws java.io.IOExceptionOnce 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:
java.io.IOException
-
syncWithLeader
protected void syncWithLeader(long newLeaderZxid) throws java.io.IOException, java.lang.InterruptedExceptionFinally, synchronize our history with the Leader.- Parameters:
newLeaderZxid-- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
revalidate
protected void revalidate(QuorumPacket qp) throws java.io.IOException
- Throws:
java.io.IOException
-
ping
protected void ping(QuorumPacket qp) throws java.io.IOException
- Throws:
java.io.IOException
-
shutdown
public void shutdown()
Shutdown the Peer
-
-