Develop custom services
To define a class that runs when an application server starts and shuts down, develop a custom service class and use the WAS administrative console to configure a custom service for an application server. When the application server starts, the custom service starts and initializes.
Perform the following steps to develop a custom service class:
Develop a custom service class that implements the com.ibm.websphere.runtime.CustomService interface. For more information on this interface, see The com.ibm.websphere.runtime.CustomService interface.
The properties that pass by the application server run-time to the initialize method can include a property, which specifies an external file that contains configuration for the service. The static variable externalConfigURLKey from the CustomService interface retrieves this property. In addition, the properties can contain any name-value pairs and other system administration configuration data for the service. The properties pass to the initialize method of the service as a Properties object.
There is also a shutdown method for the interface. Both methods of the CustomService interface declare that they may throw an exception, but no specific exception subclass is defined. If an exception is thrown during initialization, the run-time logs it, disables the custom service, and proceeds with starting the server.
Start the WAS administrative console. To start the console, open this URL in your browser:
http://your.server.name:port/adminwhere your.server.name is the hostname of your iSeries server and port is your administrative port number. See The administrative console topic for more information.
Expand Servers, and click Application Servers.
Click the server for which you want to configure the custom service.
Click Custom Services.
On the Custom Service page, click New.
On the Configuration page, specify the settings for the custom service.
See Custom services settings for more information.
If your custom services class requires a configuration file, specify the fully-qualified path name to that configuration file in the External Configuration URL field. This file name is passed into your custom service class.
Note: When you specify the class name for the custom service, specify the package-scoped class name. For example, if the custom service class has a package statement of package com.mycompany.customservices; and the class is ServerStartup, you would specify com.ibm.mycompany.customservices.ServerStartup in the Classname field.
Click OK.
Click Save on the toolbar to save the configuration.
Click Save again to update the master repository with your changes.
Click Logout on the toolbar.
Stop the application server, and restart the server.
Check the application server to ensure that the initialize method of the custom service ran as intended. Also ensure that the shutdown method performs as intended when the server stops.