~linaro-automation/jenkins-remoting/linaro-trunk

« back to all changes in this revision

Viewing changes to src/main/java/hudson/remoting/PingThread.java

  • Committer: Kohsuke Kawaguchi
  • Date: 2011-09-25 01:15:08 UTC
  • Revision ID: git-v1:d94bb55ed83e2616409369a35306278234af802f
[JENKINS-11097] defending against possible spurious wakeup.

Although looking at how channel.callAsync is implemented, I think this Future implementation doesn't have that problem.

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
 
98
98
    private void ping() throws IOException, InterruptedException {
99
99
        Future<?> f = channel.callAsync(new Ping());
100
 
        try {
101
 
            f.get(timeout,MILLISECONDS);
102
 
        } catch (ExecutionException e) {
103
 
            if (e.getCause() instanceof RequestAbortedException)
104
 
                return; // connection has shut down orderly.
105
 
            onDead(e);
106
 
        } catch (TimeoutException e) {
107
 
            onDead(e);
108
 
        }
 
100
        long start = System.currentTimeMillis();
 
101
        long end = start +timeout;
 
102
 
 
103
        long remaining;
 
104
        do {
 
105
            remaining = end-System.currentTimeMillis();
 
106
            try {
 
107
                f.get(Math.max(0,remaining),MILLISECONDS);
 
108
                return;
 
109
            } catch (ExecutionException e) {
 
110
                if (e.getCause() instanceof RequestAbortedException)
 
111
                    return; // connection has shut down orderly.
 
112
                onDead(e);
 
113
            } catch (TimeoutException e) {
 
114
                onDead(new TimeoutException("Ping started on "+start+" hasn't completed at "+System.currentTimeMillis()).initCause(e));
 
115
            }
 
116
        } while(remaining>0);
109
117
    }
110
118
 
111
119
    /**