ClusterAgent优化
This commit is contained in:
@@ -9,6 +9,7 @@ import java.net.InetSocketAddress;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.*;
|
import java.util.concurrent.*;
|
||||||
import java.util.concurrent.atomic.*;
|
import java.util.concurrent.atomic.*;
|
||||||
|
import java.util.function.Predicate;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import org.redkale.annotation.*;
|
import org.redkale.annotation.*;
|
||||||
import org.redkale.boot.*;
|
import org.redkale.boot.*;
|
||||||
@@ -320,20 +321,11 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable {
|
|||||||
protected void deregister(NodeServer ns, String protocol, Service service, boolean realCanceled) {
|
protected void deregister(NodeServer ns, String protocol, Service service, boolean realCanceled) {
|
||||||
String serviceName = generateServiceName(ns, protocol, service);
|
String serviceName = generateServiceName(ns, protocol, service);
|
||||||
String serviceid = generateServiceId(ns, protocol, service);
|
String serviceid = generateServiceId(ns, protocol, service);
|
||||||
ClusterEntry currEntry = null;
|
Predicate<ClusterEntry> predicate =
|
||||||
for (final ClusterEntry entry : localEntrys.values()) {
|
entry -> Objects.equals(entry.serviceName, serviceName) && Objects.equals(entry.serviceid, serviceid);
|
||||||
if (Objects.equals(entry.serviceName, serviceName) && Objects.equals(entry.serviceid, serviceid)) {
|
ClusterEntry currEntry = Utility.find(localEntrys.values(), predicate);
|
||||||
currEntry = entry;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (currEntry == null) {
|
if (currEntry == null) {
|
||||||
for (final ClusterEntry entry : remoteEntrys.values()) {
|
currEntry = Utility.find(remoteEntrys.values(), predicate);
|
||||||
if (Objects.equals(entry.serviceName, serviceName) && Objects.equals(entry.serviceid, serviceid)) {
|
|
||||||
currEntry = entry;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
source.hdel(serviceName, serviceid);
|
source.hdel(serviceName, serviceid);
|
||||||
if (realCanceled && currEntry != null) {
|
if (realCanceled && currEntry != null) {
|
||||||
|
|||||||
@@ -5,8 +5,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.cluster.spi;
|
package org.redkale.cluster.spi;
|
||||||
|
|
||||||
import static org.redkale.boot.Application.*;
|
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
@@ -16,6 +14,7 @@ import java.util.logging.*;
|
|||||||
import org.redkale.annotation.*;
|
import org.redkale.annotation.*;
|
||||||
import org.redkale.annotation.AutoLoad;
|
import org.redkale.annotation.AutoLoad;
|
||||||
import org.redkale.boot.*;
|
import org.redkale.boot.*;
|
||||||
|
import static org.redkale.boot.Application.*;
|
||||||
import org.redkale.convert.ConvertDisabled;
|
import org.redkale.convert.ConvertDisabled;
|
||||||
import org.redkale.convert.json.JsonConvert;
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.inject.ResourceEvent;
|
import org.redkale.inject.ResourceEvent;
|
||||||
@@ -203,7 +202,7 @@ public abstract class ClusterAgent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ClusterEntry entry = new ClusterEntry(ns, protocol, service);
|
ClusterEntry entry = new ClusterEntry(ns, protocol, service);
|
||||||
if (entry.serviceName.trim().endsWith(".")) {
|
if (entry.serviceName.endsWith(".")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -224,9 +223,9 @@ public abstract class ClusterAgent {
|
|||||||
public abstract CompletableFuture<Set<InetSocketAddress>> queryHttpAddress(
|
public abstract CompletableFuture<Set<InetSocketAddress>> queryHttpAddress(
|
||||||
String protocol, String module, String resname);
|
String protocol, String module, String resname);
|
||||||
|
|
||||||
// 获取SNCP远程服务的可用ip列表 restype: resourceType.getName()
|
// 获取SNCP远程服务的可用ip列表 resType: resourceType.getName()
|
||||||
public abstract CompletableFuture<Set<InetSocketAddress>> querySncpAddress(
|
public abstract CompletableFuture<Set<InetSocketAddress>> querySncpAddress(
|
||||||
String protocol, String restype, String resname);
|
String protocol, String resType, String resname);
|
||||||
|
|
||||||
// 获取远程服务的可用ip列表
|
// 获取远程服务的可用ip列表
|
||||||
protected abstract CompletableFuture<Set<InetSocketAddress>> queryAddress(ClusterEntry entry);
|
protected abstract CompletableFuture<Set<InetSocketAddress>> queryAddress(ClusterEntry entry);
|
||||||
@@ -287,8 +286,8 @@ public abstract class ClusterAgent {
|
|||||||
return this.appAddress.getPort();
|
return this.appAddress.getPort();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateSncpServiceName(String protocol, String restype, String resname) {
|
public String generateSncpServiceName(String protocol, String resType, String resname) {
|
||||||
return protocol.toLowerCase() + ":" + restype + (Utility.isEmpty(resname) ? "" : ("-" + resname));
|
return protocol.toLowerCase() + ":" + resType + (Utility.isEmpty(resname) ? "" : ("-" + resname));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 也会提供给HttpMessageClusterAgent适用
|
// 也会提供给HttpMessageClusterAgent适用
|
||||||
|
|||||||
Reference in New Issue
Block a user