package slavetest;

import java.util.Map;

import org.neo4j.graphdb.GraphDatabaseService;
import org.neo4j.helpers.collection.MapUtil;
import org.neo4j.kernel.HighlyAvailableGraphDatabase;

public class StartHaDb
{
    static final Map<Integer, String> HA_SERVERS = MapUtil.genericMap(
            "1", "172.16.2.33:5559",
            "2", "172.16.1.242:5559"
    );
    
    public static void main( String[] args ) throws Exception
    {
        final GraphDatabaseService db = new HighlyAvailableGraphDatabase( "var/hadb", MapUtil.stringMap(
                HighlyAvailableGraphDatabase.CONFIG_KEY_HA_MACHINE_ID, "2",
                HighlyAvailableGraphDatabase.CONFIG_KEY_HA_ZOO_KEEPER_SERVERS, join( StartZooKeeperServer.ZOO_KEEPER_SERVERS, "," ),
                HighlyAvailableGraphDatabase.CONFIG_KEY_HA_SERVERS, toHaServerFormat( HA_SERVERS ),
                "enable_remote_shell", "true" ) );
        Runtime.getRuntime().addShutdownHook( new Thread()
        {
            public void run()
            {
                db.shutdown();
            }
        } );
    }
    
    private static String toHaServerFormat( Map<Integer, String> haServers )
    {
        StringBuilder builder = new StringBuilder();
        for ( Map.Entry<Integer, String> entry : haServers.entrySet() )
        {
            builder.append( (builder.length() > 0 ? "," : "") + entry.getKey() + "=" + entry.getValue() );
        }
        return builder.toString();
    }
    
    private static String join( String[] strings, String delimiter )
    {
        StringBuilder builder = new StringBuilder();
        for ( String string : strings )
        {
            builder.append( (builder.length() > 0 ? delimiter : "") + string );
        }
        return builder.toString();
    }
}

@@ -13,16 +13,39 @@
 etest;%0A%0A
+import java.util.Date;%0A
 import j
@@ -58,16 +58,16 @@
 il.Map;%0A
-
 %0Aimport 
@@ -204,16 +204,67 @@
 atabase;
+%0Aimport org.neo4j.kernel.ha.zookeeper.NeoStoreUtil;
 %0A%0Apublic
@@ -503,24 +503,292 @@
 ption%0A    %7B%0A
+        NeoStoreUtil store = new NeoStoreUtil( %22var/hadb%22 );%0A        System.out.println( %22Starting store: createTime=%22 + new Date( store.getCreationTime() ) + %0A                %22 identifier=%22 + store.getStoreId() + %22 last committed tx=%22 + store.getLastCommittedTx() );%0A
         fina
@@ -952,17 +952,17 @@
 NE_ID, %22
-2
+1
 %22,%0A     

Debug sys out.