mx4j.tools.jython
Class JythonRunner

java.lang.Object
  |
  +--mx4j.tools.jython.JythonRunner
All Implemented Interfaces:
java.util.EventListener, JythonRunnerMBean, MBeanRegistration, NotificationListener

public class JythonRunner
extends java.lang.Object
implements JythonRunnerMBean, NotificationListener, 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:


Constructor Summary
JythonRunner()
           
 
Method Summary
 boolean getCacheScript()
          Returns whether the script should be kept in the cache.
 java.lang.String getNotificationType()
          Gets the specific notification type being listened
 javax.management.ObjectName getObservedObject()
          Gets the object being observed by this MBean
static org.python.util.PythonInterpreter getPythonInterpreter()
           
 java.lang.String getScript()
          Returns the script as text.
 java.net.URL getScriptFile()
          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, java.lang.Object handback)
          Called when a notification occurs.
protected static java.lang.String loadStream(java.io.InputStream in)
           
 void postDeregister()
          Called upon after the MBean has been de-registered.
 void postRegister(java.lang.Boolean registrationDone)
          Called upon after a registration ( successful or not ).
 void preDeregister()
          Called upon before an MBean will be de-registered by the MBeanServer.
 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(java.lang.String notificationName)
          Sets the notification being listed.
 void setObservedObject(javax.management.ObjectName targetMBeanName)
          Sets the object being observed by this MBean.
 void setScript(java.lang.String text)
          Sets the content of the script.
 void setScriptFile(java.net.URL file)
          Sets the script source as URL.
protected  void unregisterListener()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JythonRunner

public JythonRunner()
Method Detail

handleNotification

public void handleNotification(javax.management.Notification notification,
                               java.lang.Object handback)
Description copied from interface: NotificationListener
Called when a notification occurs.

Specified by:
handleNotification in interface NotificationListener
Parameters:
notification - The notification object
handback - Helps in associating information regarding the listener.

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

getPythonInterpreter

public static org.python.util.PythonInterpreter getPythonInterpreter()

loadStream

protected static java.lang.String loadStream(java.io.InputStream in)
                                      throws java.io.IOException
java.io.IOException

getNotificationType

public java.lang.String getNotificationType()
Gets the specific notification type being listened

Specified by:
getNotificationType in interface JythonRunnerMBean

setNotificationType

public void setNotificationType(java.lang.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

getObservedObject

public javax.management.ObjectName getObservedObject()
Gets the object being observed by this MBean

Specified by:
getObservedObject 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

setScript

public void setScript(java.lang.String text)
Sets the content of the script. If you want to use a file, use ScriptFile instead.

Specified by:
setScript in interface JythonRunnerMBean

getScript

public java.lang.String getScript()
Returns the script as text.

Specified by:
getScript in interface JythonRunnerMBean

getScriptFile

public java.net.URL getScriptFile()
Returns the URL pointing to the script source

Specified by:
getScriptFile in interface JythonRunnerMBean

setScriptFile

public void setScriptFile(java.net.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:
setScriptFile in interface JythonRunnerMBean

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

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

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 MBeanRegistration
Parameters:
server - The MBeanServer on which the MBean will be registered.
name - The ObjectName of the MBean.
Returns:
ObjectName The name of the registered MBean
Throws:
java.lang.Exception - Exception of the operation. Note that this is caught by the MBeanServer and re-thrown as an MBeanRegistrationException.

postRegister

public void postRegister(java.lang.Boolean registrationDone)
Description copied from interface: MBeanRegistration
Called upon after a registration ( successful or not ).

Specified by:
postRegister in interface MBeanRegistration
Parameters:
registrationDone - Evaluates to true of the registrations is successful, false otherwise.

preDeregister

public void preDeregister()
                   throws java.lang.Exception
Description copied from interface: MBeanRegistration
Called upon before an MBean will be de-registered by the MBeanServer.

Specified by:
preDeregister in interface MBeanRegistration
Throws:
java.lang.Exception - Would be caught by the MBeanServer and rethrown as an MBeanRegistrationException.

postDeregister

public void postDeregister()
Description copied from interface: MBeanRegistration
Called upon after the MBean has been de-registered.

Specified by:
postDeregister in interface MBeanRegistration

registerListener

protected void registerListener()

unregisterListener

protected void unregisterListener()