org.neo4j.kernel.ha.cluster.zoo
Class ZooClient

java.lang.Object
  extended by org.neo4j.kernel.ha.cluster.zoo.ZooClient
All Implemented Interfaces:
CompatibilityMonitor, org.neo4j.kernel.lifecycle.Lifecycle

public class ZooClient
extends Object
implements org.neo4j.kernel.lifecycle.Lifecycle, CompatibilityMonitor


Field Summary
protected  Machine cachedMaster
           
protected static String COMPATIBILITY_CHILD_18
           
protected static String COMPATIBILITY_CHILD_19
           
protected static String FLUSH_REQUESTED_CHILD
           
protected static String HA_SERVERS_CHILD
           
protected  org.neo4j.kernel.impl.util.StringLogger msgLog
           
static Machine NO_MACHINE
           
protected static int STOP_FLUSHING
           
 
Constructor Summary
ZooClient(org.neo4j.kernel.impl.util.StringLogger stringLogger, org.neo4j.kernel.configuration.Config conf)
           
 
Method Summary
 void addCompatibilityModeListener(CompatibilityModeListener listener)
           
 void addZooListener(ZooListener zooListener)
           
protected  String asRootPath(org.neo4j.kernel.impl.nioneo.store.StoreId storeId)
           
protected  Map<Integer,ZooKeeperMachine> getAllMachines(boolean wait)
           
protected  Map<Integer,ZooKeeperMachine> getAllMachines(boolean wait, org.neo4j.kernel.ha.cluster.zoo.ZooClient.WaitMode mode)
           
protected  Map<Integer,ZooKeeperMachine> getAllMachinesInner(boolean wait, org.neo4j.kernel.ha.cluster.zoo.ZooClient.WaitMode mode)
           
 Machine getCachedMaster()
           
 String getClusterServer()
           
 org.neo4j.kernel.impl.nioneo.store.StoreId getClusterStoreId(org.neo4j.kernel.ha.cluster.zoo.ZooClient.WaitMode mode)
           
protected  org.neo4j.kernel.impl.nioneo.store.StoreId getClusterStoreId(org.apache.zookeeper.ZooKeeper keeper, String clusterName)
           
 int getCurrentMasterNotify()
           
 String getHaServer()
           
protected  Machine getHaServer(int machineId, boolean wait)
           
protected  Iterable<Machine> getHaServers()
           
protected  ZooKeeperMachine getMasterBasedOn(Collection<ZooKeeperMachine> machines)
           
protected  int getMyMachineId()
           
protected  int getNumberOfServers()
           
 String getRoot()
           
protected  String getSequenceNr()
           
protected  int getSessionTimeout()
           
protected  org.neo4j.kernel.impl.nioneo.store.StoreId getStoreId()
           
 org.apache.zookeeper.ZooKeeper getZooKeeper(boolean sync)
           
protected  int idFromPath(String path)
           
 void init()
           
protected  void invalidateMaster()
           
protected  void masterElectionHappened(Machine previousMaster, Machine newMaster)
           
protected  org.neo4j.helpers.Pair<Integer,Integer> parseChild(String child)
           
protected  org.neo4j.helpers.Pair<Long,Integer> readDataRepresentingInstance(String path)
           
protected  Machine readHaServer(int machineId, boolean wait)
           
protected  void refreshHaServers()
           
 String refreshMasterFromZooKeeper()
          Tries to discover the master from the zookeeper information.
 void removeCompatibilityModeListener(CompatibilityModeListener listener)
           
protected  void setDataChangeWatcher(String child, int currentMasterId)
           
protected  void setDataChangeWatcher(String child, int currentMasterId, boolean skipOnSame)
          Writes into one of master-notify or master-rebound the value given.
 void shutdown()
           
 void start()
           
 void stop()
           
protected  void subscribeToChildrenChangeWatcher(String child)
           
protected  void subscribeToDataChangeWatcher(String child)
           
 String toString()
           
 void waitForSyncConnected()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

HA_SERVERS_CHILD

protected static final String HA_SERVERS_CHILD
See Also:
Constant Field Values

FLUSH_REQUESTED_CHILD

protected static final String FLUSH_REQUESTED_CHILD
See Also:
Constant Field Values

COMPATIBILITY_CHILD_18

protected static final String COMPATIBILITY_CHILD_18
See Also:
Constant Field Values

COMPATIBILITY_CHILD_19

protected static final String COMPATIBILITY_CHILD_19
See Also:
Constant Field Values

STOP_FLUSHING

protected static final int STOP_FLUSHING
See Also:
Constant Field Values

cachedMaster

protected volatile Machine cachedMaster

msgLog

protected final org.neo4j.kernel.impl.util.StringLogger msgLog

NO_MACHINE

public static final Machine NO_MACHINE
Constructor Detail

ZooClient

public ZooClient(org.neo4j.kernel.impl.util.StringLogger stringLogger,
                 org.neo4j.kernel.configuration.Config conf)
Method Detail

init

public void init()
          throws Throwable
Specified by:
init in interface org.neo4j.kernel.lifecycle.Lifecycle
Throws:
Throwable

start

public void start()
           throws Throwable
Specified by:
start in interface org.neo4j.kernel.lifecycle.Lifecycle
Throws:
Throwable

stop

public void stop()
          throws Throwable
Specified by:
stop in interface org.neo4j.kernel.lifecycle.Lifecycle
Throws:
Throwable

shutdown

public void shutdown()
Specified by:
shutdown in interface org.neo4j.kernel.lifecycle.Lifecycle

refreshMasterFromZooKeeper

public String refreshMasterFromZooKeeper()
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.

Returns:
The master URI as a String

invalidateMaster

protected void invalidateMaster()

getCachedMaster

public Machine getCachedMaster()

getStoreId

protected org.neo4j.kernel.impl.nioneo.store.StoreId getStoreId()

getMyMachineId

protected int getMyMachineId()

subscribeToDataChangeWatcher

protected void subscribeToDataChangeWatcher(String child)

subscribeToChildrenChangeWatcher

protected void subscribeToChildrenChangeWatcher(String child)

setDataChangeWatcher

protected void setDataChangeWatcher(String child,
                                    int currentMasterId)

setDataChangeWatcher

protected void setDataChangeWatcher(String child,
                                    int currentMasterId,
                                    boolean skipOnSame)
Writes into one of master-notify or master-rebound the value given. If skipOnSame is true then if the value there is the same as the argument nothing will be written. A watch is always set on the node.

Parameters:
child - The node to write to
currentMasterId - The value to write
skipOnSame - If true, then if the existing value is the same as currentMasterId nothing will be written.

getRoot

public String getRoot()

getCurrentMasterNotify

public int getCurrentMasterNotify()

masterElectionHappened

protected void masterElectionHappened(Machine previousMaster,
                                      Machine newMaster)

getZooKeeper

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

getClusterStoreId

public org.neo4j.kernel.impl.nioneo.store.StoreId getClusterStoreId(org.neo4j.kernel.ha.cluster.zoo.ZooClient.WaitMode mode)

getClusterStoreId

protected org.neo4j.kernel.impl.nioneo.store.StoreId getClusterStoreId(org.apache.zookeeper.ZooKeeper keeper,
                                                                       String clusterName)

asRootPath

protected String asRootPath(org.neo4j.kernel.impl.nioneo.store.StoreId storeId)

parseChild

protected org.neo4j.helpers.Pair<Integer,Integer> parseChild(String child)

readDataRepresentingInstance

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

getSequenceNr

protected String getSequenceNr()

toString

public String toString()
Overrides:
toString in class Object

addZooListener

public void addZooListener(ZooListener zooListener)

addCompatibilityModeListener

public void addCompatibilityModeListener(CompatibilityModeListener listener)
Specified by:
addCompatibilityModeListener in interface CompatibilityMonitor

removeCompatibilityModeListener

public void removeCompatibilityModeListener(CompatibilityModeListener listener)
Specified by:
removeCompatibilityModeListener in interface CompatibilityMonitor

getMasterBasedOn

protected ZooKeeperMachine getMasterBasedOn(Collection<ZooKeeperMachine> machines)

getAllMachines

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

getAllMachines

protected Map<Integer,ZooKeeperMachine> getAllMachines(boolean wait,
                                                       org.neo4j.kernel.ha.cluster.zoo.ZooClient.WaitMode mode)

getAllMachinesInner

protected Map<Integer,ZooKeeperMachine> getAllMachinesInner(boolean wait,
                                                            org.neo4j.kernel.ha.cluster.zoo.ZooClient.WaitMode mode)

getHaServer

protected Machine getHaServer(int machineId,
                              boolean wait)

getClusterServer

public String getClusterServer()

getHaServer

public String getHaServer()

refreshHaServers

protected void refreshHaServers()
                         throws org.apache.zookeeper.KeeperException
Throws:
org.apache.zookeeper.KeeperException

getHaServers

protected Iterable<Machine> getHaServers()

getNumberOfServers

protected int getNumberOfServers()

readHaServer

protected Machine readHaServer(int machineId,
                               boolean wait)

waitForSyncConnected

public final void waitForSyncConnected()

getSessionTimeout

protected int getSessionTimeout()

idFromPath

protected int idFromPath(String path)


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