Skip to content

Commit

Permalink
[FIXED JENKINS-30055] The listener which closes flow graph log files …
Browse files Browse the repository at this point in the history
…must receive events immediately, and unregister itself.

Originally-Committed-As: 1084a9bd2495989bb78e013c08c8348542e7955f
  • Loading branch information
jglick committed Sep 25, 2015
1 parent 248f243 commit 630edfb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 10 deletions.
Expand Up @@ -237,7 +237,7 @@ public class CpsFlowExecution extends FlowExecution {

private final AtomicInteger iota = new AtomicInteger();

private transient List<GraphListener> listeners;
private transient List<GraphListener> listeners, synchronousListeners;

/**
* Result set from {@link StepContext}. Start by success and progressively gets worse.
Expand Down Expand Up @@ -681,11 +681,27 @@ void subsumeHead(FlowNode n) {


@Override
public void addListener(GraphListener listener) {
if (listeners == null) {
listeners = new CopyOnWriteArrayList<GraphListener>();
public void addListener(GraphListener listener, boolean synchronous) {
if (synchronous) {
if (synchronousListeners == null) {
synchronousListeners = new CopyOnWriteArrayList<GraphListener>();
}
synchronousListeners.add(listener);
} else {
if (listeners == null) {
listeners = new CopyOnWriteArrayList<GraphListener>();
}
listeners.add(listener);
}
}

@Override public void removeListener(GraphListener listener) {
if (listeners != null) {
listeners.remove(listener);
}
if (synchronousListeners != null) {
synchronousListeners.remove(listener);
}
listeners.add(listener);
}

@Override
Expand Down Expand Up @@ -767,9 +783,10 @@ synchronized FlowHead getFirstHead() {
return heads.firstEntry().getValue();
}

void notifyListeners(FlowNode node) {
if (listeners != null) {
for (GraphListener listener : listeners) {
void notifyListeners(FlowNode node, boolean synchronous) {
List<GraphListener> _listeners = synchronous ? synchronousListeners : listeners;
if (_listeners != null) {
for (GraphListener listener : _listeners) {
listener.onNewHead(node);
}
}
Expand Down
Expand Up @@ -315,9 +315,10 @@ private void run() throws IOException {
@CpsVmThreadOnly
/*package*/ void notifyNewHead(final FlowNode head) {
assertVmThread();
execution.notifyListeners(head, true);
runner.execute(new Runnable() {
public void run() {
execution.notifyListeners(head);
execution.notifyListeners(head, false);
}
});
}
Expand Down
Expand Up @@ -119,7 +119,9 @@ void setNewHead(FlowNode v) {
} else {
// in recovering from error and such situation, we sometimes need to grow the graph
// without running the program.
execution.notifyListeners(v);
// TODO can CpsThreadGroup.notifyNewHead be used instead?
execution.notifyListeners(v, true);
execution.notifyListeners(v, false);
}
} catch (IOException e) {
LOGGER.log(Level.FINE, "Failed to record new head: " + v, e);
Expand Down

0 comments on commit 630edfb

Please sign in to comment.