Creating 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.
About this task
Custom services run in servants, not in
controllers. For example, because there can be more than one servant
started in the life of a server and these servants can be started
long after the server (controller) is up, as needed by WLM, a custom
service runs during the start of each servant.
If
you need to define a hook point that runs when a server starts and
shuts down, create 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.
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.
- The initialize and shutdown methods must return control to the runtime.
- No work is dispatched into the server instance until all custom service initialize methods return.
- The initialize and shutdown methods are called only once on each service, and once for each operating system process that makes up the server instance.
- Initialization of process level static data, without leaving the process, is supported.
- Only JDBC RMLT (resource manager local transaction) operations are supported. Every unit of work (UOW) must be completed before the methods return.
- Creation of threads is not supported.
- Creation of sockets and I/O, other than file I/O, is not supported.
- Running standard Java™ Platform, Enterprise Edition (Java EE) code, such as client code, servlets, and enterprise beans, is not supported.
- The Java Transaction API (JTA) interface is not available.
- This feature is available in Java EE server processes and distributed generic server processes only.
- While the runtime makes an effort to call shutdown, there is no guarantee that shutdown will be called prior to process termination.
- JNDI operations that request resources are not supported.
Procedure
Results
The custom service loads and initializes
whenever the server or node agent starts and stops.
The
custom service loads and initializes whenever the server starts and
shuts down.
Example
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.
Check the application server to
verify that the initialize and shutdown methods of the custom service
run the way that you want them to run.