Operating Systems: i5/OS
             Personalize the table of contents and search results

 

Create custom services

 

You can create one or more custom services for an application server. Each custom services defines a class that is loaded and initialized whenever the server starts and shuts down. Each of these classes must implement the com.ibm.websphere.runtime.CustomService interface. After you create a custom service, use the administrative console to configure that custom service for your application servers.

 

Overview

To define a routine that runs whenever a server or node agent starts and shuts down, you develop a custom service class and then configure a custom service instance. When the application server or node agent starts, the custom service starts and initializes. Following is a list of restrictions that apply to the WebSphere Application Server custom services implementation. Most of these restrictions apply only to the initialize method:

 

Procedure

  1. Develop a custom service class that implements the com.ibm.websphere.runtime.CustomService interface. The com.ibm.websphere.runtime.CustomService interface includes an initialize and shutdown methods. The application server uses the initialize method to pass properties to the custom service. These properties can include:

    Both the initialize and shutdown methods declare that they might create an exception, although no specific exception subclass is defined. If either method creates an exception, the runtime logs the exception, disables the custom service, and continues to start the server.

  2. Configure the custom service.

    In the administrative console, click Servers > Application Servers, and then under Server Infrastructure, click Custom Services > New. Then, on the settings page for a custom service instance, create a custom service configuration for an existing application server or node agent, supplying the name of the class implemented. If your custom service class requires a configuration file, specify the fully-qualified path name to that configuration file in the externalConfigURL field. This file name is passed into your custom service class.

    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. This procedure adds the path name to the extension classloader, which allows the custom service to locate and correctly load the native library.

  3. Stop the application server, and then restart it.

    If you are developing a custom service for an application server, stop the application server, and then restart the server.

    If you are developing a custom service for a node agent, stop and then restart the processing of the node agent. In the administrative console, click System Administration > Node Agents, select the node agent you want to stop, and then click Stop. To restart the node agent, select the node agent you want to restart, and click Restart.

 

Results

Each custom services defines a class that is loaded and initialized whenever the server starts and shuts down.

The custom service loads and initializes whenever the server or node agent starts and stops.

 

Example

As previously mentioned, your custom services class must implement the com.ibm.websphere.runtime.CustomService interface. In addition, your class must implement the initialize and shutdown methods. The following example, shows the code that declares the class ServerInit that implements your custom service. This code assumes that your custom service class needs a configuration file. This example also includes the code that accesses the external configuration file. If your class does not require a configuration file, you do not have to include the configProperties portion of this code.

public class ServerInit implements com.ibm.websphere.runtime.CustomService
{
/**
* The initialize method is called by the application server runtime when the
* server starts. The Properties object that the application server passes
* to this method must contain all of  the configuration information that this 
* service needs 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 runtime when the
* server begins its shutdown processing.
*
    public void shutdown() throws Exception
    {
        // Implement shutdown method
    }

 

What to do next

Check the application server or node agent to verify that the initialize and shutdown methods of the custom service run the way that you want them to run.


}
Custom service collection

 

Related concepts


Developer API documentation

 

Related tasks


Stopping an application server
Starting an application server
Administering application servers