diff options
author | James Moger <james.moger@gitblit.com> | 2014-05-15 17:14:41 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-05-15 17:14:41 -0400 |
commit | c59584f08d46de4a1b9515f4fd1535426ce603b3 (patch) | |
tree | dac02f17739e4edeb1d3598cb369f0522f10691e | |
parent | 032d8228dd61867c792c655e506aa8fae7026fd9 (diff) | |
download | gitblit-c59584f08d46de4a1b9515f4fd1535426ce603b3.tar.gz gitblit-c59584f08d46de4a1b9515f4fd1535426ce603b3.zip |
Add startup/shutdown LifeCycle extension point
-rw-r--r-- | releases.moxie | 3 | ||||
-rw-r--r-- | src/main/java/com/gitblit/extensions/LifeCycleListener.java | 43 | ||||
-rw-r--r-- | src/main/java/com/gitblit/servlet/GitblitContext.java | 20 | ||||
-rw-r--r-- | src/site/plugins_extensions.mkd | 31 |
4 files changed, 95 insertions, 2 deletions
diff --git a/releases.moxie b/releases.moxie index 049a2826..718e79c5 100644 --- a/releases.moxie +++ b/releases.moxie @@ -14,7 +14,6 @@ r24: { - Fix failure to generate SSH server keys on ARM (issue-426, ticket-70) - Fix flotr2 chart generation failure if a label contained a single-quote (ticket-77) changes: - - Added extension points for top nav links, root-level pages, repository nav links, user menu links, and http request filters (ticket-23) - Split the pages servlet into a raw servlet and a pages servlet. All raw links now use the raw servlet (issue-413, ticket-49) - Drop deprecated --set-upstream syntax for -u (ticket-59) - BARNUM: Prune deleted branches on fetch (git fetch -p) (ticket-60) @@ -27,9 +26,11 @@ r24: { - Add My Tickets page (issue-215, ticket-15) - Added CRUD functionality for Ticket Milestones (ticket-17) - Implemented Ticket migration tool to move between backends (ticket-19) + - Added extension points for top nav links, root-level pages, repository nav links, user menu links, and http request filters (ticket-23) - Add FORK_REPOSITORY RPC request type (issue-371, pr-161, ticket-65) - Add object type (ot) parameter for RSS queries to retrieve tag details (pr-165, ticket-66) - Add setting to allow STARTTLS without requiring SMTPS (pr-183) + - Added an extension point for monitoring onStartup and onShutdown (ticket-79) dependencyChanges: - Update to javax.mail 1.5.1 (issue-417, ticket-58) contributors: diff --git a/src/main/java/com/gitblit/extensions/LifeCycleListener.java b/src/main/java/com/gitblit/extensions/LifeCycleListener.java new file mode 100644 index 00000000..84c7348d --- /dev/null +++ b/src/main/java/com/gitblit/extensions/LifeCycleListener.java @@ -0,0 +1,43 @@ +/* + * Copyright 2014 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.extensions; + +import ro.fortsoft.pf4j.ExtensionPoint; + +/** + * Extension point to allow plugins to listen to major Gitblit lifecycle events. + * + * @author James Moger + * @since 1.6.0 + */ +public abstract class LifeCycleListener implements ExtensionPoint { + + /** + * Called after all internal managers have been started. + * This may be useful for reporting "server is ready" to a monitoring system. + * + * @since 1.6.0 + */ + public abstract void onStartup(); + + /** + * Called when the servlet container is gracefully shutting-down the webapp. + * This is called before the internal managers are stopped. + * + * @since 1.6.0 + */ + public abstract void onShutdown(); +} diff --git a/src/main/java/com/gitblit/servlet/GitblitContext.java b/src/main/java/com/gitblit/servlet/GitblitContext.java index ebe2cc2b..110e553c 100644 --- a/src/main/java/com/gitblit/servlet/GitblitContext.java +++ b/src/main/java/com/gitblit/servlet/GitblitContext.java @@ -38,6 +38,7 @@ import com.gitblit.IStoredSettings; import com.gitblit.Keys; import com.gitblit.WebXmlSettings; import com.gitblit.dagger.DaggerContext; +import com.gitblit.extensions.LifeCycleListener; import com.gitblit.manager.IAuthenticationManager; import com.gitblit.manager.IFederationManager; import com.gitblit.manager.IGitblit; @@ -191,6 +192,15 @@ public class GitblitContext extends DaggerContext { logger.info(""); logger.info("All managers started."); logger.info(""); + + IPluginManager pluginManager = injector.get(IPluginManager.class); + for (LifeCycleListener listener : pluginManager.getExtensions(LifeCycleListener.class)) { + try { + listener.onStartup(); + } catch (Throwable t) { + logger.error(null, t); + } + } } private String lookupBaseFolderFromJndi() { @@ -225,6 +235,16 @@ public class GitblitContext extends DaggerContext { @Override protected void destroyContext(ServletContext context) { logger.info("Gitblit context destroyed by servlet container."); + + IPluginManager pluginManager = getManager(IPluginManager.class); + for (LifeCycleListener listener : pluginManager.getExtensions(LifeCycleListener.class)) { + try { + listener.onShutdown(); + } catch (Throwable t) { + logger.error(null, t); + } + } + for (IManager manager : managers) { logger.debug("stopping {}", manager.getClass().getSimpleName()); manager.stop(); diff --git a/src/site/plugins_extensions.mkd b/src/site/plugins_extensions.mkd index 7bf63c17..99b6400f 100644 --- a/src/site/plugins_extensions.mkd +++ b/src/site/plugins_extensions.mkd @@ -54,7 +54,7 @@ public class ExamplePlugin extends GitblitPlugin { } /** - * You can also create Webapp plugins that register mounted pages. + * You can also create Webapp plugins that register pages. */ public class ExampleWicketPlugin extends GitblitWicketPlugin { @Override @@ -285,3 +285,32 @@ public class MyNavLink extends NavLinkExtension { } } ``` + +### Lifecycle Listener + +*SINCE 1.6.0* + +You can provide a lifecycle listener to be notified when Gitblit has completely started and just before Gitblit is gracefully terminated. + +```java +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import ro.fortsoft.pf4j.Extension; +import com.gitblit.extensions.LifeCycleListener; + +@Extension +public class MyLifeCycleListener extends LifeCycleListener { + + final Logger log = LoggerFactory.getLogger(getClass()); + + @Override + public void onStartup() { + log.info("Gitblit is Ready!!"); + } + + @Override + public void onShutdown() { + log.info("Gitblit is Going Down!!"); + } +} +```
\ No newline at end of file |