Search in sources :

Example 1 with DisplayAndGroup

use of org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup in project org.csstudio.display.builder by kasemir.

the class EmbeddedDisplayRepresentation method fileChanged.

private void fileChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
    final DisplayAndGroup file_and_group = new DisplayAndGroup(model_widget.propFile().getValue(), model_widget.propGroupName().getValue());
    // System.out.println("Requested: " + file_and_group);
    final DisplayAndGroup skipped = pending_display_and_group.getAndSet(file_and_group);
    if (skipped != null)
        logger.log(Level.FINE, "Skipped: {0}", skipped);
    // Load embedded display in background thread
    ModelThreadPool.getExecutor().execute(this::updatePendingDisplay);
}
Also used : DisplayAndGroup(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup)

Example 2 with DisplayAndGroup

use of org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup in project org.csstudio.display.builder by kasemir.

the class EmbeddedDisplayRepresentation method updatePendingDisplay.

/**
 * Update to the next pending display
 *
 *  <p>Synchronized to serialize the background threads.
 *
 *  <p>Example: Displays A, B, C are requested in quick succession.
 *
 *  <p>pending_display_and_group=A is submitted to executor thread A.
 *
 *  <p>While handling A, pending_display_and_group=B is submitted to executor thread B.
 *  Thread B will be blocked in synchronized method.
 *
 *  <p>Then pending_display_and_group=C is submitted to executor thread C.
 *  As thread A finishes, thread B finds pending_display_and_group==C.
 *  As thread C finally continues, it finds pending_display_and_group empty.
 *  --> Showing A, then C, skipping B.
 */
private synchronized void updatePendingDisplay() {
    final DisplayAndGroup handle = pending_display_and_group.getAndSet(null);
    if (handle == null)
        return;
    try {
        // Load new model (potentially slow)
        final DisplayModel new_model = loadDisplayModel(model_widget, handle);
        // Atomically update the 'active' model
        final DisplayModel old_model = active_content_model.getAndSet(new_model);
        if (old_model != null) {
            // Dispose old model
            final Future<Object> completion = toolkit.submit(() -> {
                toolkit.disposeRepresentation(old_model);
                return null;
            });
            checkCompletion(model_widget, completion, "timeout disposing old representation");
        }
        // Represent new model on UI thread
        final Future<Object> completion = toolkit.submit(() -> {
            representContent(new_model);
            return null;
        });
        checkCompletion(model_widget, completion, "timeout representing new content");
        model_widget.runtimePropEmbeddedModel().setValue(new_model);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Failed to handle embedded display " + handle, ex);
    }
}
Also used : DisplayAndGroup(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup) DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayRepresentationUtil.loadDisplayModel(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel)

Example 3 with DisplayAndGroup

use of org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup in project org.csstudio.display.builder by kasemir.

the class EmbeddedDisplayRepresentation method fileChanged.

private void fileChanged(final WidgetProperty<?> property, final Object old_value, final Object new_value) {
    final DisplayAndGroup file_and_group = new DisplayAndGroup(model_widget.propFile().getValue(), model_widget.propGroupName().getValue());
    final DisplayAndGroup skipped = pending_display_and_group.getAndSet(file_and_group);
    if (skipped != null)
        logger.log(Level.FINE, "Skipped: {0}", skipped);
    // Load embedded display in background thread
    ModelThreadPool.getExecutor().execute(this::updatePendingDisplay);
}
Also used : DisplayAndGroup(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup)

Example 4 with DisplayAndGroup

use of org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup in project org.csstudio.display.builder by kasemir.

the class EmbeddedDisplayRepresentation method updatePendingDisplay.

/**
 * Update to the next pending display
 *
 *  <p>Synchronized to serialize the background threads.
 *
 *  <p>Example: Displays A, B, C are requested in quick succession.
 *
 *  <p>pending_display_and_group=A is submitted to executor thread A.
 *
 *  <p>While handling A, pending_display_and_group=B is submitted to executor thread B.
 *  Thread B will be blocked in synchronized method.
 *
 *  <p>Then pending_display_and_group=C is submitted to executor thread C.
 *  As thread A finishes, thread B finds pending_display_and_group==C.
 *  As thread C finally continues, it finds pending_display_and_group empty.
 *  --> Showing A, then C, skipping B.
 */
private synchronized void updatePendingDisplay() {
    final DisplayAndGroup handle = pending_display_and_group.getAndSet(null);
    if (handle == null) {
        // System.out.println("Nothing to handle");
        return;
    }
    if (inner == null) {
        // System.out.println("Aborted: " + handle);
        return;
    }
    try {
        // Load new model (potentially slow)
        final DisplayModel new_model = loadDisplayModel(model_widget, handle);
        // Stop (old) runtime
        // EmbeddedWidgetRuntime tracks this property to start/stop the embedded model's runtime
        model_widget.runtimePropEmbeddedModel().setValue(null);
        // Atomically update the 'active' model
        final DisplayModel old_model = active_content_model.getAndSet(new_model);
        new_model.propBackgroundColor().addUntypedPropertyListener(this::backgroundChanged);
        if (old_model != null) {
            // Dispose old model
            final Future<Object> completion = toolkit.submit(() -> {
                toolkit.disposeRepresentation(old_model);
                return null;
            });
            checkCompletion(model_widget, completion, "timeout disposing old representation");
        }
        // Represent new model on UI thread
        final Future<Object> completion = toolkit.submit(() -> {
            representContent(new_model);
            return null;
        });
        checkCompletion(model_widget, completion, "timeout representing new content");
        // Allow EmbeddedWidgetRuntime to start the new runtime
        model_widget.runtimePropEmbeddedModel().setValue(new_model);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Failed to handle embedded display " + handle, ex);
    }
}
Also used : DisplayAndGroup(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup) DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayRepresentationUtil.loadDisplayModel(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel)

Example 5 with DisplayAndGroup

use of org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup in project org.csstudio.display.builder by kasemir.

the class NavigationTabsRepresentation method updatePendingDisplay.

/**
 * Update to the next pending display
 *
 *  <p>Synchronized to serialize the background threads.
 *
 *  <p>Example: Displays A, B, C are requested in quick succession.
 *
 *  <p>pending_display_and_group=A is submitted to executor thread A.
 *
 *  <p>While handling A, pending_display_and_group=B is submitted to executor thread B.
 *  Thread B will be blocked in synchronized method.
 *
 *  <p>Then pending_display_and_group=C is submitted to executor thread C.
 *  As thread A finishes, thread B finds pending_display_and_group==C.
 *  As thread C finally continues, it finds pending_display_and_group empty.
 *  --> Showing A, then C, skipping B.
 */
private synchronized void updatePendingDisplay() {
    final DisplayAndGroup handle = pending_display_and_group.getAndSet(null);
    if (handle == null)
        return;
    if (body == null) {
        // System.out.println("Aborted: " + handle);
        return;
    }
    try {
        // Load new model (potentially slow)
        final DisplayModel new_model = loadDisplayModel(model_widget, handle);
        // Atomically update the 'active' model
        final DisplayModel old_model = active_content_model.getAndSet(new_model);
        if (old_model != null) {
            // Dispose old model
            final Future<Object> completion = toolkit.submit(() -> {
                toolkit.disposeRepresentation(old_model);
                return null;
            });
            checkCompletion(model_widget, completion, "timeout disposing old representation");
        }
        // Represent new model on UI thread
        final Future<Object> completion = toolkit.submit(() -> {
            representContent(new_model);
            return null;
        });
        checkCompletion(model_widget, completion, "timeout representing new content");
        model_widget.runtimePropEmbeddedModel().setValue(new_model);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Failed to handle embedded display " + handle, ex);
    }
}
Also used : DisplayAndGroup(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup) DisplayModel(org.csstudio.display.builder.model.DisplayModel) EmbeddedDisplayRepresentationUtil.loadDisplayModel(org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel)

Aggregations

DisplayAndGroup (org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.DisplayAndGroup)5 DisplayModel (org.csstudio.display.builder.model.DisplayModel)3 EmbeddedDisplayRepresentationUtil.loadDisplayModel (org.csstudio.display.builder.representation.EmbeddedDisplayRepresentationUtil.loadDisplayModel)3