source: AnnotationManagerN4J/src/main/java/de/mpiwg/itgroup/annotations/AnnotationServerDb.java @ 1:6556943c4fb9

Last change on this file since 1:6556943c4fb9 was 1:6556943c4fb9, checked in by casties, 12 years ago

include neo4j and restlet

File size: 2.1 KB
Line 
1package de.mpiwg.itgroup.annotations;
2
3import org.neo4j.graphdb.GraphDatabaseService;
4import org.neo4j.graphdb.factory.GraphDatabaseFactory;
5import org.neo4j.kernel.AbstractGraphDatabase;
6import org.neo4j.server.WrappingNeoServerBootstrapper;
7
8public 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}
Note: See TracBrowser for help on using the repository browser.