comparison artifact-database/src/main/java/de/intevation/artifactdatabase/FactoryBootstrap.java @ 304:40b64b4aafce

Added lifetime listeners to be called when system is up and is going down. artifacts/trunk@2410 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Wed, 27 Jul 2011 13:51:30 +0000
parents b0a949d3fe09
children d96bcb40dbf9
comparison
equal deleted inserted replaced
303:190aa68ae7a8 304:40b64b4aafce
118 "/artifact-database/rest-server/http-server/text()"; 118 "/artifact-database/rest-server/http-server/text()";
119 119
120 public static final String DEFAULT_HTTP_SERVER = 120 public static final String DEFAULT_HTTP_SERVER =
121 "de.intevation.artifactdatabase.rest.Standalone"; 121 "de.intevation.artifactdatabase.rest.Standalone";
122 122
123 public static final String LIFETIME_LISTENERS =
124 "/artifact-database/lifetime-listeners/listener";
125
123 /** 126 /**
124 * Default export signing secret. 127 * Default export signing secret.
125 * <strong>PLEASE CHANGE THE SECRET VIA THE XPATH EXPORT_SECRET 128 * <strong>PLEASE CHANGE THE SECRET VIA THE XPATH EXPORT_SECRET
126 * IN THE CONFIGURATION.</strong>. 129 * IN THE CONFIGURATION.</strong>.
127 */ 130 */
161 protected CallContext.Listener callContextListener; 164 protected CallContext.Listener callContextListener;
162 165
163 protected List<Hook> postFeedHooks; 166 protected List<Hook> postFeedHooks;
164 167
165 protected List<Hook> postAdvanceHooks; 168 protected List<Hook> postAdvanceHooks;
169
170 protected List<LifetimeListener> lifetimeListeners;
166 171
167 /** 172 /**
168 * byte array holding the export signing secret. 173 * byte array holding the export signing secret.
169 */ 174 */
170 protected byte [] exportSecret; 175 protected byte [] exportSecret;
437 logger.error(cce.getLocalizedMessage(), cce); 442 logger.error(cce.getLocalizedMessage(), cce);
438 } 443 }
439 catch (IllegalAccessException iae) { 444 catch (IllegalAccessException iae) {
440 logger.error(iae.getLocalizedMessage(), iae); 445 logger.error(iae.getLocalizedMessage(), iae);
441 } 446 }
447 }
448
449 protected void loadLifetimeListeners() {
450 logger.info("loading lifetime listeners");
451
452 NodeList nodes = Config.getNodeSetXPath(LIFETIME_LISTENERS);
453
454 if (nodes == null) {
455 logger.debug("no lifetime listeners configure");
456 return;
457 }
458
459 List<LifetimeListener> ltls = new ArrayList<LifetimeListener>();
460
461 for (int i = 0, N = nodes.getLength(); i < N; ++i) {
462 Node node = nodes.item(i);
463 String className = node.getTextContent();
464 if (className == null
465 || (className = className.trim()).length() == 0) {
466 continue;
467 }
468 try {
469 Class clazz = Class.forName(className);
470 LifetimeListener listener =
471 (LifetimeListener)clazz.newInstance();
472
473 listener.setup(Config.getConfig());
474
475 lifetimeListeners.add(listener);
476 }
477 catch (ClassNotFoundException cnfe) {
478 logger.error(cnfe.getLocalizedMessage(), cnfe);
479 }
480 catch (InstantiationException ie) {
481 logger.error(ie.getLocalizedMessage(), ie);
482 }
483 catch (ClassCastException cce) {
484 logger.error(cce.getLocalizedMessage(), cce);
485 }
486 catch (IllegalAccessException iae) {
487 logger.error(iae.getLocalizedMessage(), iae);
488 }
489 }
490
491 lifetimeListeners = ltls;
442 } 492 }
443 493
444 protected void loadHooks() { 494 protected void loadHooks() {
445 logger.info("loading hooks"); 495 logger.info("loading hooks");
446 496
531 loadServiceFactories(); 581 loadServiceFactories();
532 loadUserFactory(); 582 loadUserFactory();
533 loadCallContextListener(); 583 loadCallContextListener();
534 loadHTTPServer(); 584 loadHTTPServer();
535 loadHooks(); 585 loadHooks();
586 loadLifetimeListeners();
536 } 587 }
537 588
538 /** 589 /**
539 * Returns the artifact collection factory. 590 * Returns the artifact collection factory.
540 * 591 *
604 } 655 }
605 656
606 public HTTPServer getHTTPServer() { 657 public HTTPServer getHTTPServer() {
607 return httpServer; 658 return httpServer;
608 } 659 }
660
661 public List<LifetimeListener> getLifetimeListeners() {
662 return lifetimeListeners;
663 }
609 } 664 }
610 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 665 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org