Search in sources :

Example 1 with ScriptSupport

use of org.csstudio.display.builder.runtime.script.internal.ScriptSupport in project org.csstudio.display.builder by kasemir.

the class WidgetRuntime method stop.

/**
 * Stop: Disconnect PVs, ...
 */
public void stop() {
    awaitStartup();
    widget.propClass().removePropertyListener(update_widget_class);
    final List<RuntimePV> safe_pvs = writable_pvs;
    if (safe_pvs != null) {
        for (final RuntimePV pv : safe_pvs) {
            removePV(pv);
            PVFactory.releasePV(pv);
        }
        writable_pvs = null;
    }
    final PVNameToValueBinding binding = pv_name_binding.getAndSet(null);
    if (binding != null)
        binding.dispose();
    final Map<ExecuteScriptActionInfo, Script> actions = action_scripts;
    if (actions != null) {
        actions.clear();
        action_scripts = null;
    }
    final List<RuntimeScriptHandler> handlers = script_handlers;
    if (handlers != null) {
        for (final RuntimeScriptHandler handler : handlers) handler.shutdown();
        script_handlers = null;
    }
    if (runtime_pvs != null) {
        final Collection<RuntimePV> pvs = runtime_pvs.getPVs();
        if (!pvs.isEmpty())
            logger.log(Level.SEVERE, widget + " has unreleased PVs: " + pvs);
    }
    // Close script support that might have been created
    // by RuntimeScriptHandlers or action-invoked scripts
    final ScriptSupport scripting = widget.getUserData(Widget.USER_DATA_SCRIPT_SUPPORT);
    if (scripting != null)
        scripting.close();
    // Prepare for another start()
    started = new CountDownLatch(1);
}
Also used : RuntimePV(org.csstudio.display.builder.runtime.pv.RuntimePV) Script(org.csstudio.display.builder.runtime.script.internal.Script) RuntimeScriptHandler(org.csstudio.display.builder.runtime.script.internal.RuntimeScriptHandler) ExecuteScriptActionInfo(org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo) CountDownLatch(java.util.concurrent.CountDownLatch) ScriptSupport(org.csstudio.display.builder.runtime.script.internal.ScriptSupport)

Example 2 with ScriptSupport

use of org.csstudio.display.builder.runtime.script.internal.ScriptSupport in project org.csstudio.display.builder by kasemir.

the class JythonScriptTest method testJythonScript.

@Test
public void testJythonScript() throws Exception {
    System.setProperty("python.import.site", "false");
    final DisplayModel display = ModelLoader.resolveAndLoadModel("../org.csstudio.display.builder.runtime.test/examples/dummy.opi", "script_test.opi");
    final Widget widget = display.getChildren().parallelStream().filter(w -> w.getName().equals("Label 100")).findFirst().get();
    System.out.println(widget);
    // Set widget variable in script
    final ScriptSupport scripting = new ScriptSupport();
    final Script script = scripting.compile(".", "updateText.py", new FileInputStream("../org.csstudio.display.builder.runtime.test/examples/updateText.py"));
    for (int run = 0; run < 10; ++run) {
        widget.setPropertyValue("text", "Initial");
        assertThat(widget.getPropertyValue("text"), equalTo("Initial"));
        script.submit(widget).get();
        assertThat(widget.getPropertyValue("text"), equalTo("Hello"));
    }
    scripting.close();
}
Also used : Script(org.csstudio.display.builder.runtime.script.internal.Script) DisplayModel(org.csstudio.display.builder.model.DisplayModel) Widget(org.csstudio.display.builder.model.Widget) ScriptSupport(org.csstudio.display.builder.runtime.script.internal.ScriptSupport) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 3 with ScriptSupport

use of org.csstudio.display.builder.runtime.script.internal.ScriptSupport in project org.csstudio.display.builder by kasemir.

the class PythonScriptTest method testPythonScript.

@Test
public void testPythonScript() throws Exception {
    if (!PythonGatewaySupport.isConnect2jInstalled()) {
        System.err.println("Skipping PythonScriptTest because there is no python with connect2j");
        return;
    }
    final DisplayModel display = ModelLoader.resolveAndLoadModel("../org.csstudio.display.builder.runtime.test/examples/dummy.opi", "script_test.opi");
    final Widget widget = display.getChildren().parallelStream().filter(w -> w.getName().equals("Label 100")).findFirst().get();
    System.out.println(widget);
    // Set widget variable in script
    final ScriptSupport scripting = new ScriptSupport();
    final Script script = scripting.compile("../org.csstudio.display.builder.runtime.test/examples", "updateText_python.py", null);
    for (int run = 0; run < 10; ++run) {
        widget.setPropertyValue("text", "Initial");
        assertThat(widget.getPropertyValue("text"), equalTo("Initial"));
        script.submit(widget).get();
        assertThat(widget.getPropertyValue("text"), equalTo("Hello"));
    }
    scripting.close();
}
Also used : Script(org.csstudio.display.builder.runtime.script.internal.Script) DisplayModel(org.csstudio.display.builder.model.DisplayModel) Widget(org.csstudio.display.builder.model.Widget) ScriptSupport(org.csstudio.display.builder.runtime.script.internal.ScriptSupport) Test(org.junit.Test)

Example 4 with ScriptSupport

use of org.csstudio.display.builder.runtime.script.internal.ScriptSupport in project org.csstudio.display.builder by kasemir.

the class RuntimeUtil method getScriptSupport.

/**
 * Obtain script support
 *
 *  <p>Script support is associated with the top-level display model
 *  and initialized on first access, i.e. each display has its own
 *  script support. Embedded displays use the script support of
 *  their parent display.
 *
 *  @param widget Widget
 *  @return {@link ScriptSupport} for the widget's top-level display model
 *  @throws Exception on error
 */
public static ScriptSupport getScriptSupport(final Widget widget) throws Exception {
    final DisplayModel model = widget.getTopDisplayModel();
    // So sync'ing on the ScriptSupport class
    synchronized (ScriptSupport.class) {
        ScriptSupport scripting = model.getUserData(Widget.USER_DATA_SCRIPT_SUPPORT);
        if (scripting == null) {
            // This takes about 3 seconds
            final long start = System.currentTimeMillis();
            scripting = new ScriptSupport();
            final long elapsed = System.currentTimeMillis() - start;
            logger.log(Level.FINE, "ScriptSupport created for {0} by {1} in {2} ms", new Object[] { model, widget, elapsed });
            model.setUserData(Widget.USER_DATA_SCRIPT_SUPPORT, scripting);
        }
        return scripting;
    }
}
Also used : DisplayModel(org.csstudio.display.builder.model.DisplayModel) ScriptSupport(org.csstudio.display.builder.runtime.script.internal.ScriptSupport)

Aggregations

ScriptSupport (org.csstudio.display.builder.runtime.script.internal.ScriptSupport)4 DisplayModel (org.csstudio.display.builder.model.DisplayModel)3 Script (org.csstudio.display.builder.runtime.script.internal.Script)3 Widget (org.csstudio.display.builder.model.Widget)2 Test (org.junit.Test)2 FileInputStream (java.io.FileInputStream)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ExecuteScriptActionInfo (org.csstudio.display.builder.model.properties.ExecuteScriptActionInfo)1 RuntimePV (org.csstudio.display.builder.runtime.pv.RuntimePV)1 RuntimeScriptHandler (org.csstudio.display.builder.runtime.script.internal.RuntimeScriptHandler)1