Ignore:
Timestamp:
Jul 2, 2012, 8:39:46 PM (12 years ago)
Author:
casties
Branch:
default
Message:

store seems to work now :-)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/main/java/de/mpiwg/itgroup/annotations/restlet/RestServer.java

    r3 r4  
    2828import org.restlet.Restlet;
    2929import org.restlet.routing.Router;
    30 import org.restlet.security.ChallengeAuthenticator;
    31 
    32 import scala.sys.process.ProcessBuilderImpl.Dummy;
     30
     31import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore;
    3332
    3433public class RestServer extends Application {
    3534
    36     public static Logger logger = Logger.getRootLogger();
    37 
    38     private ChallengeAuthenticator authenticator;
     35    public static Logger logger = Logger.getLogger(RestServer.class);
    3936
    4037    /**
     
    4744    public static final String GRAPHDB_KEY = "annotationmanager.graphdb";
    4845    public String DB_PATH = "WEB-INF/neo4j-annotation-db";
     46
     47    private WrappingNeoServerBootstrapper srv;
     48    public static final String GRAPHDBSRV_KEY = "annotationmanager.graphdb.srv";
     49   
     50    private AnnotationStore store;
     51    public static final String ANNSTORE_KEY = "annotationmanager.store";
    4952
    5053    /**
     
    7174                    logger.debug("opening DB " + dbFn);
    7275                    graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbFn);
     76                    registerShutdownHook(graphDb);
    7377                    // store in context
    7478                    sc.setAttribute(GRAPHDB_KEY, graphDb);
    75                     WrappingNeoServerBootstrapper srv = new WrappingNeoServerBootstrapper((AbstractGraphDatabase) graphDb);
     79                    // AnnotationStore
     80                    store = new AnnotationStore(graphDb);
     81                    sc.setAttribute(ANNSTORE_KEY, store);
     82                    // admin server
     83                    srv = new WrappingNeoServerBootstrapper((AbstractGraphDatabase) graphDb);
    7684                    logger.debug("Starting DB admin server...");
     85                    // store in context
     86                    sc.setAttribute(GRAPHDBSRV_KEY, srv);
    7787                    srv.start();
    7888                } else {
     
    127137        router.attach("/annotator/annotations", AnnotatorAnnotations.class);
    128138        router.attach("/annotator/annotations/{id}", AnnotatorAnnotations.class);
    129         // router.attach("/annotator/search", AnnotatorSearch.class);
     139        router.attach("/annotator/search", AnnotatorSearch.class);
    130140
    131141        // router.attach("",redirector); router.attach("/annotator",
     
    241251    }
    242252
     253    /* (non-Javadoc)
     254     * @see org.restlet.Application#stop()
     255     */
     256    @Override
     257    public synchronized void stop() throws Exception {
     258        /*
     259         * trying to clean up databases, nur sure if this is the right way...
     260         */
     261        if (srv != null) {
     262            logger.debug("Stopping DB admin server...");
     263            srv.stop();
     264            srv = null;
     265        }
     266        if (graphDb != null) {
     267            logger.debug("Stopping DB...");
     268            graphDb.shutdown();
     269            graphDb = null;
     270        }
     271        super.stop();
     272    }
     273
     274    private static void registerShutdownHook(final GraphDatabaseService graphDb) {
     275        // Registers a shutdown hook for the Neo4j instance so that it
     276        // shuts down nicely when the VM exits (even if you "Ctrl-C" the
     277        // running example before it's completed)
     278        Runtime.getRuntime().addShutdownHook(new Thread() {
     279            @Override
     280            public void run() {
     281                graphDb.shutdown();
     282            }
     283        });
     284    }
     285   
     286   
    243287}
Note: See TracChangeset for help on using the changeset viewer.