Mercurial > hg > AnnotationManagerN4J
diff src/main/java/de/mpiwg/itgroup/annotations/old/AnnotationServerDb.java @ 7:798a65338565
move test class to old
author | casties |
---|---|
date | Wed, 11 Jul 2012 17:17:32 +0200 |
parents | src/main/java/de/mpiwg/itgroup/annotations/AnnotationServerDb.java@6556943c4fb9 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/main/java/de/mpiwg/itgroup/annotations/old/AnnotationServerDb.java Wed Jul 11 17:17:32 2012 +0200 @@ -0,0 +1,67 @@ +package de.mpiwg.itgroup.annotations.old; + +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(); + } + }); + } +}