优化client

This commit is contained in:
redkale
2023-12-06 21:35:02 +08:00
parent b3ea041b67
commit 989153815f
3 changed files with 13 additions and 11 deletions

View File

@@ -130,14 +130,14 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable {
checkApplicationHealth(); checkApplicationHealth();
checkHttpAddressHealth(); checkHttpAddressHealth();
loadSncpAddressHealth(); loadSncpAddressHealth();
localEntrys.values().stream().filter(e -> !e.canceled).forEach(entry -> { localEntrys.values().stream()
checkLocalHealth(entry); .filter(e -> !e.canceled)
}); .forEach(this::checkLocalHealth);
remoteEntrys.values().stream().filter(entry -> "SNCP".equalsIgnoreCase(entry.protocol)).forEach(entry -> { remoteEntrys.values().stream()
updateSncpAddress(entry); .filter(entry -> "SNCP".equalsIgnoreCase(entry.protocol))
}); .forEach(this::updateSncpAddress);
} catch (Exception e) { } catch (Exception e) {
logger.log(Level.SEVERE, "scheduleAtFixedRate check error", e instanceof CompletionException ? ((CompletionException) e).getCause() : e); logger.log(Level.SEVERE, "scheduleAtFixedRate check error", e);
} }
}; };
} }

View File

@@ -67,7 +67,7 @@ class AsyncNioCompletionHandler<A> implements CompletionHandler<Integer, A>, Run
@Override @Override
public void completed(Integer result, A attach) { public void completed(Integer result, A attach) {
ScheduledFuture future = this.timeoutFuture; ScheduledFuture future = this.timeoutFuture;
if (future != null) { if (future != null && !future.isDone()) {
this.timeoutFuture = null; this.timeoutFuture = null;
future.cancel(true); future.cancel(true);
} }
@@ -95,7 +95,7 @@ class AsyncNioCompletionHandler<A> implements CompletionHandler<Integer, A>, Run
@Override @Override
public void failed(Throwable exc, A attach) { public void failed(Throwable exc, A attach) {
ScheduledFuture future = this.timeoutFuture; ScheduledFuture future = this.timeoutFuture;
if (future != null) { if (future != null && !future.isDone()) {
this.timeoutFuture = null; this.timeoutFuture = null;
future.cancel(true); future.cancel(true);
} }

View File

@@ -137,8 +137,10 @@ public abstract class Client<C extends ClientConnection<R, P>, R extends ClientR
try { try {
R req = pingRequestSupplier.get(); R req = pingRequestSupplier.get();
if (req == null) { //可能运行中进行重新赋值 if (req == null) { //可能运行中进行重新赋值
timeoutFuture.cancel(true); if (timeoutFuture != null && !timeoutFuture.isDone()) {
timeoutFuture = null; timeoutFuture.cancel(true);
timeoutFuture = null;
}
return; return;
} }
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();