Skip to content

Commit

Permalink
Merge pull request #1 from jglick/remotable-JENKINS-26521
Browse files Browse the repository at this point in the history
Showing how to do Channel.export
  • Loading branch information
abayer committed Apr 11, 2018
2 parents 1307d5a + 5b8a953 commit 1129e93
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import hudson.model.Result;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.remoting.Channel;
import java.io.IOException;
import java.io.OutputStream;
import java.io.Serializable;
Expand Down Expand Up @@ -61,7 +62,7 @@ public boolean start() throws Exception {
bodyInvoker = bodyInvoker.withContext(
BodyInvoker.mergeConsoleLogFilters(
context.get(ConsoleLogFilter.class),
new ConsoleLogFilterImpl(new ResetCallback())
new ConsoleLogFilterImpl(new ResetCallbackImpl())
)
);
}
Expand Down Expand Up @@ -229,23 +230,31 @@ public String getShortDescription() {
}
}

private class ResetCallback implements Serializable {
private static final long serialVersionUID = 1L;
public interface ResetCallback extends Serializable {
void logWritten();
}

private void logWritten() {
private class ResetCallbackImpl implements ResetCallback {
private static final long serialVersionUID = 1L;
@Override public void logWritten() {
resetTimer();
}
}

private static class ConsoleLogFilterImpl extends ConsoleLogFilter implements Serializable {
private static class ConsoleLogFilterImpl extends ConsoleLogFilter implements /* TODO Remotable */ Serializable {
private static final long serialVersionUID = 1L;

private final ResetCallback callback;

public ConsoleLogFilterImpl(ResetCallback callback) {
ConsoleLogFilterImpl(ResetCallback callback) {
this.callback = callback;
}

private Object writeReplace() {
Channel ch = Channel.current();
return ch == null ? this : new ConsoleLogFilterImpl(ch.export(ResetCallback.class, callback));
}

@Override
public OutputStream decorateLogger(@SuppressWarnings("rawtypes") Run build, final OutputStream logger)
throws IOException, InterruptedException {
Expand Down

0 comments on commit 1129e93

Please sign in to comment.