## mx4j.tools.jython
Class JythonRunner

    java.lang.Object
      mx4j.tools.jython.JythonRunner

All Implemented Interfaces:
  java.util.EventListener, 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:

- from javax.management import *
- from javax.management.loading import *

Version:
  $Revision: 1.9 $

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` `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, java.lang.Object handback)`
`protected static java.lang.String` `loadStream(java.io.InputStream in)`
`void` `postDeregister()`
`void` `postRegister(java.lang.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(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` `setScriptURL(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)

  Specified by:
    `handleNotification` in interface `javax.management.NotificationListener`

### 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

  Throws:
    `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`

### getScriptURL

    public java.net.URL getScriptURL()

  Returns the URL pointing to the script source

  Specified by:
    `getScriptURL` in interface `JythonRunnerMBean`

### setScriptURL

    public void setScriptURL(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:
    `setScriptURL` 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 `javax.management.MBeanRegistration`
  Throws:
    `java.lang.Exception`

### postRegister

    public void postRegister(java.lang.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`
  Throws:
    `java.lang.Exception`

### postDeregister

    public void postDeregister()

  Specified by:
    `postDeregister` in interface `javax.management.MBeanRegistration`

### registerListener

    protected void registerListener()

### unregisterListener

    protected void unregisterListener()

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