创建定制服务
可以为应用程序服务器创建一个或多个定制服务。各个定制服务都定义每当服务器启动和关闭时装入并初始化的类。这些类中的每个类都必须实现 com.ibm.websphere.runtime.CustomService 接口。在创建定制服务后,应使用管理控制台来对应用程序服务器配置该定制服务。
关于此任务
定制服务在服务方中运行,而不是在控制器中运行。例如,因为在服务器使用中可以启动多个服务方,且这些服务方可以在服务器(控制器)启动很久后启动,所以如 WLM 所需,在每个服务方启动期间运行定制服务。
如果需要定义服务器启动和关闭时运行的挂钩点,请创建定制服务类,然后使用管理控制台来配置定制服务实例。当应用程序服务器启动时,定制服务启动和初始化。
要定义每当服务器或 Node Agent 启动和关闭时运行的例程,请开发定制服务类,然后配置定制服务实例。当应用程序服务器或 Node Agent 启动时,定制服务启动和初始化。
以下是适用于该产品定制服务实现的限制列表。这些限制中的大多数仅适用于 initialize 方法:
- initialize 和 shutdown 方法必须将控制权返回给运行时。
- 没有工作分派给服务器实例,直到所有定制服务 initialize 方法返回。
- 在每个服务上仅调用一次 initialize 和 shutdown 方法,而且对于组成服务器实例的每个操作系统进程也仅调用一次。
- 支持进程级别静态数据的初始化,无须离开过程。
- 仅支持 JDBC RMLT(资源管理器局部事务)操作。在方法返回前,每个工作单元 (UOW) 必须完成。
- 不支持线程的创建。
- 不支持套接字和除文件 I/O 之外的 I/O 的创建。
- 不支持运行标准 Java™ Platform, Enterprise Edition (Java EE) 代码,例如,客户机代码、servlet 和企业 Bean。
- Java 事务 API(JTA)接口不可用。
- 此功能仅在 Java EE 服务器进程和分布式通用服务器进程中才可用。
- 当运行时尝试调用 shutdown 时,不保证 shutdown 将在进程终止前被调用。
- 不支持请求资源的 JNDI 操作。
过程
结果
每当服务器或 Node Agent 启动和停止时,定制服务都将装入并初始化。
每当服务器启动和关闭时,定制服务都将装入并初始化。
示例
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
}
下一步做什么
检查应用程序服务器或 Node Agent,以验证定制服务的 initialize 和 shutdown 方法是否按预期方式运行。
检查应用程序服务器,以验证定制服务的 initialize 和 shutdown 方法是否按预期方式运行。