comparison artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.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 190aa68ae7a8
children a077bb098eb4
comparison
equal deleted inserted replaced
303:190aa68ae7a8 304:40b64b4aafce
433 /** 433 /**
434 * Hooks that are executed after an artifact has advanced. 434 * Hooks that are executed after an artifact has advanced.
435 */ 435 */
436 protected List<Hook> postAdvanceHooks; 436 protected List<Hook> postAdvanceHooks;
437 437
438 protected List<LifetimeListener> lifetimeListeners;
439
438 /** 440 /**
439 * Default constructor. 441 * Default constructor.
440 */ 442 */
441 public ArtifactDatabaseImpl() { 443 public ArtifactDatabaseImpl() {
442 } 444 }
466 setupArtifactFactories(bootstrap); 468 setupArtifactFactories(bootstrap);
467 setupServices(bootstrap); 469 setupServices(bootstrap);
468 setupUserFactory(bootstrap); 470 setupUserFactory(bootstrap);
469 setupCallContextListener(bootstrap); 471 setupCallContextListener(bootstrap);
470 setupHooks(bootstrap); 472 setupHooks(bootstrap);
473 setupLifetimeListeners(bootstrap);
471 474
472 context = bootstrap.getContext(); 475 context = bootstrap.getContext();
473 context.put(GLOBAL_CONTEXT_KEY, this); 476 context.put(GLOBAL_CONTEXT_KEY, this);
474 477
475 exportSecret = bootstrap.getExportSecret(); 478 exportSecret = bootstrap.getExportSecret();
541 544
542 545
543 protected void setupHooks(FactoryBootstrap bootstrap) { 546 protected void setupHooks(FactoryBootstrap bootstrap) {
544 setPostFeedHook(bootstrap.getPostFeedHooks()); 547 setPostFeedHook(bootstrap.getPostFeedHooks());
545 setPostAdvanceHook(bootstrap.getPostAdvanceHooks()); 548 setPostAdvanceHook(bootstrap.getPostAdvanceHooks());
549 }
550
551 protected void setupLifetimeListeners(FactoryBootstrap bootstrap) {
552 this.lifetimeListeners = bootstrap.getLifetimeListeners();
546 } 553 }
547 554
548 /** 555 /**
549 * Used to extract the user factory from the bootstrap. 556 * Used to extract the user factory from the bootstrap.
550 */ 557 */
1717 boolean success = backend.loadAllArtifacts(callback); 1724 boolean success = backend.loadAllArtifacts(callback);
1718 if (!success) { 1725 if (!success) {
1719 throw new ArtifactDatabaseException(INTERNAL_ERROR); 1726 throw new ArtifactDatabaseException(INTERNAL_ERROR);
1720 } 1727 }
1721 } 1728 }
1729
1730 public void start() {
1731 if (lifetimeListeners == null || lifetimeListeners.isEmpty()) {
1732 return;
1733 }
1734
1735 for (LifetimeListener ltl: lifetimeListeners) {
1736 ltl.systemUp(context);
1737 }
1738
1739 Runtime.getRuntime().addShutdownHook(new Thread() {
1740 @Override
1741 public void run() {
1742 for (LifetimeListener ltl: lifetimeListeners) {
1743 ltl.systemDown(context);
1744 }
1745 }
1746 });
1747 }
1722 } 1748 }
1723 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : 1749 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org