Search in sources :

Example 1 with ClusterManager

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);
}
Also used : ClusterManager(org.neo4j.kernel.ha.zookeeper.ClusterManager) IOException(java.io.IOException) TimeoutException(org.jboss.netty.handler.timeout.TimeoutException) MalformedObjectNameException(javax.management.MalformedObjectNameException) TimeoutException(org.jboss.netty.handler.timeout.TimeoutException)

Example 2 with ClusterManager

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();
    }
}
Also used : ComException(org.neo4j.com.ComException) ClusterManager(org.neo4j.kernel.ha.zookeeper.ClusterManager) Machine(org.neo4j.kernel.ha.zookeeper.Machine)

Example 3 with ClusterManager

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();
}
Also used : ClusterManager(org.neo4j.kernel.ha.zookeeper.ClusterManager) Machine(org.neo4j.kernel.ha.zookeeper.Machine)

Aggregations

ClusterManager (org.neo4j.kernel.ha.zookeeper.ClusterManager)3 Machine (org.neo4j.kernel.ha.zookeeper.Machine)2 IOException (java.io.IOException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 TimeoutException (org.jboss.netty.handler.timeout.TimeoutException)1 ComException (org.neo4j.com.ComException)1