Class JMXClientJob

All Implemented Interfaces:
Runnable, ArooaContextAware, ArooaSessionAware, BeanDirectoryOwner, PropertyChangeNotifier, Iconic, RemoteDirectoryOwner, ConsoleArchiver, LogArchiver, LogEnabled, Resettable, Stateful, Stoppable, Structural

public class JMXClientJob extends ClientBase implements Structural, LogArchiver, ConsoleArchiver, RemoteDirectoryOwner
Author:
Rob Gordon

Description

Connect to an Oddjob JMXServerJob. This job allows remote jobs to be monitored and controlled from a local Oddjob.

This service will run until it is manually stopped or until the connection to the remote server is lost. If this job is stopped it's state will be COMPLETE, if the connection is lost the state state will be EXCEPTION.

To access and control jobs on a server from within a configuration file this client must have an id. If the client has an id of 'freds-pc' and the job on the server has an id of 'freds-job'. The job on the server can be accessed from the client using the expression ${freds-pc/freds-job}.

Example

Connect to a remote server that is using the Platform MBean Server. This example also demonstrates using the value of a remote jobs property.

<oddjob id="this" xmlns:jmx="http://rgordon.co.uk/oddjob/jmx">

  <job>

    <sequential>

      <jobs>

        <jmx:client id="remote" connection="${this.args[0]}"/>

        <echo>${remote/echo.text}</echo>

        <stop job="${remote}"/>

      </jobs>

    </sequential>

  </job>

</oddjob>

Note that the StopJob is required otherwise Oddjob wouldn't exit. An Alternative to using stop, would be to make the client a child of a SequentialJob with an ServiceManagerStateOp operator.

Here's an example of the command used to launch it:

 java -jar C:\Users\rob\projects\oddjob\run-oddjob.jar -f C:\Users\rob\projects\oddjob\test\java\org\oddjob\jmx\PlatformMBeanClientExample.xml localhost:13013
 

This configuration is the client side of the first example in JMXServerJob.To create a connection to a remote server that is using an RMI registry using the full form of the JMX URL.

<jmx:client id="freds-pc" name="Connection to Freds PC" url="service:jmx:rmi:///jndi/rmi://${hosts.freds-pc}/freds-oddjob-server" xmlns:jmx="http://rgordon.co.uk/oddjob/jmx"/>
Connect, run a remote job, and disconnect.

<oddjob>

  <job>

    <sequential>

      <jobs>

        <jmx:client id="freds-pc" name="Oddjob Client" url="service:jmx:rmi:///jndi/rmi://${hosts.freds-pc}/freds-oddjob-server" xmlns:jmx="http://rgordon.co.uk/oddjob/jmx"/>

        <run job="${freds-pc/server-jobs/greeting}" join="true"/>

        <stop job="${freds-pc}"/>

      </jobs>

    </sequential>

  </job>

</oddjob>

The run job starts the server job but doesn't wait for it to complete. We would need to add a wait job for that.Connect using a username and password to a secure server.

<jmx:client connection="localhost/my-oddjob" xmlns:jmx="http://rgordon.co.uk/oddjob/jmx">

    <environment>

        <jmx:client-credentials username="username" password="password"/>

    </environment>

</jmx:client>
A local job triggers when a server job runs.

<oddjob>

    <job>

        <sequential>

            <jobs>

                <jmx:client id="freds-pc" name="Oddjob Client" url="service:jmx:rmi:///jndi/rmi://${hosts.freds-pc}/freds-oddjob-server" xmlns:jmx="http://rgordon.co.uk/oddjob/jmx"/>

                <scheduling:trigger on="${freds-pc/server-jobs/greeting}" xmlns:scheduling="http://rgordon.co.uk/oddjob/scheduling">

                    <job>

                        <sequential>

                            <jobs>

                                <echo id="local-job">Server Job Ran!</echo>

                                <stop job="${freds-pc}"/>

                            </jobs>

                        </sequential>

                    </job>

                </scheduling:trigger>

            </jobs>

        </sequential>

    </job>

</oddjob>
  • Field Details

    • DEFAULT_LOG_POLLING_INTERVAL

      public static final long DEFAULT_LOG_POLLING_INTERVAL
      See Also:
  • Constructor Details

    • JMXClientJob

      public JMXClientJob()
  • Method Details

    • setUrl

      @Deprecated public void setUrl(String url)
      Deprecated.
      Reference Property:
      url

      Description

      This property is now deprecated in favour of connection which reflects that the connection string no longer need only be a full JMX URL.
      Required:
      No.
    • addLogListener

      public void addLogListener(LogListener l, Object component, LogLevel level, long last, int history)
      Description copied from interface: LogArchiver
      Add a listener to the archiver which will receive all missed events. The idea of receiving only missed events is to minimise network traffic when used remotely.

      Event numbers begin at 0. To receive all events, last must be -1.

      Specified by:
      addLogListener in interface LogArchiver
      Parameters:
      l - The logListener which will receive the events.
      level - The level of events required.
      last - The last event number received. The LogArchive will not send messages from before this number.
      history - The maximum messages to send up to the most recent.
    • removeLogListener

      public void removeLogListener(LogListener l, Object component)
      Description copied from interface: LogArchiver
      Remove the LogListener.
      Specified by:
      removeLogListener in interface LogArchiver
      Parameters:
      l - The LogListener.
    • addConsoleListener

      public void addConsoleListener(LogListener l, Object component, long last, int max)
      Description copied from interface: ConsoleArchiver
      Add a listener to the archiver which will receive all missed events. The idea of receiving only missed event is to minimise network traffic when used remotely.
      Specified by:
      addConsoleListener in interface ConsoleArchiver
      Parameters:
      l - The logListener which will receive the events.
      component - The component whose console to receive events for.
      last - The last event number received. The LogArchive will not send messages from before this number.
      max - The maximum messages to send up to the most recent.
    • removeConsoleListener

      public void removeConsoleListener(LogListener l, Object component)
      Description copied from interface: ConsoleArchiver
      Remove the LogListener.
      Specified by:
      removeConsoleListener in interface ConsoleArchiver
      Parameters:
      l - The LogListener.
    • consoleIdFor

      public String consoleIdFor(Object component)
      Description copied from interface: ConsoleArchiver
      Get the console id for a given component.
      Specified by:
      consoleIdFor in interface ConsoleArchiver
      Parameters:
      component - The component.
      Returns:
      The console id.
    • onInitialised

      public void onInitialised()
      Description copied from class: BaseComponent
      Subclasses override this method to perform post creation initialisation.
      Overrides:
      onInitialised in class BaseComponent
    • doStart

      protected void doStart(MBeanServerConnection mbsc, ScheduledExecutorService notificationProcessor)
      Description copied from class: ClientBase
      Overridden by subclasses to provide a specific startup.
      Specified by:
      doStart in class ClientBase
      Parameters:
      mbsc -
      notificationProcessor -
    • onStop

      protected void onStop(ClientBase.WhyStop why)
      Specified by:
      onStop in class ClientBase
    • provideBeanDirectory

      public RemoteDirectory provideBeanDirectory()
      Description copied from interface: RemoteDirectoryOwner
      Provide a remote directory.
      Specified by:
      provideBeanDirectory in interface BeanDirectoryOwner
      Specified by:
      provideBeanDirectory in interface RemoteDirectoryOwner
      Returns:
      The BeanDirectory or null.
    • addStructuralListener

      public void addStructuralListener(StructuralListener listener)
      Description copied from interface: Structural
      Add a listener. The listener will immediately receive add notifications for all existing children.
      Specified by:
      addStructuralListener in interface Structural
      Parameters:
      listener - The listener.
    • removeStructuralListener

      public void removeStructuralListener(StructuralListener listener)
      Description copied from interface: Structural
      Remove a listener.
      Specified by:
      removeStructuralListener in interface Structural
      Parameters:
      listener - The listener.
    • getMaxConsoleLines

      public int getMaxConsoleLines()
    • setMaxConsoleLines

      public void setMaxConsoleLines(int maxConsoleLines)
    • getMaxLoggerLines

      public int getMaxLoggerLines()
    • setMaxLoggerLines

      public void setMaxLoggerLines(int maxLoggerLines)
    • getLogPollingInterval

      public long getLogPollingInterval()
    • setLogPollingInterval

      public void setLogPollingInterval(long logPollingInterval)
    • getHandlerFactories

      public HandlerFactoryProvider getHandlerFactories()
    • setHandlerFactories

      public void setHandlerFactories(HandlerFactoryProvider handlerFactories)