Mercurial > dive4elements > framework
diff 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 |
line wrap: on
line diff
--- a/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Wed Jul 27 09:32:26 2011 +0000 +++ b/artifact-database/src/main/java/de/intevation/artifactdatabase/ArtifactDatabaseImpl.java Wed Jul 27 13:51:30 2011 +0000 @@ -435,6 +435,8 @@ */ protected List<Hook> postAdvanceHooks; + protected List<LifetimeListener> lifetimeListeners; + /** * Default constructor. */ @@ -468,6 +470,7 @@ setupUserFactory(bootstrap); setupCallContextListener(bootstrap); setupHooks(bootstrap); + setupLifetimeListeners(bootstrap); context = bootstrap.getContext(); context.put(GLOBAL_CONTEXT_KEY, this); @@ -545,6 +548,10 @@ setPostAdvanceHook(bootstrap.getPostAdvanceHooks()); } + protected void setupLifetimeListeners(FactoryBootstrap bootstrap) { + this.lifetimeListeners = bootstrap.getLifetimeListeners(); + } + /** * Used to extract the user factory from the bootstrap. */ @@ -1719,5 +1726,24 @@ throw new ArtifactDatabaseException(INTERNAL_ERROR); } } + + public void start() { + if (lifetimeListeners == null || lifetimeListeners.isEmpty()) { + return; + } + + for (LifetimeListener ltl: lifetimeListeners) { + ltl.systemUp(context); + } + + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + for (LifetimeListener ltl: lifetimeListeners) { + ltl.systemDown(context); + } + } + }); + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :