public class JMXClientJob extends ClientBase implements Structural, LogArchiver, ConsoleArchiver, RemoteDirectoryOwner
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}
.
<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
.
<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"/>
<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.
<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>
<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>
ClientBase.WhyStop
Modifier and Type | Field and Description |
---|---|
static long |
DEFAULT_LOG_POLLING_INTERVAL |
MAX_HISTORY, NO_LOG_AVAILABLE
Constructor and Description |
---|
JMXClientJob() |
Modifier and Type | Method and Description |
---|---|
void |
addConsoleListener(LogListener l,
java.lang.Object component,
long last,
int max)
Add a listener to the archiver which will receive all missed
events.
|
void |
addLogListener(LogListener l,
java.lang.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.
|
java.lang.String |
consoleIdFor(java.lang.Object component)
Get the console id for a given component.
|
protected void |
doStart(javax.management.MBeanServerConnection mbsc,
java.util.concurrent.ScheduledExecutorService notificationProcessor)
Overridden by subclasses to provide a specific startup.
|
HandlerFactoryProvider |
getHandlerFactories() |
long |
getLogPollingInterval() |
int |
getMaxConsoleLines() |
int |
getMaxLoggerLines() |
void |
onInitialised()
Subclasses override this method to perform post creation
initialisation.
|
protected void |
onStop(ClientBase.WhyStop why) |
RemoteDirectory |
provideBeanDirectory()
Provide a remote directory.
|
void |
removeConsoleListener(LogListener l,
java.lang.Object component)
Remove the LogListener.
|
void |
removeLogListener(LogListener l,
java.lang.Object component)
Remove the LogListener.
|
void |
removeStructuralListener(StructuralListener listener)
Remove a listener.
|
void |
setHandlerFactories(HandlerFactoryProvider handlerFactories) |
void |
setLogPollingInterval(long logPollingInterval) |
void |
setMaxConsoleLines(int maxConsoleLines) |
void |
setMaxLoggerLines(int maxLoggerLines) |
void |
setUrl(java.lang.String url)
Deprecated.
|
doStop, getConnection, getEnvironment, getHeartbeat, onStart, onStop, setConnection, setEnvironment, setHeartbeat
fireDestroyedState, getName, getStateChanger, hardReset, iconHelper, logger, loggerName, onDestroy, run, setName, softReset, stateHandler, stop, toString
addIconListener, addPropertyChangeListener, addStateListener, configure, destroy, firePropertyChange, getArooaSession, iconForId, initialise, lastStateEvent, onConfigured, removeIconListener, removePropertyChangeListener, removeStateListener, save, save, setArooaContext, setArooaSession
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addStateListener, lastStateEvent, removeStateListener
public static final long DEFAULT_LOG_POLLING_INTERVAL
@Deprecated public void setUrl(java.lang.String url)
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.
public void addLogListener(LogListener l, java.lang.Object component, LogLevel level, long last, int history)
LogArchiver
Event numbers begin at 0. To receive all events, last must be -1.
addLogListener
in interface LogArchiver
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.public void removeLogListener(LogListener l, java.lang.Object component)
LogArchiver
removeLogListener
in interface LogArchiver
l
- The LogListener.public void addConsoleListener(LogListener l, java.lang.Object component, long last, int max)
ConsoleArchiver
addConsoleListener
in interface ConsoleArchiver
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.public void removeConsoleListener(LogListener l, java.lang.Object component)
ConsoleArchiver
removeConsoleListener
in interface ConsoleArchiver
l
- The LogListener.public java.lang.String consoleIdFor(java.lang.Object component)
ConsoleArchiver
consoleIdFor
in interface ConsoleArchiver
component
- The component.public void onInitialised()
BaseComponent
onInitialised
in class BaseComponent
protected void doStart(javax.management.MBeanServerConnection mbsc, java.util.concurrent.ScheduledExecutorService notificationProcessor)
ClientBase
doStart
in class ClientBase
protected void onStop(ClientBase.WhyStop why)
onStop
in class ClientBase
public RemoteDirectory provideBeanDirectory()
RemoteDirectoryOwner
provideBeanDirectory
in interface BeanDirectoryOwner
provideBeanDirectory
in interface RemoteDirectoryOwner
BeanDirectory
or null.public void addStructuralListener(StructuralListener listener)
Structural
addStructuralListener
in interface Structural
listener
- The listener.public void removeStructuralListener(StructuralListener listener)
Structural
removeStructuralListener
in interface Structural
listener
- The listener.public int getMaxConsoleLines()
public void setMaxConsoleLines(int maxConsoleLines)
public int getMaxLoggerLines()
public void setMaxLoggerLines(int maxLoggerLines)
public long getLogPollingInterval()
public void setLogPollingInterval(long logPollingInterval)
public HandlerFactoryProvider getHandlerFactories()
public void setHandlerFactories(HandlerFactoryProvider handlerFactories)