Why and when to perform this task
To define a hook point to be run when a server starts and shuts down, you develop a custom service class and then use the administrative console to configure a custom service instance. When the application server starts, the custom service starts and initializes.
The following restrictions apply to the WebSphere custom services implementation:
Steps for this task
There is a shutdown method for the interface as well. Both methods of the interface declare that they may throw an exception, although no specific exception subclass is defined. If an exception is thrown, the run-time logs it, disables the custom service, and proceeds with starting the server.
To invoke a native library from the custom service, provide the path name in the Classpath field in addition to the path names that are used to locate the classes and JAR files for the custom service. Doing this adds the path name to the WAS extension classloader, which allows the custom service to locate and correctly load the native library.
Example
ServerInitpublic class ServerInit implements CustomService { /** * The initialize method is called by the application server run-time when the * server starts. The Properties object passed to this method must contain all * configuration information necessary for this service to initialize properly. * * @param configProperties java.util.Properties */ static final java.lang.String externalConfigURLKey = "com.ibm.websphere.runtime.CustomService.externalConfigURLKey"; static String ConfigFileName=""; public void initialize(java.util.Properties configProperties) throws Exception { if (configProperties.getProperty(externalConfigURLKey) != null) { ConfigFileName = configProperties.getProperty(externalConfigURLKey); } // Implement rest of initialize method }
/** * The shutdown method is called by the application server run-time when the * server begins its shutdown processing. * * @param configProperties java.util.Properties */ public void shutdown() throws Exception { // Implement shutdown method }