mx4j.tools.jython

Class JythonRunner

Implemented Interfaces:
JythonRunnerMBean, javax.management.MBeanRegistration, javax.management.NotificationListener

public class JythonRunner
extends java.lang.Object
implements JythonRunnerMBean, javax.management.NotificationListener, javax.management.MBeanRegistration

This MBean enables you to run scripts written in jython. Scripts can be run using the managed operation runScript or by listening notifcations from another MBean. To us it you need to install jython 2.1 or higher from <a href="http://www.jython.org">here</a>

If you want to use a jython library remember to add the jython jar to the classpath in the right location or modify the python.path address

The scripts have always the "server" embedded variable which points to the current server. It also automatically import some JMX modules as:

Version:
$Revision: 1.9 $

Method Summary

boolean
getCacheScript()
Returns whether the script should be kept in the cache.
String
getNotificationType()
Gets the specific notification type being listened
javax.management.ObjectName
getObservedObject()
Gets the object being observed by this MBean
static PythonInterpreter
getPythonInterpreter()
String
getScript()
Returns the script as text.
URL
getScriptURL()
Returns the URL pointing to the script source
boolean
getUseText()
Indicates wether to use the script given in the ScripText variable or the one given in the script File.
void
handleNotification(javax.management.Notification notification, Object handback)
protected static String
loadStream(InputStream in)
void
postDeregister()
void
postRegister(Boolean registrationDone)
void
preDeregister()
javax.management.ObjectName
preRegister(javax.management.MBeanServer server, javax.management.ObjectName name)
Gathers some basic data
protected void
registerListener()
void
runScript()
Executes a given script.
void
setCacheScript(boolean useCache)
Sets whether the script should be kept in the cache.
void
setNotificationType(String notificationName)
Sets the notification being listed.
void
setObservedObject(javax.management.ObjectName targetMBeanName)
Sets the object being observed by this MBean.
void
setScript(String text)
Sets the content of the script.
void
setScriptURL(URL file)
Sets the script source as URL.
protected void
unregisterListener()

Method Details

getCacheScript

public boolean getCacheScript()
Returns whether the script should be kept in the cache. If true, no further attempts to read the script will be done afterwards. By default is false
Specified by:
getCacheScript in interface JythonRunnerMBean

getNotificationType

public String getNotificationType()
Gets the specific notification type being listened
Specified by:
getNotificationType in interface JythonRunnerMBean

getObservedObject

public javax.management.ObjectName getObservedObject()
Gets the object being observed by this MBean
Specified by:
getObservedObject in interface JythonRunnerMBean

getPythonInterpreter

public static PythonInterpreter getPythonInterpreter()

getScript

public String getScript()
Returns the script as text.
Specified by:
getScript in interface JythonRunnerMBean

getScriptURL

public URL getScriptURL()
Returns the URL pointing to the script source
Specified by:
getScriptURL in interface JythonRunnerMBean

getUseText

public boolean getUseText()
Indicates wether to use the script given in the ScripText variable or the one given in the script File.
Specified by:
getUseText in interface JythonRunnerMBean

handleNotification

public void handleNotification(javax.management.Notification notification,
                               Object handback)
Specified by:
handleNotification in interface javax.management.NotificationListener

loadStream

protected static String loadStream(InputStream in)
            throws IOException

postDeregister

public void postDeregister()
Specified by:
postDeregister in interface javax.management.MBeanRegistration

postRegister

public void postRegister(Boolean registrationDone)
Specified by:
postRegister in interface javax.management.MBeanRegistration

preDeregister

public void preDeregister()
            throws java.lang.Exception
Specified by:
preDeregister in interface javax.management.MBeanRegistration

preRegister

public javax.management.ObjectName preRegister(javax.management.MBeanServer server,
                                               javax.management.ObjectName name)
            throws java.lang.Exception
Gathers some basic data
Specified by:
preRegister in interface javax.management.MBeanRegistration

registerListener

protected void registerListener()

runScript

public void runScript()
Executes a given script. If useText is true the text passed will be run as a script otherwise the script will be loaded from the URL an executed
Specified by:
runScript in interface JythonRunnerMBean

setCacheScript

public void setCacheScript(boolean useCache)
Sets whether the script should be kept in the cache. If true, no further attempts to read the script will be done afterwards. By default is false
Specified by:
setCacheScript in interface JythonRunnerMBean

setNotificationType

public void setNotificationType(String notificationName)
Sets the notification being listed. If null any notification will trigger the execution of the script. Otherwise only notifications matching notificationName will trigger it
Specified by:
setNotificationType in interface JythonRunnerMBean

setObservedObject

public void setObservedObject(javax.management.ObjectName targetMBeanName)
Sets the object being observed by this MBean. The MBean will register itself as a listener of targetMBeanName
Specified by:
setObservedObject in interface JythonRunnerMBean

setScript

public void setScript(String text)
Sets the content of the script. If you want to use a file, use ScriptFile instead.
Specified by:
setScript in interface JythonRunnerMBean

setScriptURL

public void setScriptURL(URL file)
Sets the script source as URL. If the cache script variable is true the file will be loaded only once, otherwise everytime the script is executed
Specified by:
setScriptURL in interface JythonRunnerMBean

unregisterListener

protected void unregisterListener()

Copyright © 2001-2005 The MX4J Contributors. All Rights Reserved.