Class Learner
- java.lang.Object
-
- org.apache.zookeeper.server.quorum.Learner
-
-
Field Summary
Fields Modifier and Type Field Description protected java.io.BufferedOutputStream
bufferedOutput
static boolean
closeSocketAsync
protected MultipleAddresses
leaderAddr
protected InputArchive
leaderIs
protected OutputArchive
leaderOs
protected int
leaderProtocolVersion
the protocol version of the leaderstatic java.lang.String
LEARNER_ASYNC_SENDING
static java.lang.String
LEARNER_CLOSE_SOCKET_ASYNC
protected static org.slf4j.Logger
LOG
protected MessageTracker
messageTracker
protected java.net.Socket
sock
protected java.util.concurrent.atomic.AtomicBoolean
sockBeingClosed
-
Constructor Summary
Constructors Constructor Description Learner()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
connectToLeader(MultipleAddresses multiAddr, java.lang.String hostname)
Establish a connection with the LearnerMaster found by findLearnerMaster.protected java.net.Socket
createSocket()
Creating a simple or and SSL socket.protected QuorumPeer.QuorumServer
findLeader()
Returns the address of the node we think is the leader.protected static boolean
getAsyncSending()
int
getPendingRevalidationsCount()
java.net.Socket
getSocket()
Socket getterprotected long
nanoTime()
Overridable helper method to return the System.nanoTime().protected void
ping(QuorumPacket qp)
protected long
registerWithLeader(int pktType)
Once connected to the leader or learner master, perform the handshake protocol to establish a following / observing connection.protected void
revalidate(QuorumPacket qp)
protected static void
setAsyncSending(boolean newMode)
void
shutdown()
Shutdown the Peerprotected void
sockConnect(java.net.Socket sock, java.net.InetSocketAddress addr, int timeout)
Overridable helper method to simply call sock.connect().protected void
startSendingThread()
Start thread that will forward any packet in the queue to the leaderprotected void
syncWithLeader(long newLeaderZxid)
Finally, synchronize our history with the Leader (if Follower) or the LearnerMaster (if Observer).
-
-
-
Field Detail
-
bufferedOutput
protected java.io.BufferedOutputStream bufferedOutput
-
sock
protected java.net.Socket sock
-
leaderAddr
protected MultipleAddresses leaderAddr
-
sockBeingClosed
protected java.util.concurrent.atomic.AtomicBoolean sockBeingClosed
-
leaderIs
protected InputArchive leaderIs
-
leaderOs
protected OutputArchive leaderOs
-
leaderProtocolVersion
protected int leaderProtocolVersion
the protocol version of the leader
-
messageTracker
protected final MessageTracker messageTracker
-
LOG
protected static final org.slf4j.Logger LOG
-
LEARNER_ASYNC_SENDING
public static final java.lang.String LEARNER_ASYNC_SENDING
- See Also:
- Constant Field Values
-
LEARNER_CLOSE_SOCKET_ASYNC
public static final java.lang.String LEARNER_CLOSE_SOCKET_ASYNC
- See Also:
- Constant Field Values
-
closeSocketAsync
public static final boolean closeSocketAsync
-
-
Method Detail
-
getSocket
public java.net.Socket getSocket()
Socket getter
-
getPendingRevalidationsCount
public int getPendingRevalidationsCount()
-
setAsyncSending
protected static void setAsyncSending(boolean newMode)
-
getAsyncSending
protected static boolean getAsyncSending()
-
startSendingThread
protected void startSendingThread()
Start thread that will forward any packet in the queue to the leader
-
findLeader
protected QuorumPeer.QuorumServer findLeader()
Returns the address of the node we think is the leader.
-
nanoTime
protected long nanoTime()
Overridable helper method to return the System.nanoTime(). This method behaves identical to System.nanoTime().
-
sockConnect
protected void sockConnect(java.net.Socket sock, java.net.InetSocketAddress addr, int timeout) throws java.io.IOException
Overridable helper method to simply call sock.connect(). This can be overriden in tests to fake connection success/failure for connectToLeader.- Throws:
java.io.IOException
-
connectToLeader
protected void connectToLeader(MultipleAddresses multiAddr, java.lang.String hostname) throws java.io.IOException
Establish a connection with the LearnerMaster found by findLearnerMaster. Followers only connect to Leaders, Observers can connect to any active LearnerMaster. Retries until either initLimit time has elapsed or 5 tries have happened.- Parameters:
multiAddr
- - the address of the Peer 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
-
createSocket
protected java.net.Socket createSocket() throws X509Exception, java.io.IOException
Creating a simple or and SSL socket. This can be overridden in tests to fake already connected sockets for connectToLeader.- Throws:
X509Exception
java.io.IOException
-
registerWithLeader
protected long registerWithLeader(int pktType) throws java.io.IOException
Once connected to the leader or learner master, 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.lang.Exception
Finally, synchronize our history with the Leader (if Follower) or the LearnerMaster (if Observer).- Parameters:
newLeaderZxid
-- Throws:
java.io.IOException
java.lang.InterruptedException
java.lang.Exception
-
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
-
-