优化cluster
This commit is contained in:
@@ -22,8 +22,8 @@ import org.redkale.net.*;
|
|||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
import org.redkale.net.sncp.Sncp;
|
import org.redkale.net.sncp.Sncp;
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
import org.redkale.util.AnyValue.DefaultAnyValue;
|
|
||||||
import org.redkale.util.*;
|
import org.redkale.util.*;
|
||||||
|
import org.redkale.util.AnyValue.DefaultAnyValue;
|
||||||
import org.redkale.watch.*;
|
import org.redkale.watch.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -558,12 +558,12 @@ public class NodeHttpServer extends NodeServer {
|
|||||||
if (!cluster.containsPort(server.getSocketAddress().getPort())) {
|
if (!cluster.containsPort(server.getSocketAddress().getPort())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cluster.register(this, protocol, dynServletMap.keySet(), new HashSet<>());
|
cluster.register(this, protocol, dynServletMap.keySet(), new HashSet<>(), dynServletMap.keySet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void afterClusterDeregisterOnPreDestroyServices(ClusterAgent cluster, String protocol) {
|
protected void afterClusterDeregisterOnPreDestroyServices(ClusterAgent cluster, String protocol) {
|
||||||
cluster.deregister(this, protocol, dynServletMap.keySet(), new HashSet<>());
|
cluster.deregister(this, protocol, dynServletMap.keySet(), new HashSet<>(), dynServletMap.keySet());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -593,7 +593,7 @@ public abstract class NodeServer {
|
|||||||
localServices.addAll(swlist);
|
localServices.addAll(swlist);
|
||||||
//this.loadPersistData();
|
//this.loadPersistData();
|
||||||
long preinits = System.currentTimeMillis();
|
long preinits = System.currentTimeMillis();
|
||||||
preInitServices(localServices, remoteServices);
|
preInitServices(localServices, remoteServices, servletServices);
|
||||||
long preinite = System.currentTimeMillis() - preinits;
|
long preinite = System.currentTimeMillis() - preinits;
|
||||||
final List<String> slist = sb == null ? null : new CopyOnWriteArrayList<>();
|
final List<String> slist = sb == null ? null : new CopyOnWriteArrayList<>();
|
||||||
if (application.isCompileMode()) {
|
if (application.isCompileMode()) {
|
||||||
@@ -669,7 +669,7 @@ public abstract class NodeServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Service.init执行之前调用
|
//Service.init执行之前调用
|
||||||
protected void preInitServices(Set<Service> localServices, Set<Service> remoteServices) {
|
protected void preInitServices(Set<Service> localServices, Set<Service> remoteServices, Set<Service> servletServices) {
|
||||||
final ClusterAgent cluster = application.getClusterAgent();
|
final ClusterAgent cluster = application.getClusterAgent();
|
||||||
if (!application.isCompileMode() && cluster != null) {
|
if (!application.isCompileMode() && cluster != null) {
|
||||||
NodeProtocol pros = getClass().getAnnotation(NodeProtocol.class);
|
NodeProtocol pros = getClass().getAnnotation(NodeProtocol.class);
|
||||||
@@ -680,7 +680,7 @@ public abstract class NodeServer {
|
|||||||
if (!cluster.containsPort(server.getSocketAddress().getPort())) {
|
if (!cluster.containsPort(server.getSocketAddress().getPort())) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
cluster.register(this, protocol, localServices, remoteServices);
|
cluster.register(this, protocol, localServices, remoteServices, servletServices);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -690,13 +690,13 @@ public abstract class NodeServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Service.destroy执行之前调用
|
//Service.destroy执行之前调用
|
||||||
protected void preDestroyServices(Set<Service> localServices, Set<Service> remoteServices) {
|
protected void preDestroyServices(Set<Service> localServices, Set<Service> remoteServices, Set<Service> servletServices) {
|
||||||
if (!application.isCompileMode() && application.getClusterAgent() != null) { //服务注销
|
if (!application.isCompileMode() && application.getClusterAgent() != null) { //服务注销
|
||||||
final ClusterAgent cluster = application.getClusterAgent();
|
final ClusterAgent cluster = application.getClusterAgent();
|
||||||
NodeProtocol pros = getClass().getAnnotation(NodeProtocol.class);
|
NodeProtocol pros = getClass().getAnnotation(NodeProtocol.class);
|
||||||
String protocol = pros.value().toUpperCase();
|
String protocol = pros.value().toUpperCase();
|
||||||
if (cluster.containsProtocol(protocol) && cluster.containsPort(server.getSocketAddress().getPort())) {
|
if (cluster.containsProtocol(protocol) && cluster.containsPort(server.getSocketAddress().getPort())) {
|
||||||
cluster.deregister(this, protocol, localServices, remoteServices);
|
cluster.deregister(this, protocol, localServices, remoteServices, servletServices);
|
||||||
afterClusterDeregisterOnPreDestroyServices(cluster, protocol);
|
afterClusterDeregisterOnPreDestroyServices(cluster, protocol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -708,7 +708,7 @@ public abstract class NodeServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Server.start执行之后调用
|
//Server.start执行之后调用
|
||||||
protected void postStartServer(Set<Service> localServices, Set<Service> remoteServices) {
|
protected void postStartServer(Set<Service> localServices, Set<Service> remoteServices, Set<Service> servletServices) {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract ClassFilter<Filter> createFilterClassFilter();
|
protected abstract ClassFilter<Filter> createFilterClassFilter();
|
||||||
@@ -853,7 +853,7 @@ public abstract class NodeServer {
|
|||||||
interceptor.preStart(this);
|
interceptor.preStart(this);
|
||||||
}
|
}
|
||||||
server.start();
|
server.start();
|
||||||
postStartServer(localServices, remoteServices);
|
postStartServer(localServices, remoteServices, servletServices);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void shutdown() throws IOException {
|
public void shutdown() throws IOException {
|
||||||
@@ -862,7 +862,7 @@ public abstract class NodeServer {
|
|||||||
}
|
}
|
||||||
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
final StringBuilder sb = logger.isLoggable(Level.INFO) ? new StringBuilder() : null;
|
||||||
final boolean finest = logger.isLoggable(Level.FINEST);
|
final boolean finest = logger.isLoggable(Level.FINEST);
|
||||||
preDestroyServices(localServices, remoteServices);
|
preDestroyServices(localServices, remoteServices, servletServices);
|
||||||
localServices.forEach(y -> {
|
localServices.forEach(y -> {
|
||||||
long s = System.currentTimeMillis();
|
long s = System.currentTimeMillis();
|
||||||
if (finest) {
|
if (finest) {
|
||||||
|
|||||||
@@ -309,22 +309,22 @@ public class CacheClusterAgent extends ClusterAgent implements Resourcable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String generateApplicationServiceName() {
|
protected String generateApplicationServiceName() {
|
||||||
return "cluster." + super.generateApplicationServiceName();
|
return "cluster.application." + super.generateApplicationServiceName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String generateServiceName(NodeServer ns, String protocol, Service service) {
|
protected String generateServiceName(NodeServer ns, String protocol, Service service) {
|
||||||
return "cluster." + super.generateServiceName(ns, protocol, service);
|
return "cluster.service." + super.generateServiceName(ns, protocol, service);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateHttpServiceName(String protocol, String module, String resname) {
|
public String generateHttpServiceName(String protocol, String module, String resname) {
|
||||||
return "cluster." + super.generateHttpServiceName(protocol, module, resname);
|
return "cluster.service." + super.generateHttpServiceName(protocol, module, resname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateSncpServiceName(String protocol, String restype, String resname) {
|
public String generateSncpServiceName(String protocol, String restype, String resname) {
|
||||||
return "cluster." + super.generateSncpServiceName(protocol, restype, resname);
|
return "cluster.service." + super.generateSncpServiceName(protocol, restype, resname);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -136,12 +136,12 @@ public abstract class ClusterAgent {
|
|||||||
public abstract void deregister(Application application);
|
public abstract void deregister(Application application);
|
||||||
|
|
||||||
//注册服务, 在NodeService调用Service.init方法之前调用
|
//注册服务, 在NodeService调用Service.init方法之前调用
|
||||||
public void register(NodeServer ns, String protocol, Set<Service> localServices, Set<Service> remoteServices) {
|
public void register(NodeServer ns, String protocol, Set<Service> localServices, Set<Service> remoteServices, Set<Service> servletServices) {
|
||||||
if (localServices.isEmpty()) {
|
if (servletServices.isEmpty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//注册本地模式
|
//注册本地模式
|
||||||
for (Service service : localServices) {
|
for (Service service : servletServices) {
|
||||||
if (!canRegister(ns, protocol, service)) {
|
if (!canRegister(ns, protocol, service)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -159,9 +159,9 @@ public abstract class ClusterAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//注销服务, 在NodeService调用Service.destroy 方法之前调用
|
//注销服务, 在NodeService调用Service.destroy 方法之前调用
|
||||||
public void deregister(NodeServer ns, String protocol, Set<Service> localServices, Set<Service> remoteServices) {
|
public void deregister(NodeServer ns, String protocol, Set<Service> localServices, Set<Service> remoteServices, Set<Service> servletServices) {
|
||||||
//注销本地模式 远程模式不注册
|
//注销本地模式 远程模式不注册
|
||||||
for (Service service : localServices) {
|
for (Service service : servletServices) {
|
||||||
if (!canRegister(ns, protocol, service)) {
|
if (!canRegister(ns, protocol, service)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -253,11 +253,11 @@ public abstract class ClusterAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String generateApplicationServiceName() {
|
protected String generateApplicationServiceName() {
|
||||||
return "application.node" + (appName == null || appName.isEmpty() ? "" : ("." + appName));
|
return "node" + (appName == null || appName.isEmpty() ? "" : ("." + appName));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String generateApplicationServiceType() {
|
protected String generateApplicationServiceType() {
|
||||||
return "application.nodes";
|
return "nodes";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected String generateApplicationServiceId() {
|
protected String generateApplicationServiceId() {
|
||||||
@@ -281,7 +281,7 @@ public abstract class ClusterAgent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected String serviceSeparator() {
|
protected String serviceSeparator() {
|
||||||
return "-";
|
return ".";
|
||||||
}
|
}
|
||||||
|
|
||||||
public String generateSncpServiceName(String protocol, String restype, String resname) {
|
public String generateSncpServiceName(String protocol, String restype, String resname) {
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import static org.redkale.boot.Application.RESNAME_APP_NODEID;
|
|||||||
import org.redkale.convert.Convert;
|
import org.redkale.convert.Convert;
|
||||||
import org.redkale.convert.ConvertFactory;
|
import org.redkale.convert.ConvertFactory;
|
||||||
import org.redkale.convert.ConvertType;
|
import org.redkale.convert.ConvertType;
|
||||||
|
import org.redkale.convert.json.JsonConvert;
|
||||||
import org.redkale.net.Servlet;
|
import org.redkale.net.Servlet;
|
||||||
import org.redkale.net.WorkThread;
|
import org.redkale.net.WorkThread;
|
||||||
import org.redkale.net.http.*;
|
import org.redkale.net.http.*;
|
||||||
@@ -248,7 +249,7 @@ public abstract class MessageAgent implements Resourcable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
String typestr = consumer.getClass().getName();
|
String typestr = consumer.getClass().getName();
|
||||||
String topicstr = topics.size() == 1 ? topics.get(0) : topics.toString();
|
String topicstr = JsonConvert.root().convertTo(topics.size() == 1 ? topics.get(0) : topics);
|
||||||
if (typestr.length() > typeMax.get()) {
|
if (typestr.length() > typeMax.get()) {
|
||||||
typeMax.set(typestr.length());
|
typeMax.set(typestr.length());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user