优化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();
checkHttpAddressHealth();
loadSncpAddressHealth();
localEntrys.values().stream().filter(e -> !e.canceled).forEach(entry -> {
checkLocalHealth(entry);
});
remoteEntrys.values().stream().filter(entry -> "SNCP".equalsIgnoreCase(entry.protocol)).forEach(entry -> {
updateSncpAddress(entry);
});
localEntrys.values().stream()
.filter(e -> !e.canceled)
.forEach(this::checkLocalHealth);
remoteEntrys.values().stream()
.filter(entry -> "SNCP".equalsIgnoreCase(entry.protocol))
.forEach(this::updateSncpAddress);
} 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
public void completed(Integer result, A attach) {
ScheduledFuture future = this.timeoutFuture;
if (future != null) {
if (future != null && !future.isDone()) {
this.timeoutFuture = null;
future.cancel(true);
}
@@ -95,7 +95,7 @@ class AsyncNioCompletionHandler<A> implements CompletionHandler<Integer, A>, Run
@Override
public void failed(Throwable exc, A attach) {
ScheduledFuture future = this.timeoutFuture;
if (future != null) {
if (future != null && !future.isDone()) {
this.timeoutFuture = null;
future.cancel(true);
}

View File

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