Creating service MBeans

Service MBeans must expose a well-defined lifecycle API that provides the ability to start, stop, and check the status of managed services. To create a service MBean:

  1. In the Systems Management Console, highlight MBeans, right-click, and select Add MBean.

  2. Follow the instructions in the Add MBean wizard.

    The wizard registers the MBean on the server, and configures the MBean to load on start-up.

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 13-5.

Table 13-5: 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.management.jmx.services.ServiceSupport class is available to extend, if required. This class provides all the API methods described in Table 13-5 and Table 13-6. If you extend this class, you can override the methods defined in Table 13-6, and let the ServiceSupport class handle state management for you. See “Service builder” for an example of how to do this. The ServiceSupport class provides default implementations for all the methods listed in Table 13-6, so you can implement only the ones you need. The ServiceSupport class is in ROOT/lib/sybasejmx.jar.

Table 13-6: 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