use of org.neo4j.kernel.ha.zookeeper.ClusterManager in project graphdb by neo4j-attic.
the class LocalhostZooKeeperCluster method await.
private void await(ZooKeeper[] keepers, long timeout, TimeUnit unit) {
timeout = System.currentTimeMillis() + unit.toMillis(timeout);
do {
ClusterManager cm = null;
try {
cm = new ClusterManager(getConnectionString());
cm.waitForSyncConnected();
break;
} catch (Exception e) {
e.printStackTrace();
// ok retry
} finally {
if (cm != null) {
try {
cm.shutdown();
} catch (Throwable t) {
t.printStackTrace();
}
}
}
if (System.currentTimeMillis() > timeout) {
throw new TimeoutException("waiting for ZooKeeper cluster to start");
}
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
Thread.interrupted();
}
} while (true);
}
use of org.neo4j.kernel.ha.zookeeper.ClusterManager in project graphdb by neo4j-attic.
the class HaBackupProvider method getMasterServerInCluster.
private static String getMasterServerInCluster(String from) {
ClusterManager clusterManager = new ClusterManager(from);
Pair<String, Integer> masterServer = null;
try {
clusterManager.waitForSyncConnected();
Machine master = clusterManager.getMaster();
masterServer = master.getServer();
if (masterServer != null) {
int backupPort = clusterManager.getBackupPort(master.getMachineId());
return String.format(ServerAddressFormat, masterServer.first(), backupPort);
}
throw new ComException("Master couldn't be found from cluster managed by " + from);
} finally {
clusterManager.shutdown();
}
}
use of org.neo4j.kernel.ha.zookeeper.ClusterManager in project graphdb by neo4j-attic.
the class DumpZooInfo method main.
public static void main(String[] args) {
ClusterManager clusterManager = new ClusterManager("localhost");
clusterManager.waitForSyncConnected();
System.out.println("Master is " + clusterManager.getCachedMaster());
System.out.println("Connected slaves");
for (Machine info : clusterManager.getConnectedSlaves()) {
System.out.println("\t" + info);
}
// System.out.println( "Disconnected slaves" );
// for ( Machine info : clusterManager.getDisconnectedSlaves() )
// {
// System.out.println( "\t" + info );
// }
clusterManager.shutdown();
}
Aggregations