Introduction

This example comes with an MBean and server. It shows how jobs can be configured to run and monitor this MBean.

Feature Status

FEATURE AVAILABILITY STARTING FROM RELEASE 1.3 FEATURE AVAILABILITY ENDING WITH RELEASE 1.10

JS-1315 - Getting issue details... STATUS

Downloads

Instructions

  • Download the JMX Remote Reference Implementation and the JMX Implementation from http://java.sun.com/javase/technologies/core/mntr-mgmt/javamanagement/download.jsp
  • Unzip all files from jmx.zip into the ./config/live folder of your JobScheduler.
  • Put sos.jmx.jar into the lib directory the JobScheduler.
  • Create a directory for the MBean server somewhere on your system and unzip jmx_server.zip into that directory.
  • Put jmxremote.jar, jmxremote_optional.jar, jmxri.jar (from the Sun downloads) and sos.howto.jar into that directory.
  • Open a shell and start the jmx server with server.sh or server.cmd
  • Open the config/factory.ini file of your job Scheduler and add the lib directories of the two Sun jmx downloads to the classpath. (E.g. add ":/home/test/jmx-1_2_1-bin/lib/*.jar:/home/test/jmx/jmxremote-1_0_1-bin/lib/*.jar" with ";" instead of ":" on Windows to the existing classpath)
  • Start the JobScheduler
  • Open the web interface of the JobScheduler in your browser using http://scheduler_host:scheduler_port

Asynchronous execution

The JobSchedulerJMXManager Job can run launch and check MBeans for ansynchronous execution.

  • Find the job samples/jmx/SOSSampleLaunch and click on it.
  • In the Job menu press "Start task now"

The job will now launch the MBean. Open the console window of the MBean Server to see the output of the MBean. Note that the job is also running. The job now periodically checks the state of the MBean and displays it on the JobScheduler Operations GUI. Should any problem occur with the MBean the Job will report an error and try to relaunch the MBean.

  • In the Job menu press "Stop"
  • Watch the console

The job will now cancel the Execution of the MBean. This might take a moment.

Synchronous execution with a standalone job

The JobSchedulerJMXManager Job can run execute Methods synchronously in an MBean.

  • Find the job samples/jmx/SOSSampleExecute and click on it.
  • In the Job menu press "Start task parameterized"
  • Set some parameters in the dialog ("foo=bar", whatever you like) and press "Submit".

The job will now execute an MBean function called "execute" and pass it's parameters to that function. Watch the output of the server console. You should be able to find your parameters there. Once the method has been exectued, the job will not be running anymore.

Synchronous execution in a job chain

The JobSchedulerJMXManager Job can be used as part of a job chain to execute Methods synchronously in an MBean as a step of a job chain.

  • Open the JOB CHAINS tab and enable "Show orders".
  • Find the job chain samples/jmx/scheduler_managed_beans.
  • Find the order SOSSampleExecute, open the order menu and choose "Start order now".

The job Scheduler will now first execute a simple shell job and then execute the "execute" function of the MBean. Open the order history and see the log of the order to confirm.

How it works

The JobSchedulerJMXManager job can be configured to perform different actions. The following actions are available:

Action      Explanation
startThe job creates the MBean on the server. It is recommended to have the server create the MBean as the job can only call createMBean without parameters.
stopThe job unregisters the MBean on the server. It is recommended to have the server create and unregister the MBean, though.
launchThe job calls the launch function of an MBean which is already created. The launch function is expected to make the MBean start it's asynchonous execution.
After launch has been executed, the MBean is expected to be in the running state.
checkThe job checks with the State attribute if an asynchonous execution of an MBean which has been started with the launch function is still running. The state is expected return running. If the state is not running or if another problem occurs checking the MBean, the job will report an error.
The name of the State attribute and the expected return value can be configured.
cancelThe job executes the cancel function on a running MBean. The cancel function is expected to cause the MBean to end it's asynchonous execution.
An orderjob will execute cancel in spooler_process. A standalone job will execute cancel in spooler_exit. This makes it possible to have an MBean end at the end of a period or to stop it manually using the "stop" command of the job menu.
executeThe job calls the execute function of an MBean which is already created. The execute function is expected to make the MBean start a synchonous execution. This means that the function call should only end when the task has been completed.
Parameters can be passed to the execute function (see main text of the job documentation). After execute has been executed, the MBean is expected to be in the pending state.


These actions call functions inside the MBean. The names of these functions can be configured, but the functions need to be implemented in the MBean implementation and exposed in the interface (except for start and stop.

Have a look at SOSSample.java and SOSSampleMBean.java to see how these functions are defined in the Interface SOSSampleMBean and implemented in SOSSample.

The execute function has one Properties Object as a parameter. The execute Method needs to have this signature, as the job will use a Properties Object to pass it's parameters (and the order parameters) to the MBean.

The launch function is expected to launch an asynchronous execution and return immediately. To achieve this, a thread of the SOSSampleThread class is created and launched. The thread is stopped in the launch function.

When the check action is configured, the job constantly checks the "State" attribute of the MBean. Note that all actions set the appropriate state which is expected by the job.

The MBean Server is implemented in Server.java. Note that the Server creates the MBean. The Job can also be used to create MBeans, but we recommend letting the server create the MBean as the Job does not pass any parameters for the creation to the server, thus only the standard constructor of an MBean could be used.

Have a look at the job definitions. The jobs are configured with <delay_after_error> elements. This causes the job to repeat in case of an error. For synchronous execution this means, that the function will be executed again. With the launch,check,cancel configuration of the asynchronous job, this will result in a re-launch of the job if an error occurs during one of the periodic check actions.

Next steps

  • Move the MBean server to another machine. Adjust the config/live/samples/jmx/JMXMP.connector.params.xml file to point to that other machine.
  • Start modifying the code of SOSSample.java to implement some real-life functions.
  • Take an existing java class and make it accessible as an MBean by creating an MBean interface for this class and adjusting the name of the execute method (or others) and the name of the State attribute by job configuration.

See also

  • No labels