Mercurial > hg > AnnotationManagerN4J
comparison src/main/java/de/mpiwg/itgroup/annotations/restlet/RestServer.java @ 4:3599b29c393f
store seems to work now :-)
author | casties |
---|---|
date | Mon, 02 Jul 2012 22:39:46 +0200 |
parents | 47b53ae385d1 |
children | bbf0cc5bee29 |
comparison
equal
deleted
inserted
replaced
3:47b53ae385d1 | 4:3599b29c393f |
---|---|
25 import org.neo4j.server.WrappingNeoServerBootstrapper; | 25 import org.neo4j.server.WrappingNeoServerBootstrapper; |
26 import org.restlet.Application; | 26 import org.restlet.Application; |
27 import org.restlet.Context; | 27 import org.restlet.Context; |
28 import org.restlet.Restlet; | 28 import org.restlet.Restlet; |
29 import org.restlet.routing.Router; | 29 import org.restlet.routing.Router; |
30 import org.restlet.security.ChallengeAuthenticator; | 30 |
31 | 31 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; |
32 import scala.sys.process.ProcessBuilderImpl.Dummy; | |
33 | 32 |
34 public class RestServer extends Application { | 33 public class RestServer extends Application { |
35 | 34 |
36 public static Logger logger = Logger.getRootLogger(); | 35 public static Logger logger = Logger.getLogger(RestServer.class); |
37 | |
38 private ChallengeAuthenticator authenticator; | |
39 | 36 |
40 /** | 37 /** |
41 * Properties holding consumer keys and secrets | 38 * Properties holding consumer keys and secrets |
42 */ | 39 */ |
43 private Properties consumerKeys; | 40 private Properties consumerKeys; |
44 public String CONSUMER_KEYS_PATH = "WEB-INF/consumerkeys.property"; | 41 public String CONSUMER_KEYS_PATH = "WEB-INF/consumerkeys.property"; |
45 | 42 |
46 private GraphDatabaseService graphDb; | 43 private GraphDatabaseService graphDb; |
47 public static final String GRAPHDB_KEY = "annotationmanager.graphdb"; | 44 public static final String GRAPHDB_KEY = "annotationmanager.graphdb"; |
48 public String DB_PATH = "WEB-INF/neo4j-annotation-db"; | 45 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"; | |
49 | 52 |
50 /** | 53 /** |
51 * constructor | 54 * constructor |
52 * | 55 * |
53 * @param parentContext | 56 * @param parentContext |
68 */ | 71 */ |
69 String dbFn = getResourcePath(sc, DB_PATH); | 72 String dbFn = getResourcePath(sc, DB_PATH); |
70 if (dbFn != null) { | 73 if (dbFn != null) { |
71 logger.debug("opening DB " + dbFn); | 74 logger.debug("opening DB " + dbFn); |
72 graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbFn); | 75 graphDb = new GraphDatabaseFactory().newEmbeddedDatabase(dbFn); |
76 registerShutdownHook(graphDb); | |
73 // store in context | 77 // store in context |
74 sc.setAttribute(GRAPHDB_KEY, graphDb); | 78 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); | |
76 logger.debug("Starting DB admin server..."); | 84 logger.debug("Starting DB admin server..."); |
85 // store in context | |
86 sc.setAttribute(GRAPHDBSRV_KEY, srv); | |
77 srv.start(); | 87 srv.start(); |
78 } else { | 88 } else { |
79 logger.error("Unable to get resource " + DB_PATH); | 89 logger.error("Unable to get resource " + DB_PATH); |
80 } | 90 } |
81 } | 91 } |
124 | 134 |
125 Router router = new Router(getContext()); | 135 Router router = new Router(getContext()); |
126 | 136 |
127 router.attach("/annotator/annotations", AnnotatorAnnotations.class); | 137 router.attach("/annotator/annotations", AnnotatorAnnotations.class); |
128 router.attach("/annotator/annotations/{id}", AnnotatorAnnotations.class); | 138 router.attach("/annotator/annotations/{id}", AnnotatorAnnotations.class); |
129 // router.attach("/annotator/search", AnnotatorSearch.class); | 139 router.attach("/annotator/search", AnnotatorSearch.class); |
130 | 140 |
131 // router.attach("",redirector); router.attach("/annotator", | 141 // router.attach("",redirector); router.attach("/annotator", |
132 // ExtendedAnnotationInput.class); | 142 // ExtendedAnnotationInput.class); |
133 | 143 |
134 router.attach("/", AnnotatorInfo.class); | 144 router.attach("/", AnnotatorInfo.class); |
238 filename = sc.getRealPath(filename); | 248 filename = sc.getRealPath(filename); |
239 } | 249 } |
240 return filename; | 250 return filename; |
241 } | 251 } |
242 | 252 |
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 | |
243 } | 287 } |