org.apache.zookeeper.server.quorum
Class QuorumCnxManager

java.lang.Object
  extended by org.apache.zookeeper.server.quorum.QuorumCnxManager

public class QuorumCnxManager
extends java.lang.Object

This class implements a connection manager for leader election using TCP. It maintains one connection for every pair of servers. The tricky part is to guarantee that there is exactly one connection for every pair of servers that are operating correctly and that can communicate over the network. If two servers try to start a connection concurrently, then the connection manager uses a very simple tie-breaking mechanism to decide which connection to drop based on the IP addressed of the two parties. For every peer, the manager maintains a queue of messages to send. If the connection to any particular peer drops, then the sender thread puts the message back on the list. As this implementation currently uses a queue implementation to maintain messages to send to another peer, we add the message to the tail of the queue, thus changing the order of messages. Although this is not a problem for the leader election, it could be a problem when consolidating peer communication. This is to be verified, though.


Nested Class Summary
 class QuorumCnxManager.Listener
          Thread to listen on some port
static class QuorumCnxManager.Message
           
 
Field Summary
 QuorumCnxManager.Listener listener
           
 java.util.concurrent.ArrayBlockingQueue<QuorumCnxManager.Message> recvQueue
           
 
Constructor Summary
QuorumCnxManager(QuorumPeer self)
           
 
Method Summary
 void connectAll()
          Try to establish a connection with each server if one doesn't exist.
 QuorumPeer getQuorumPeer()
          Return reference to QuorumPeer
 long getThreadCount()
           
 void halt()
          Flag that it is time to wrap up all activities and interrupt the listener.
 boolean initiateConnection(java.nio.channels.SocketChannel s, java.lang.Long sid)
          If this server has initiated the connection, then it gives up on the connection if it loses challenge.
 void softHalt()
          A soft halt simply finishes workers.
 void testInitiateConnection(long sid)
          Invokes initiateConnection for testing purposes
 void toSend(java.lang.Long sid, java.nio.ByteBuffer b)
          Processes invoke this message to queue a message to send.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

recvQueue

public final java.util.concurrent.ArrayBlockingQueue<QuorumCnxManager.Message> recvQueue

listener

public final QuorumCnxManager.Listener listener
Constructor Detail

QuorumCnxManager

public QuorumCnxManager(QuorumPeer self)
Method Detail

testInitiateConnection

public void testInitiateConnection(long sid)
                            throws java.lang.Exception
Invokes initiateConnection for testing purposes

Parameters:
sid -
Throws:
java.lang.Exception

initiateConnection

public boolean initiateConnection(java.nio.channels.SocketChannel s,
                                  java.lang.Long sid)
If this server has initiated the connection, then it gives up on the connection if it loses challenge. Otherwise, it keeps the connection.


toSend

public void toSend(java.lang.Long sid,
                   java.nio.ByteBuffer b)
Processes invoke this message to queue a message to send. Currently, only leader election uses it.


connectAll

public void connectAll()
Try to establish a connection with each server if one doesn't exist.


halt

public void halt()
Flag that it is time to wrap up all activities and interrupt the listener.


softHalt

public void softHalt()
A soft halt simply finishes workers.


getThreadCount

public long getThreadCount()

getQuorumPeer

public QuorumPeer getQuorumPeer()
Return reference to QuorumPeer



Copyright © 2012 The Apache Software Foundation