org.neo4j.kernel.ha.cluster.zoo
Class ZooClient
java.lang.Object
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
|
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()
|
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
ZooClient
public ZooClient(org.neo4j.kernel.impl.util.StringLogger stringLogger,
org.neo4j.kernel.configuration.Config conf)
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 tocurrentMasterId - The value to writeskipOnSame - 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.