Skip to content

Commit

Permalink
refactor cancel future.
Browse files Browse the repository at this point in the history
  • Loading branch information
zonghaishang committed Jan 10, 2019
1 parent 740be9c commit 5fdd75b
Showing 1 changed file with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,7 @@ private synchronized void initConnectStatusCheckCommand() {
@Override
public void run() {
try {

/**
* If the provider service is detected offline,
* the client should not attempt to connect again.
*
* issue: https://github.com/apache/incubator-dubbo/issues/3158
*/
if(isClosed()) {
ScheduledFuture<?> future = reconnectExecutorFuture;
if(future != null && !future.isCancelled()){
/**
* Client has been destroyed and
* scheduled task should be cancelled.
*/
future.cancel(true);
}
return;
}
if (cancelFutureIfOffline()) return;

if (!isConnected()) {
connect();
Expand All @@ -191,7 +174,29 @@ public void run() {
}
}
}

private boolean cancelFutureIfOffline() {
/**
* If the provider service is detected offline,
* the client should not attempt to connect again.
*
* issue: https://github.com/apache/incubator-dubbo/issues/3158
*/
if(isClosed()) {
ScheduledFuture<?> future = reconnectExecutorFuture;
if(future != null && !future.isCancelled()){
/**
* Client has been destroyed and
* scheduled task should be cancelled.
*/
future.cancel(true);
}
return true;
}
return false;
}
};

reconnectExecutorFuture = reconnectExecutorService.scheduleWithFixedDelay(connectStatusCheckCommand, reconnect, reconnect, TimeUnit.MILLISECONDS);
}
}
Expand Down

0 comments on commit 5fdd75b

Please sign in to comment.