org.neo4j.kernel.ha.zookeeper
Class AbstractZooKeeperManager

java.lang.Object
  extended by org.neo4j.kernel.ha.zookeeper.AbstractZooKeeperManager
All Implemented Interfaces:
org.apache.zookeeper.Watcher
Direct Known Subclasses:
ZooClient, ZooKeeperClusterClient

public abstract class AbstractZooKeeperManager
extends Object
implements org.apache.zookeeper.Watcher

Contains basic functionality for a ZooKeeper manager, f.ex. how to get the current master in the cluster.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.apache.zookeeper.Watcher
org.apache.zookeeper.Watcher.Event
 
Field Summary
protected static String HA_SERVERS_CHILD
           
static Pair<Master,Machine> NO_MASTER_MACHINE_PAIR
           
 
Constructor Summary
AbstractZooKeeperManager(String servers, AbstractGraphDatabase graphDb, int clientReadTimeout, int clientLockReadTimeout, int maxConcurrentChannelsPerSlave, long sessionTimeout)
           
 
Method Summary
protected  Pair<Master,Machine> bootstrap()
           
protected  Map<Integer,ZooKeeperMachine> getAllMachines(boolean wait)
           
protected  Map<Integer,ZooKeeperMachine> getAllMachines(boolean wait, org.neo4j.kernel.ha.zookeeper.AbstractZooKeeperManager.WaitMode mode)
           
 Pair<Master,Machine> getCachedMaster()
           
protected  Client.ConnectionLostHandler getConnectionLostHandler()
           
protected  AbstractGraphDatabase getGraphDb()
           
protected  String getHaServer(int machineId, boolean wait)
           
protected  ZooKeeperMachine getMasterBasedOn(Collection<ZooKeeperMachine> machines)
           
protected  Master getMasterClientToMachine(Machine master)
           
protected  Pair<Master,Machine> getMasterFromZooKeeper(boolean wait, boolean allowChange)
          Tries to discover the master from the zookeeper information.
protected abstract  int getMyMachineId()
           
abstract  String getRoot()
           
 String getServers()
           
protected  int getSessionTimeout()
           
abstract  org.apache.zookeeper.ZooKeeper getZooKeeper(boolean sync)
           
protected  org.apache.zookeeper.ZooKeeper instantiateZooKeeper()
           
protected  void invalidateMaster()
           
protected  Pair<Integer,Integer> parseChild(String child)
           
protected  Pair<Long,Integer> readDataRepresentingInstance(String path)
           
protected  Pair<String,Integer> readHaServer(int machineId, boolean wait)
           
 void shutdown()
           
 void waitForSyncConnected()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.zookeeper.Watcher
process
 

Field Detail

HA_SERVERS_CHILD

protected static final String HA_SERVERS_CHILD
See Also:
Constant Field Values

NO_MASTER_MACHINE_PAIR

public static final Pair<Master,Machine> NO_MASTER_MACHINE_PAIR
Constructor Detail

AbstractZooKeeperManager

public AbstractZooKeeperManager(String servers,
                                AbstractGraphDatabase graphDb,
                                int clientReadTimeout,
                                int clientLockReadTimeout,
                                int maxConcurrentChannelsPerSlave,
                                long sessionTimeout)
Method Detail

instantiateZooKeeper

protected org.apache.zookeeper.ZooKeeper instantiateZooKeeper()

getSessionTimeout

protected int getSessionTimeout()

getZooKeeper

public abstract org.apache.zookeeper.ZooKeeper getZooKeeper(boolean sync)

getRoot

public abstract String getRoot()

getGraphDb

protected AbstractGraphDatabase getGraphDb()

parseChild

protected Pair<Integer,Integer> parseChild(String child)

readDataRepresentingInstance

protected Pair<Long,Integer> readDataRepresentingInstance(String path)
                                                   throws InterruptedException,
                                                          org.apache.zookeeper.KeeperException
Throws:
InterruptedException
org.apache.zookeeper.KeeperException

invalidateMaster

protected void invalidateMaster()

getMasterFromZooKeeper

protected Pair<Master,Machine> getMasterFromZooKeeper(boolean wait,
                                                      boolean allowChange)
Tries to discover the master from the zookeeper information. Will return a Pair of a Master and the Machine it resides on. If the new master is different than the current then the current is invalidated and if allowChange is set to true then the a connection to the new master is established otherwise a NO_MASTER is returned.

Parameters:
wait - Whether to wait for a sync connected event
allowChange - If to connect to the new master
Returns:
The master machine pair, possibly a NO_MASTER_MACHINE_PAIR

bootstrap

protected Pair<Master,Machine> bootstrap()

getMasterClientToMachine

protected Master getMasterClientToMachine(Machine master)

getMyMachineId

protected abstract int getMyMachineId()

getCachedMaster

public Pair<Master,Machine> getCachedMaster()

getMasterBasedOn

protected ZooKeeperMachine getMasterBasedOn(Collection<ZooKeeperMachine> machines)

getConnectionLostHandler

protected Client.ConnectionLostHandler getConnectionLostHandler()

getAllMachines

protected Map<Integer,ZooKeeperMachine> getAllMachines(boolean wait)

getAllMachines

protected Map<Integer,ZooKeeperMachine> getAllMachines(boolean wait,
                                                       org.neo4j.kernel.ha.zookeeper.AbstractZooKeeperManager.WaitMode mode)

getHaServer

protected String getHaServer(int machineId,
                             boolean wait)

readHaServer

protected Pair<String,Integer> readHaServer(int machineId,
                                            boolean wait)

shutdown

public void shutdown()

waitForSyncConnected

public final void waitForSyncConnected()

getServers

public String getServers()


Copyright © 2002-2012 The Neo4j Graph Database Project. All Rights Reserved.