org.oddjob.jmx
Class JMXClientJob

java.lang.Object
  extended by org.oddjob.framework.BaseComponent
      extended by org.oddjob.jmx.JMXClientJob
All Implemented Interfaces:
Runnable, ArooaContextAware, BeanDirectoryOwner, PropertyChangeNotifier, Iconic, RemoteDirectoryOwner, ConsoleArchiver, LogArchiver, LogEnabled, Resetable, Stateful, Stoppable, Structural

public class JMXClientJob
extends BaseComponent
implements Runnable, Stateful, Resetable, Stoppable, Structural, LogArchiver, ConsoleArchiver, LogEnabled, RemoteDirectoryOwner

Description

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

This job will run until it is manually stopped or until the remote server is stopped. If this job is stopped it's state will be COMPLETE, if the server stops this job's state will be INCOMPLETE.

To access and control jobs on a server from within a configuration file this client job 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

To create a connection to a remote server.
<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"/>

Example

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}"/>
                 <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.

Example

Connect using a username and password to a secure server.
<jmx:client url="service:jmx:rmi:///jndi/rmi://localhost/my-oddjob" xmlns:jmx="http://rgordon.co.uk/oddjob/jmx">
    <environment>
        <jmx:client-credentials username="username" password="password"/>
    </environment>
</jmx:client>

Example

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>
Author:
Rob Gordon

Field Summary
static long DEFAULT_LOG_POLLING_INTERVAL
           
 
Fields inherited from class org.oddjob.framework.BaseComponent
iconHelper
 
Fields inherited from interface org.oddjob.logging.LogArchiver
MAX_HISTORY, NO_LOG_AVAILABLE
 
Constructor Summary
JMXClientJob()
           
 
Method Summary
 void addConsoleListener(LogListener l, Object component, long last, int max)
          Add a listener to the archiver which will receive all missed events.
 void addLogListener(LogListener l, Object component, LogLevel level, long last, int history)
          Add a listener to the archiver which will receive all missed events.
 void addStructuralListener(StructuralListener listener)
          Add a listener.
 String consoleIdFor(Object component)
          Get the console id for a given component.
protected  void fireDestroyedState()
          Internal method to fire state.
 Map<String,?> getEnvironment()
           
 long getHeartbeat()
           
 long getLogPollingInterval()
           
 int getMaxConsoleLines()
           
 int getMaxLoggerLines()
           
 String getName()
          Get the name.
protected  ServiceStateChanger getStateChanger()
           
 String getUrl()
          Get the JMX service URL.
 boolean hardReset()
          Perform a hard reset on the job.
protected  org.apache.log4j.Logger logger()
           
 String loggerName()
           
protected  void onDestroy()
          Subclasses override this method to clear up resources.
 void onInitialised()
          Subclasses override this method to perform post creation initialisation.
 RemoteDirectory provideBeanDirectory()
          Get the BeanDirectory.
 void removeConsoleListener(LogListener l, Object component)
          Remove the LogListener.
 void removeLogListener(LogListener l, Object component)
          Remove the LogListener.
 void removeStructuralListener(StructuralListener listener)
          Remove a listener.
 void run()
           
 void setEnvironment(Map<String,?> environment)
           
 void setHeartbeat(long heartbeat)
           
 void setLogPollingInterval(long logPollingInterval)
           
 void setMaxConsoleLines(int maxConsoleLines)
           
 void setMaxLoggerLines(int maxLoggerLines)
           
 void setName(String name)
          Set the name
 void setUrl(String lookup)
          Set naming service url.
 boolean softReset()
          Perform a soft reset on the job.
protected  ServiceStateHandler stateHandler()
           
 void stop()
          Stop executing.
 String toString()
           
 
Methods inherited from class org.oddjob.framework.BaseComponent
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, removeIconListener, removePropertyChangeListener, removeStateListener, save, save, setArooaContext, setArooaSession
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.oddjob.Stateful
addStateListener, lastStateEvent, removeStateListener
 

Field Detail

DEFAULT_LOG_POLLING_INTERVAL

public static final long DEFAULT_LOG_POLLING_INTERVAL
See Also:
Constant Field Values
Constructor Detail

JMXClientJob

public JMXClientJob()
Method Detail

stateHandler

protected ServiceStateHandler stateHandler()
Specified by:
stateHandler in class BaseComponent

getStateChanger

protected ServiceStateChanger getStateChanger()

getName

public String getName()
Get the name.

Returns:
The name.

setName

public void setName(String name)
Set the name

Parameters:
name - The name.

logger

protected org.apache.log4j.Logger logger()
Specified by:
logger in class BaseComponent

loggerName

public String loggerName()
Specified by:
loggerName in interface LogEnabled

setUrl

public void setUrl(String lookup)
Set naming service url.

Parameters:
url - The name of the remote node in the naming service.

getUrl

public String getUrl()
Get the JMX service URL.

Returns:
The name of the remote node in the naming service.

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 recieve all events, last must be -1.

Specified by:
addLogListener in interface LogArchiver
Parameters:
l - The logListener which will recieve the events.
level - The level of events required.
last - The last event number recieved. 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 recieve the events.
component - The component whose console to receive events for.
last - The last event number recieved. 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

run

public void run()
Specified by:
run in interface Runnable

stop

public void stop()
Description copied from interface: Stoppable
Stop executing. This method should not return until the Stoppable has actually stopped.

Specified by:
stop in interface Stoppable

provideBeanDirectory

public RemoteDirectory provideBeanDirectory()
Description copied from interface: BeanDirectoryOwner
Get the BeanDirectory. This method may return null if the BeanDirectory isn't available.

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.

softReset

public boolean softReset()
Perform a soft reset on the job.

Specified by:
softReset in interface Resetable
Returns:
true if successful.

hardReset

public boolean hardReset()
Perform a hard reset on the job.

Specified by:
hardReset in interface Resetable
Returns:
true if successful.

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)

toString

public String toString()
Overrides:
toString in class Object

getEnvironment

public Map<String,?> getEnvironment()

setEnvironment

public void setEnvironment(Map<String,?> environment)

getHeartbeat

public long getHeartbeat()

setHeartbeat

public void setHeartbeat(long heartbeat)

onDestroy

protected void onDestroy()
Description copied from class: BaseComponent
Subclasses override this method to clear up resources.

Overrides:
onDestroy in class BaseComponent

fireDestroyedState

protected void fireDestroyedState()
Internal method to fire state.

Specified by:
fireDestroyedState in class BaseComponent