UnboundID Server SDK

Ping Identity
UnboundID Server SDK Documentation
Getting Started with the UnboundID Server SDK

Performing Processing at Startup and Shutdown

The UnboundID Server SDK provides a number of mechanisms for performing custom processing when the server is starting up and/or shutting down. This section describes the differences between those mechanisms and the contexts in which they should be used.

Extension Initialization and Finalization

Whenever an extension is prepared for use in the server, then a method is invoked in that extension to allow it to perform any appropriate initialization (e.g., parsing arguments provided to the extension). If an extension is already defined and enabled in the server configuration, then this initialization will occur during server startup. Otherwise, it will be invoked whenever a new instance of the extension is added to the server configuration (if that extension is enabled at the time it is added), or when an existing disabled extension is updated so that it is enabled. If you need to perform processing whenever an extension is initialized, regardless of whether that initialization is performed at startup or after the server is already running, then the extension's initialize{ExtensionType} method should be used to accomplish that.

Similarly, each type of extension also provides a method that will be invoked whenever that extension will be taken out of service (e.g., to close any files or free up any other resources it might have been using). If an extension is disabled while the server is still running, then this finalization will occur at that time. Otherwise, it will be invoked as part of the server shutdown processing. If you need to perform processing whenever an extension is taken out of service, whether at shutdown or while the server is still running, then the extension's finalize{ExtensionType} method should be used to do that.

Startup and Shutdown Plugins

If you want to have a certain set of processing performed only at the time that the server is started rather than any time that an extension is initialized, then you should use a startup plugin (i.e., create a Java-based or scripted plugin that implements the doStartup method).

Note that if you include code in the initializePlugin method, then it will be invoked whenever the plugin is initialized, regardless of whether that occurs at startup or after the server is already running. If it is at startup, then the initializePlugin method will be invoked before the doStartup method. If the plugin is added to the server after it has already been started, then the initializePlugin method will be invoked at that time, but the doStartup method will not be invoked until the next time the server is started.

By default, startup plugins will be invoked very late in the startup process, after nearly all other server components have been initialized but before the server has begun accepting client connections. This helps ensure that any other components the plugin might need to reference will be available for use. However, if it is necessary for that to occur earlier in the startup process, then that can be accomplished by implementing the getStartupDependencies method and returning a set containing the minimal set of dependencies that must be satisfied before the processing should be invoked.

Similarly, plugins can implement a doShutdown method, which will be invoked only when the server is shutting down. This processing will be invoked very early in the shutdown process after the server has stopped accepting new connections and closed all existing connections, but before shutting down most other components.

If a plugin implements both the doShutdown and finalizePlugin methods, then both methods will be invoked at shutdown if the plugin is enabled, with the doShutdown method called before the finalizePlugin method. However, if the plugin is disabled while the server is still running, then the finalizePlugin method will be invoked at that time, and the doShutdown method will not be invoked when the server is shut down.

Server Shutdown Listeners

If you want to have a non-plugin extension perform some kind of processing only when the server is shutting down, then you can have that extension implement the ServerShutdownListener interface and use the ServerContext.registerShutdownListener method to register that listener to be invoked whenever the server is shut down.

Note that if an extension is registered as a shutdown listener, then both the processServerShutdown method and the extension's finalize{ExtensionType} method will be invoked (in that order) at server shutdown. Also note that even if an extension is disabled, if it has previously been registered as a shutdown listener, then its processServerShutdown method will be invoked unless it is also deregistered as a shutdown listener in its finalize{ExtensionType} method.