Creating service MBeans

Service MBeans must expose a well-defined life cycle API that provides the ability to start, stop, and check the status of managed services.

Because MBeans are invoked via the JMX MBeanServer APIs, service MBeans are not required to implement a particular interface or extend a particular class to ensure life-cycle compliancy. However, they are required to implement the methods described in Table 14-2.

Table 14-2: MBean required methods

Method

Description

void start()

Starts the MBean.

void stop()

Stops the MBean.

int getState()

Returns the state of the MBean. The return values, as defined in JSR 77, can be:

  • 0 – STARTING

  • 1 – RUNNING

  • 2 – STOPPING

  • 4 – FAILED

The com.sybase.djc.management.jmx.services.ServiceSuport class is available to extend, if required. This class provides all the API methods described in Table 14-2 and Table 14-3. If you extend this class, you can override the methods defined in Table 14-3, and let the ServiceSupport class handle state management for you. The ServiceSupport class provides default implementations for all the methods listed in Table 14-3, so you can implement only the ones you need. The ServiceSupport class is in DJC_HOME/lib/eas-server.jar.

Table 14-3: MBean optional methods

Method

Description

void getLogfile()

Gets the service’s log file

void initService()

Initializes the resources

void refreshService()

Refreshes the MBean without restarting

void restartService()

Stops, then restarts the MBean

void startRecursiveService()

Starts dependent MBeans

void startService()

Starts the service

void stopService()

Stops the service

void terminateService()

Cleans up the resources