Mercurial > hg > AnnotationManagerN4J
annotate src/main/java/de/mpiwg/itgroup/annotations/restlet/BaseRestlet.java @ 71:326369d4bc4d
trying restlet 2.1. doesn't work yet.
author | casties |
---|---|
date | Fri, 07 Mar 2014 13:48:50 +0100 |
parents | 2b1e6df5e21a |
children | 4c2cea836bc0 |
rev | line source |
---|---|
18 | 1 package de.mpiwg.itgroup.annotations.restlet; |
2 | |
70 | 3 /* |
4 * #%L | |
5 * AnnotationManager | |
6 * %% | |
7 * Copyright (C) 2012 - 2014 MPIWG Berlin | |
8 * %% | |
9 * This program is free software: you can redistribute it and/or modify | |
10 * it under the terms of the GNU Lesser General Public License as | |
11 * published by the Free Software Foundation, either version 3 of the | |
12 * License, or (at your option) any later version. | |
13 * | |
14 * This program is distributed in the hope that it will be useful, | |
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 * GNU General Lesser Public License for more details. | |
18 * | |
19 * You should have received a copy of the GNU General Lesser Public | |
20 * License along with this program. If not, see | |
21 * <http://www.gnu.org/licenses/lgpl-3.0.html>. | |
22 * #L% | |
23 * Author: Robert Casties (casties@mpiwg-berlin.mpg.de) | |
24 */ | |
25 | |
18 | 26 import java.io.File; |
27 import java.io.FileInputStream; | |
28 import java.io.FileNotFoundException; | |
29 import java.io.IOException; | |
30 import java.io.InputStream; | |
31 import java.util.Hashtable; | |
32 import java.util.Properties; | |
71 | 33 import java.util.concurrent.ConcurrentMap; |
18 | 34 |
35 import javax.naming.NamingEnumeration; | |
36 import javax.naming.NamingException; | |
37 import javax.naming.directory.Attribute; | |
38 import javax.naming.directory.DirContext; | |
39 import javax.naming.directory.InitialDirContext; | |
40 import javax.naming.directory.SearchControls; | |
41 import javax.naming.directory.SearchResult; | |
42 import javax.servlet.ServletContext; | |
43 | |
44 import org.apache.log4j.BasicConfigurator; | |
45 import org.apache.log4j.Logger; | |
46 import org.neo4j.graphdb.GraphDatabaseService; | |
66
5b568de5ee0d
updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents:
60
diff
changeset
|
47 import org.neo4j.graphdb.factory.GraphDatabaseBuilder; |
18 | 48 import org.neo4j.graphdb.factory.GraphDatabaseFactory; |
66
5b568de5ee0d
updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents:
60
diff
changeset
|
49 import org.neo4j.graphdb.factory.GraphDatabaseSettings; |
5b568de5ee0d
updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents:
60
diff
changeset
|
50 import org.neo4j.kernel.GraphDatabaseAPI; |
18 | 51 import org.neo4j.server.WrappingNeoServerBootstrapper; |
52 import org.restlet.Application; | |
53 import org.restlet.Context; | |
71 | 54 import org.restlet.Restlet; |
55 import org.restlet.data.LocalReference; | |
18 | 56 |
57 import de.mpiwg.itgroup.annotations.neo4j.AnnotationStore; | |
58 | |
59 public abstract class BaseRestlet extends Application { | |
60 | |
61 public static Logger logger = Logger.getLogger(BaseRestlet.class); | |
62 | |
63 /** | |
57
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
64 * Properties holding consumer keys and secrets. |
18 | 65 */ |
66 protected Properties consumerKeys; | |
71 | 67 public String CONSUMER_KEYS_PATH = "consumerkeys.property"; |
18 | 68 public static final String CONSUMERKEYS_KEY = "annotationmanager.consumerkeys"; |
69 | |
57
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
70 /** |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
71 * Properties holding server config. |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
72 */ |
18 | 73 protected Properties serverConfig; |
71 | 74 public String CONFIG_PROPS_PATH = "serverconfig.property"; |
18 | 75 public static final String SERVERCONFIG_KEY = "annotationmanager.serverconfig"; |
76 | |
57
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
77 /** |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
78 * database instance; |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
79 */ |
18 | 80 protected GraphDatabaseService graphDb; |
81 public static final String GRAPHDB_KEY = "annotationmanager.graphdb"; | |
82 public static final String GRAPHDB_PATH_KEY = "annotationmanager.graphdb.path"; | |
71 | 83 public String graphdbPath = "neo4j-annotation-db"; |
18 | 84 |
57
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
85 /** |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
86 * database interface server instance. |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
87 */ |
18 | 88 protected WrappingNeoServerBootstrapper srv; |
89 public static final String GRAPHDBSRV_KEY = "annotationmanager.graphdb.srv"; | |
90 | |
57
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
91 /** |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
92 * annotation store instance. |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
93 */ |
18 | 94 protected AnnotationStore store; |
95 public static final String ANNSTORE_KEY = "annotationmanager.store"; | |
96 | |
57
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
97 /** |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
98 * LDAP server URI (for looking up full user names). |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
99 */ |
18 | 100 protected String ldapServerUrl; |
101 public static final String LDAP_SERVER_KEY = "annotationmanager.ldapserver.url"; | |
102 | |
50 | 103 public static final String ADMIN_USER_KEY = "annotationmanager.admin.user"; |
104 public static final String ADMIN_PASSWORD_KEY = "annotationmanager.admin.password"; | |
105 | |
18 | 106 /** |
57
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
107 * run in authorization mode i.e. with tokens. |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
108 */ |
58 | 109 protected boolean authorizationMode = false; |
57
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
110 public static final String AUTHORIZATION_MODE_KEY = "annotationmanager.authorization"; |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
111 |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
112 /** |
58 | 113 * prefix to create uris for tags in store. |
114 */ | |
115 public static String TAGS_URI_PREFIX = ""; | |
116 public static final String TAGS_URI_KEY = "annotationmanager.uris.tags"; | |
117 | |
118 /** | |
119 * prefix to create uris for persons in store. | |
120 */ | |
121 public static String PERSONS_URI_PREFIX = ""; | |
122 public static final String PERSONS_URI_KEY = "annotationmanager.uris.persons"; | |
123 | |
124 /** | |
125 * prefix to create uris for groups in store. | |
126 */ | |
127 public static String GROUPS_URI_PREFIX = ""; | |
128 public static final String GROUPS_URI_KEY = "annotationmanager.uris.groups"; | |
129 | |
59
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
58
diff
changeset
|
130 public static final String ANNOTATIONS_URI_KEY = "annotationmanager.uris.annotations"; |
e2f86ef9b871
make annotation uri in store configurable. fix npe with no tags.
casties
parents:
58
diff
changeset
|
131 |
58 | 132 /** |
18 | 133 * constructor |
134 * | |
135 * @param context | |
136 */ | |
137 public BaseRestlet(Context context) { | |
138 super(context); | |
71 | 139 configure(context); |
18 | 140 } |
141 | |
142 /** | |
143 * Configures the restlet. | |
144 * Reads serverConfig, consumerKeys and graphDb config from config files and starts graphDb. | |
145 * Uses config from webapp context if already initialized. | |
71 | 146 * @param context |
18 | 147 */ |
71 | 148 protected void configure(Context context) { |
149 Context ctx = Context.getCurrent(); | |
150 ConcurrentMap<String, Object> attrs = ctx.getAttributes(); | |
151 ServletContext sc = null; | |
152 if (context != null) { | |
153 Restlet a = context.getServerDispatcher(); | |
154 Context b = a.getContext(); | |
155 ConcurrentMap<String, Object> c = b.getAttributes(); | |
156 sc = (ServletContext) context.getServerDispatcher().getContext().getAttributes() | |
18 | 157 .get("org.restlet.ext.servlet.ServletContext"); |
71 | 158 } |
159 if (attrs != null) { | |
160 if (attrs.get("annotationserver.log4j.configured") == null) { | |
18 | 161 // TODO: is this the right place to run the log4j configurator? |
162 BasicConfigurator.configure(); | |
71 | 163 attrs.put("annotationserver.log4j.configured", "done"); |
18 | 164 } |
165 logger.info(getVersion() + " starting..."); | |
166 | |
167 /* | |
168 * read config from webapp | |
169 */ | |
71 | 170 serverConfig = (Properties) attrs.get(SERVERCONFIG_KEY); |
18 | 171 if (serverConfig == null) { |
172 serverConfig = new Properties(); | |
173 InputStream ps = getResourceAsStream(sc, CONFIG_PROPS_PATH); | |
174 if (ps != null) { | |
175 logger.debug("loading config from " + CONFIG_PROPS_PATH); | |
176 try { | |
177 serverConfig.load(ps); | |
178 /* | |
179 * read serverconfig options | |
180 */ | |
181 graphdbPath = serverConfig.getProperty(GRAPHDB_PATH_KEY, graphdbPath); | |
182 ldapServerUrl = serverConfig.getProperty(LDAP_SERVER_KEY, null); | |
60
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
183 /* |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
184 * uri prefixes |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
185 */ |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
186 if (serverConfig.containsKey(PERSONS_URI_KEY)) { |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
187 BaseRestlet.PERSONS_URI_PREFIX = serverConfig.getProperty(PERSONS_URI_KEY); |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
188 } |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
189 if (serverConfig.containsKey(GROUPS_URI_KEY)) { |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
190 BaseRestlet.GROUPS_URI_PREFIX = serverConfig.getProperty(GROUPS_URI_KEY); |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
191 } |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
192 if (serverConfig.containsKey(TAGS_URI_KEY)) { |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
193 BaseRestlet.TAGS_URI_PREFIX = serverConfig.getProperty(TAGS_URI_KEY); |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
194 } |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
195 if (serverConfig.containsKey(ANNOTATIONS_URI_KEY)) { |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
196 AnnotationStore.ANNOTATION_URI_PREFIX = serverConfig.getProperty(ANNOTATIONS_URI_KEY); |
99d9afcfd04d
configuration of uri prefixes was completely broken.
casties
parents:
59
diff
changeset
|
197 } |
18 | 198 } catch (IOException e) { |
199 logger.warn("Error loading server config: ", e); | |
200 } | |
201 logger.debug("config: " + serverConfig); | |
202 } else { | |
203 logger.error("Unable to get resource " + CONFIG_PROPS_PATH); | |
204 } | |
205 // store config | |
71 | 206 attrs.put(SERVERCONFIG_KEY, serverConfig); |
18 | 207 } |
208 // look for database service in context | |
71 | 209 graphDb = (GraphDatabaseService) attrs.get(GRAPHDB_KEY); |
18 | 210 if (graphDb == null) { |
211 /* | |
212 * open database | |
213 */ | |
214 String dbFn = getResourcePath(sc, graphdbPath); | |
215 if (dbFn != null) { | |
216 logger.debug("opening DB " + dbFn); | |
66
5b568de5ee0d
updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents:
60
diff
changeset
|
217 GraphDatabaseBuilder graphDbBuilder = new GraphDatabaseFactory().newEmbeddedDatabaseBuilder(dbFn); |
5b568de5ee0d
updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents:
60
diff
changeset
|
218 graphDbBuilder.setConfig(GraphDatabaseSettings.allow_store_upgrade, "true"); |
5b568de5ee0d
updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents:
60
diff
changeset
|
219 graphDb = graphDbBuilder.newGraphDatabase(); |
18 | 220 registerShutdownHook(graphDb); |
221 // store in context | |
71 | 222 attrs.put(GRAPHDB_KEY, graphDb); |
18 | 223 // AnnotationStore |
224 store = new AnnotationStore(graphDb); | |
71 | 225 attrs.put(ANNSTORE_KEY, store); |
18 | 226 // admin server |
66
5b568de5ee0d
updated to new Neo4J version 2.0. doesn't use new features. problems with neo4j admin web ui.
casties
parents:
60
diff
changeset
|
227 srv = new WrappingNeoServerBootstrapper((GraphDatabaseAPI) graphDb); |
18 | 228 logger.debug("Starting DB admin server..."); |
229 // store in context | |
71 | 230 attrs.put(GRAPHDBSRV_KEY, srv); |
18 | 231 srv.start(); |
232 } else { | |
233 logger.error("Unable to get resource " + dbFn); | |
234 } | |
22 | 235 } else { |
236 // get existing AnnotationStore | |
71 | 237 store = (AnnotationStore) attrs.get(ANNSTORE_KEY); |
18 | 238 } |
239 /* | |
240 * read consumerKeys from webapp | |
241 */ | |
71 | 242 consumerKeys = (Properties) attrs.get(CONSUMERKEYS_KEY); |
18 | 243 if (consumerKeys == null) { |
244 consumerKeys = new Properties(); | |
245 InputStream ps = getResourceAsStream(sc, CONSUMER_KEYS_PATH); | |
246 if (ps != null) { | |
247 logger.debug("loading consumer keys from " + CONSUMER_KEYS_PATH); | |
248 try { | |
249 consumerKeys.load(ps); | |
250 } catch (IOException e) { | |
251 // TODO Auto-generated catch block | |
252 e.printStackTrace(); | |
253 } | |
254 logger.debug("consumer keys: " + consumerKeys); | |
255 } else { | |
256 logger.error("Unable to get resource " + CONSUMER_KEYS_PATH); | |
257 } | |
258 // store config | |
71 | 259 attrs.put(CONSUMERKEYS_KEY, consumerKeys); |
18 | 260 } |
261 } else { | |
262 logger.error("Unable to get ServletContext!"); | |
263 } | |
264 } | |
265 | |
266 public abstract String getVersion(); | |
267 | |
268 /** | |
57
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
269 * @return the authorizationMode |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
270 */ |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
271 public boolean isAuthorizationMode() { |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
272 return authorizationMode; |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
273 } |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
274 |
4efb21cf0ce0
new non-authorized mode without tokens. enabled by default. configured with annotationmanager.authorization=false property.
casties
parents:
50
diff
changeset
|
275 /** |
19 | 276 * @return the store |
277 */ | |
278 public AnnotationStore getAnnotationStore() { | |
279 return store; | |
280 } | |
281 | |
282 /** | |
18 | 283 * returns consumer secret for consumer key. returns null if consumer key |
284 * doesn't exist. | |
285 * | |
286 * @param consumerKey | |
287 * @return | |
288 */ | |
289 public String getConsumerSecret(String consumerKey) { | |
290 return consumerKeys.getProperty(consumerKey); | |
291 } | |
292 | |
293 /** | |
294 * Hole den vollen Benutzernamen aus dem LDAP | |
295 * | |
296 * @param creator | |
297 * @return | |
298 */ | |
299 public String getFullNameFromLdap(String creator) { | |
300 String retString = creator; // falls nichts gefunden wird einfach den | |
301 // creator zurueckgeben | |
302 if (ldapServerUrl == null) { | |
303 return retString; | |
304 } | |
305 Hashtable<String, String> env = new Hashtable<String, String>(); | |
306 String sp = "com.sun.jndi.ldap.LdapCtxFactory"; | |
307 env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, sp); | |
308 env.put(javax.naming.Context.PROVIDER_URL, ldapServerUrl); | |
309 | |
310 DirContext dctx; | |
311 try { | |
312 dctx = new InitialDirContext(env); | |
313 } catch (NamingException e) { | |
314 logger.error("Error in getFullNameFromLDAP!", e); | |
315 return retString; | |
316 } | |
317 | |
318 String base = "ou=people"; | |
319 | |
320 SearchControls sc = new SearchControls(); | |
321 String[] attributeFilter = { "cn", "mail" }; | |
322 sc.setReturningAttributes(attributeFilter); | |
323 sc.setSearchScope(SearchControls.SUBTREE_SCOPE); | |
324 | |
325 String filter = "(uid=" + creator + ")"; | |
326 | |
327 try { | |
328 NamingEnumeration<SearchResult> results = dctx.search(base, filter, sc); | |
329 while (results.hasMore()) { | |
330 SearchResult sr = (SearchResult) results.next(); | |
331 javax.naming.directory.Attributes attrs = sr.getAttributes(); | |
332 | |
333 Attribute attr = attrs.get("cn"); | |
334 retString = (String) attr.get(); | |
335 } | |
336 } catch (NamingException e) { | |
337 logger.error("Error in getFullNameFromLDAP!", e); | |
338 } | |
339 | |
340 try { | |
341 dctx.close(); | |
342 } catch (NamingException e) { | |
343 logger.error("Error in getFullNameFromLDAP!", e); | |
344 } | |
345 return retString; | |
346 } | |
347 | |
348 /** | |
349 * returns resource from path (in webapp) as InputStream. | |
350 * | |
351 * @param sc | |
352 * @param path | |
353 * @return | |
354 */ | |
355 protected InputStream getResourceAsStream(ServletContext sc, String path) { | |
71 | 356 InputStream ps = null; |
357 if (sc == null) { | |
358 ps = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); | |
359 } else { | |
360 ps = sc.getResourceAsStream(path); | |
361 if (ps == null) { | |
362 // try as file | |
363 File pf = new File(sc.getRealPath(path)); | |
364 if (pf != null) { | |
365 logger.debug("trying file for: " + pf); | |
366 try { | |
367 ps = new FileInputStream(pf); | |
368 } catch (FileNotFoundException e) { | |
369 logger.error(e); | |
370 } | |
18 | 371 } |
372 } | |
373 } | |
374 return ps; | |
375 } | |
376 | |
377 /** | |
378 * get a real file name for a web app file pathname. | |
379 * | |
380 * If filename starts with "/" its treated as absolute else the path is | |
381 * appended to the base directory of the web-app. | |
382 * | |
383 * @param filename | |
384 * @param sc | |
385 * @return | |
386 */ | |
387 public static String getResourcePath(ServletContext sc, String filename) { | |
388 File f = new File(filename); | |
389 // is the filename absolute? | |
71 | 390 if (!f.isAbsolute() && sc != null) { |
18 | 391 // relative path -> use getRealPath to resolve in webapp |
392 filename = sc.getRealPath(filename); | |
393 } | |
394 return filename; | |
395 } | |
396 | |
397 /* | |
398 * (non-Javadoc) | |
399 * | |
400 * @see org.restlet.Application#stop() | |
401 */ | |
402 @Override | |
403 public synchronized void stop() throws Exception { | |
404 /* | |
405 * trying to clean up databases, not sure if this is the right way... | |
406 */ | |
407 if (srv != null) { | |
408 logger.debug("Stopping DB admin server..."); | |
409 srv.stop(); | |
410 srv = null; | |
411 } | |
412 if (graphDb != null) { | |
413 logger.debug("Stopping DB..."); | |
414 graphDb.shutdown(); | |
415 graphDb = null; | |
416 } | |
417 super.stop(); | |
418 } | |
419 | |
420 private static void registerShutdownHook(final GraphDatabaseService graphDb) { | |
421 // Registers a shutdown hook for the Neo4j instance so that it | |
422 // shuts down nicely when the VM exits (even if you "Ctrl-C" the | |
423 // running example before it's completed) | |
424 Runtime.getRuntime().addShutdownHook(new Thread() { | |
425 @Override | |
426 public void run() { | |
427 graphDb.shutdown(); | |
428 } | |
429 }); | |
430 } | |
431 | |
432 } |