7
|
1 package de.mpiwg.itgroup.annotations.old;
|
1
|
2
|
|
3 import org.neo4j.graphdb.GraphDatabaseService;
|
|
4 import org.neo4j.graphdb.factory.GraphDatabaseFactory;
|
|
5 import org.neo4j.kernel.AbstractGraphDatabase;
|
|
6 import org.neo4j.server.WrappingNeoServerBootstrapper;
|
|
7
|
|
8 public class AnnotationServerDb {
|
|
9
|
|
10 private static String DB_PATH = "target/neo4j-annotation-db";
|
|
11 private static GraphDatabaseService graphDb;
|
|
12
|
|
13 /**
|
|
14 * @param args
|
|
15 */
|
|
16 public static void main(String[] args) {
|
|
17 AnnotationServerDb db = new AnnotationServerDb();
|
|
18 db.createDb();
|
|
19 // do something
|
|
20 AbstractGraphDatabase graphdb = (AbstractGraphDatabase) graphDb;
|
|
21 WrappingNeoServerBootstrapper srv;
|
|
22 srv = new WrappingNeoServerBootstrapper( graphdb );
|
|
23 System.out.println("Starting server...");
|
|
24 srv.start();
|
|
25 // The server is now running
|
|
26 try {
|
|
27 Thread.sleep(300*1000);
|
|
28 } catch (InterruptedException e) {
|
|
29 // TODO Auto-generated catch block
|
|
30 e.printStackTrace();
|
|
31 }
|
|
32 // until we stop it:
|
|
33 System.out.println("Stopping server...");
|
|
34 srv.stop();
|
|
35 db.shutDown();
|
|
36 }
|
|
37
|
|
38 /**
|
|
39 *
|
|
40 */
|
|
41 public void createDb() {
|
|
42 System.out.println();
|
|
43 System.out.println("Starting database "+DB_PATH+" ...");
|
|
44 graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(DB_PATH);
|
|
45 registerShutdownHook(graphDb);
|
|
46 }
|
|
47
|
|
48 public void shutDown() {
|
|
49 System.out.println();
|
|
50 System.out.println("Shutting down database ...");
|
|
51 // START SNIPPET: shutdownServer
|
|
52 graphDb.shutdown();
|
|
53 // END SNIPPET: shutdownServer
|
|
54 }
|
|
55
|
|
56 private static void registerShutdownHook(final GraphDatabaseService graphDb) {
|
|
57 // Registers a shutdown hook for the Neo4j instance so that it
|
|
58 // shuts down nicely when the VM exits (even if you "Ctrl-C" the
|
|
59 // running example before it's completed)
|
|
60 Runtime.getRuntime().addShutdownHook(new Thread() {
|
|
61 @Override
|
|
62 public void run() {
|
|
63 graphDb.shutdown();
|
|
64 }
|
|
65 });
|
|
66 }
|
|
67 }
|