package de.mpiwg.itgroup.annotations; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.factory.GraphDatabaseFactory; import org.neo4j.kernel.AbstractGraphDatabase; import org.neo4j.server.WrappingNeoServerBootstrapper; public class AnnotationServerDb { private static String DB_PATH = "target/neo4j-annotation-db"; private static GraphDatabaseService graphDb; /** * @param args */ public static void main(String[] args) { AnnotationServerDb db = new AnnotationServerDb(); db.createDb(); // do something AbstractGraphDatabase graphdb = (AbstractGraphDatabase) graphDb; WrappingNeoServerBootstrapper srv; srv = new WrappingNeoServerBootstrapper( graphdb ); System.out.println("Starting server..."); srv.start(); // The server is now running try { Thread.sleep(300*1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // until we stop it: System.out.println("Stopping server..."); srv.stop(); db.shutDown(); } /** * */ public void createDb() { System.out.println(); System.out.println("Starting database "+DB_PATH+" ..."); graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH); registerShutdownHook(graphDb); } public void shutDown() { System.out.println(); System.out.println("Shutting down database ..."); // START SNIPPET: shutdownServer graphDb.shutdown(); // END SNIPPET: shutdownServer } private static void registerShutdownHook(final GraphDatabaseService graphDb) { // Registers a shutdown hook for the Neo4j instance so that it // shuts down nicely when the VM exits (even if you "Ctrl-C" the // running example before it's completed) Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { graphDb.shutdown(); } }); } }