Skip to content
Permalink
Browse files
[FIXED JENKINS-30055] The listener which closes flow graph log files …
…must receive events immediately, and unregister itself.

Originally-Committed-As: 1084a9bd2495989bb78e013c08c8348542e7955f
  • Loading branch information
jglick committed Sep 25, 2015
1 parent 248f243 commit 630edfb4313db63d01f6eb135cbce7081f496fae
@@ -237,7 +237,7 @@

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.
@@ -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
@@ -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);
}
}
@@ -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);
}
});
}
@@ -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);

0 comments on commit 630edfb

Please sign in to comment.