Search in sources :

Example 1 with GraphListener

use of org.jenkinsci.plugins.workflow.flow.GraphListener in project workflow-cps-plugin by jenkinsci.

the class CpsFlowExecution method notifyListeners.

void notifyListeners(List<FlowNode> nodes, boolean synchronous) {
    List<GraphListener> toRun = getListenersToRun();
    if (!toRun.isEmpty()) {
        Saveable s = Saveable.NOOP;
        try {
            Queue.Executable exec = owner.getExecutable();
            if (exec instanceof Saveable) {
                s = (Saveable) exec;
            }
        } catch (IOException x) {
            LOGGER.log(Level.WARNING, "failed to notify listeners of changes to " + nodes + " in " + this, x);
        }
        BulkChange bc = new BulkChange(s);
        try {
            for (FlowNode node : nodes) {
                for (GraphListener listener : toRun) {
                    if (listener instanceof GraphListener.Synchronous == synchronous) {
                        listener.onNewHead(node);
                    }
                }
            }
        } finally {
            if (synchronous) {
                // hack to skip save—we are holding a lock
                bc.abort();
            } else {
                try {
                    bc.commit();
                } catch (IOException x) {
                    LOGGER.log(Level.WARNING, null, x);
                }
            }
        }
    }
}
Also used : Saveable(hudson.model.Saveable) BulkChange(hudson.BulkChange) IOException(java.io.IOException) GraphListener(org.jenkinsci.plugins.workflow.flow.GraphListener) Queue(hudson.model.Queue) FlowNode(org.jenkinsci.plugins.workflow.graph.FlowNode)

Aggregations

BulkChange (hudson.BulkChange)1 Queue (hudson.model.Queue)1 Saveable (hudson.model.Saveable)1 IOException (java.io.IOException)1 GraphListener (org.jenkinsci.plugins.workflow.flow.GraphListener)1 FlowNode (org.jenkinsci.plugins.workflow.graph.FlowNode)1