Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more refactoring
  • Loading branch information
cpt1gl0 committed Jun 9, 2020
commit 62970fc9727f4147b6768e4e0bc35429eb66418f
15 changes: 8 additions & 7 deletions src/main/java/hudson/remoting/PingThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public abstract class PingThread extends Thread {
private final long interval;

private final int maxTimeouts;
private int timeouts = 0;

public PingThread(Channel channel, long timeout, long interval, int maxTimeouts) {
super("Ping thread for channel "+channel);
Expand All @@ -89,20 +88,22 @@ public PingThread(Channel channel) {

public void run() {
try {
int timeouts = 0;

while(true) {
long nextCheck = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(interval);

try {
ping();
this.timeouts = 0;
timeouts = 0;
} catch (TimeoutException e) {
if (++this.timeouts >= this.maxTimeouts) {
if (++timeouts >= this.maxTimeouts) {
onDead(e);
} else {
LOGGER.log( Level.WARNING, "timeout {0}/{1} pinging {2}",
new Object[] {this.timeouts,
this.maxTimeouts,
channel.getName()} );
LOGGER.log( Level.WARNING,
"timeout {0}/{1} pinging {2}",
new Object[]
{timeouts, this.maxTimeouts, channel.getName()} );
}
} catch (ExecutionException e) {
onDead(e);
Expand Down