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