org.eclipse.ease.modules.platform

## Class ScriptingModule

- java.lang.Object
- - org.eclipse.ease.modules.AbstractScriptModule
  - - org.eclipse.ease.modules.platform.ScriptingModule

All Implemented Interfaces:
  IScriptModule

    public class ScriptingModule
    extends AbstractScriptModule

Commands to launch additional script engines.

### Field Summary

Fields
`static String` `MODULE_ID` Module identifier.

### Constructor Summary

Constructors
Constructor and Description
`ScriptingModule()`

### Method Summary

All Methods Static Methods Instance Methods Concrete Methods
`static IScriptEngine` `createScriptEngine(String identifier)` Create a new script engine instance.
`Object` `executeSync(Object monitor, Object code)` Run a code fragment in a synchronized block.
`IScriptEngine` `fork(Object resource, String arguments, String engineID)` Fork a new script engine and execute provided resource.
`Object` `getSharedObject(String key)` Get an object from the shared object store.
`static boolean` `join(IScriptEngine engine, long timeout)` Wait for a script engine to shut down.
`static String[]` `listScriptEngines()` Retrieve a list of available script engines.
`static void` `notify(Object monitor)` Wakes up a single thread that is waiting on the monitor.
`static void` `notifyAll(Object monitor)` Wakes up all threads that are waiting on the monitor.
`void` `setSharedObject(String key, Object object, boolean permanent, boolean writable)` Add an object to the shared object store.
`static void` `wait(Object monitor, long timeout)` Causes the current thread to wait until either another thread invokes the `Object.notify()` method or the `Object.notifyAll()` method for this object, or a specified amount of time has elapsed.

### Methods inherited from class org.eclipse.ease.modules.AbstractScriptModule

`getScriptEngine, initialize`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Field Detail

#### MODULE_ID

    public static final String MODULE_ID

Module identifier.

See Also:
  Constant Field Values

### Constructor Detail

#### ScriptingModule

    public ScriptingModule()

### Method Detail

#### createScriptEngine

    public static IScriptEngine createScriptEngine(String identifier)

Create a new script engine instance.

Parameters:
  `identifier` - engine ID, literal engine name or accepted file extension
Returns:
  script engine instance (not started) or `null`

#### listScriptEngines

    public static String[] listScriptEngines()

Retrieve a list of available script engines.

Returns:
  array of engine IDs

#### fork

    public IScriptEngine fork(Object resource,
                              @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null")
                              String arguments,
                              @ScriptParameter(defaultValue="org.eclipse.ease.modules.ScriptParameter.null")
                              String engineID)

Fork a new script engine and execute provided resource.

Parameters:
  `resource` - resource to execute (path, URI or file instance)
  `arguments` - optional script arguments delimited by commas ','
  `engineID` - engine ID to be used
Returns:
  script engine instance or `null` in case of error

#### join

    public static boolean join(IScriptEngine engine,
                               @ScriptParameter(defaultValue="0")
                               long timeout)

Wait for a script engine to shut down. If timeout is set to 0 this method will wait endlessly.

Parameters:
  `engine` - script engine to wait for
  `timeout` - time to wait for shutdown [ms]
Returns:
  `true` when engine is shut down

#### executeSync

    public Object executeSync(Object monitor,
                              Object code)

Run a code fragment in a synchronized block. Executes code within a synchronized block on the monitor object. The code object might be a `String`, `File`, `IFile` or any other object that can be adapted to `IScriptable`.

Parameters:
  `monitor` - monitor to synchronize on
  `code` - code to run.
Returns:

#### wait

    public static void wait(Object monitor,
                            @ScriptParameter(defaultValue="0")
                            long timeout)
                     throws InterruptedException

Causes the current thread to wait until either another thread invokes the `Object.notify()` method or the `Object.notifyAll()` method for this object, or a specified amount of time has elapsed. Calls the java method monitor.wait(timeout).

Parameters:
  `monitor` - monitor to wait for
  `timeout` - max timeout (0 does not time out)
Throws:
  `InterruptedException` - when wait gets interrupted

#### notify

    public static void notify(Object monitor)

Wakes up a single thread that is waiting on the monitor. Calls the java method monitor.notify().

Parameters:
  `monitor` - monitor to notify

#### notifyAll

    public static void notifyAll(Object monitor)

Wakes up all threads that are waiting on the monitor. Calls the java method monitor.notifyAll().

Parameters:
  `monitor` - monitor to notify

#### setSharedObject

    public void setSharedObject(String key,
                                Object object,
                                @ScriptParameter(defaultValue="false")
                                boolean permanent,
                                @ScriptParameter(defaultValue="false")
                                boolean writable)
                         throws IllegalAccessException

Add an object to the shared object store. The shared object store allows to share java instances between several script engines. By default objects are stored until the script engine providing it is terminated. This helps to avoid polluting the java heap. When permanent is set to `true` , this object will be stored forever.

Parameters:
  `key` - key to store the object
  `object` - instance to store
  `permanent` - flag indicating permanent storage
  `writable` - flag indicating that any engine may write this value
Throws:
  `IllegalAccessException` - when scriptEngine is not the owner of the shared object

#### getSharedObject

    public Object getSharedObject(String key)

Get an object from the shared object store.

Parameters:
  `key` - key to retrieve object for
Returns:
  shared object or `null`