Sncp.getServiceType 优化
This commit is contained in:
@@ -2437,7 +2437,7 @@ public final class Application {
|
||||
try {
|
||||
if (source instanceof Service) {
|
||||
long s = System.currentTimeMillis();
|
||||
((Service) source).destroy(Sncp.isSncpDyn((Service) source) ? Sncp.getConf((Service) source) : null);
|
||||
((Service) source).destroy(Sncp.isSncpDyn((Service) source) ? Sncp.getResourceConf((Service) source) : null);
|
||||
logger.info(source + " destroy in " + (System.currentTimeMillis() - s) + " ms");
|
||||
// } else {
|
||||
// source.getClass().getMethod("close").invoke(source);
|
||||
@@ -2454,7 +2454,7 @@ public final class Application {
|
||||
try {
|
||||
if (source instanceof Service) {
|
||||
long s = System.currentTimeMillis();
|
||||
((Service) source).destroy(Sncp.isSncpDyn((Service) source) ? Sncp.getConf((Service) source) : null);
|
||||
((Service) source).destroy(Sncp.isSncpDyn((Service) source) ? Sncp.getResourceConf((Service) source) : null);
|
||||
logger.info(source + " destroy in " + (System.currentTimeMillis() - s) + " ms");
|
||||
// } else {
|
||||
// source.getClass().getMethod("close").invoke(source);
|
||||
|
||||
@@ -388,7 +388,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
}
|
||||
stream.forEach((service) -> {
|
||||
try {
|
||||
final Class stype = Sncp.getServiceType(service);
|
||||
final Class stype = Sncp.getResourceType(service);
|
||||
final String name = Sncp.getResourceName(service);
|
||||
RestService rs = (RestService) stype.getAnnotation(RestService.class);
|
||||
if (rs == null || rs.ignore()) {
|
||||
@@ -430,7 +430,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
mappings[i] = prefix2 + mappings[i];
|
||||
}
|
||||
synchronized (rests) {
|
||||
rests.add(new AbstractMap.SimpleEntry<>(Sncp.getServiceType(service).getName() + "#" + name, mappings));
|
||||
rests.add(new AbstractMap.SimpleEntry<>(Sncp.getResourceType(service).getName() + "#" + name, mappings));
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
|
||||
@@ -616,7 +616,7 @@ public abstract class NodeServer {
|
||||
} else {
|
||||
localServices.stream().forEach(y -> {
|
||||
long s = System.currentTimeMillis();
|
||||
y.init(Sncp.getConf(y));
|
||||
y.init(Sncp.getResourceConf(y));
|
||||
long e = System.currentTimeMillis() - s;
|
||||
String serstr = Sncp.toSimpleString(y, maxNameLength, maxTypeLength);
|
||||
if (slist != null) {
|
||||
@@ -847,7 +847,7 @@ public abstract class NodeServer {
|
||||
if (finest) {
|
||||
logger.finest(y + " is destroying");
|
||||
}
|
||||
y.destroy(Sncp.getConf(y));
|
||||
y.destroy(Sncp.getResourceConf(y));
|
||||
if (finest) {
|
||||
logger.finest(y + " was destroyed");
|
||||
}
|
||||
|
||||
@@ -14,8 +14,8 @@ import java.util.logging.Logger;
|
||||
import org.redkale.annotation.AutoLoad;
|
||||
import org.redkale.annotation.*;
|
||||
import org.redkale.annotation.ResourceListener;
|
||||
import static org.redkale.boot.Application.*;
|
||||
import org.redkale.boot.*;
|
||||
import static org.redkale.boot.Application.*;
|
||||
import org.redkale.convert.ConvertDisabled;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.mq.MessageMultiConsumer;
|
||||
@@ -403,7 +403,7 @@ public abstract class ClusterAgent {
|
||||
this.serviceName = generateServiceName(ns, protocol, service);
|
||||
this.checkid = generateCheckId(ns, protocol, service);
|
||||
this.checkName = generateCheckName(ns, protocol, service);
|
||||
this.serviceType = Sncp.getServiceType(service).getName();
|
||||
this.serviceType = Sncp.getResourceType(service).getName();
|
||||
this.protocol = protocol;
|
||||
InetSocketAddress addr = ns.getSocketAddress();
|
||||
String host = addr.getHostString();
|
||||
|
||||
@@ -282,7 +282,7 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
||||
T servlet = null;
|
||||
final boolean sncp = Sncp.isSncpDyn(service);
|
||||
final String resname = name == null ? (sncp ? Sncp.getResourceName(service) : "") : name;
|
||||
final Class<S> serviceType = Sncp.getServiceType(service);
|
||||
final Class<S> serviceType = Sncp.getResourceType(service);
|
||||
if (name != null) {
|
||||
for (final HttpServlet item : ((HttpDispatcherServlet) this.dispatcher).getServlets()) {
|
||||
if (!(item instanceof HttpServlet)) {
|
||||
@@ -343,7 +343,7 @@ public class HttpServer extends Server<String, HttpContext, HttpRequest, HttpRes
|
||||
throw new HttpException(serviceType + " generate rest servlet error", e);
|
||||
}
|
||||
if (first) {
|
||||
this.dispatcher.addServlet(servlet, prefix, sncp ? Sncp.getConf(service) : null);
|
||||
this.dispatcher.addServlet(servlet, prefix, sncp ? Sncp.getResourceConf(service) : null);
|
||||
}
|
||||
return servlet;
|
||||
}
|
||||
|
||||
@@ -299,7 +299,7 @@ public final class Rest {
|
||||
if (controller != null && !controller.name().isEmpty()) {
|
||||
return controller.name();
|
||||
}
|
||||
final Class serviceType = Sncp.getServiceType(service);
|
||||
final Class serviceType = Sncp.getResourceType(service);
|
||||
return serviceType.getSimpleName().replaceAll("Service.*$", "").toLowerCase();
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@ import java.lang.reflect.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import java.security.*;
|
||||
import java.util.*;
|
||||
import org.redkale.annotation.*;
|
||||
import org.redkale.annotation.ResourceType;
|
||||
@@ -45,18 +44,6 @@ public abstract class Sncp {
|
||||
|
||||
static final String FIELDPREFIX = "_redkale";
|
||||
|
||||
private static final MessageDigest md5;
|
||||
|
||||
static { //64进制
|
||||
MessageDigest d = null;
|
||||
try {
|
||||
d = MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
md5 = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修饰由SNCP协议动态生成的class、和method
|
||||
* 本地模式:动态生成的_DynLocalXXXXService类会打上@SncpDyn(remote = false) 的注解
|
||||
@@ -126,11 +113,7 @@ public abstract class Sncp {
|
||||
if (name == null || name.isEmpty()) {
|
||||
return Uint128.ZERO;
|
||||
}
|
||||
byte[] bytes = name.trim().getBytes();
|
||||
synchronized (md5) {
|
||||
bytes = md5.digest(bytes);
|
||||
}
|
||||
return Uint128.create(bytes);
|
||||
return Uint128.create(Utility.md5(name.trim().getBytes()));
|
||||
}
|
||||
|
||||
public static boolean isRemote(Service service) {
|
||||
@@ -147,16 +130,10 @@ public abstract class Sncp {
|
||||
}
|
||||
|
||||
public static int getVersion(Service service) {
|
||||
if (service == null) {
|
||||
return -1;
|
||||
}
|
||||
return -1; //暂不实现Version
|
||||
}
|
||||
|
||||
public static String getResourceName(Service service) {
|
||||
if (service == null) {
|
||||
return null;
|
||||
}
|
||||
Resource res = service.getClass().getAnnotation(Resource.class);
|
||||
if (res != null) {
|
||||
return res.name();
|
||||
@@ -165,28 +142,16 @@ public abstract class Sncp {
|
||||
return res2 == null ? null : res2.name();
|
||||
}
|
||||
|
||||
public static Class getServiceType(Service service) {
|
||||
ResourceType rt = service.getClass().getAnnotation(ResourceType.class);
|
||||
if (rt != null) {
|
||||
return rt.value();
|
||||
}
|
||||
org.redkale.util.ResourceType rt2 = service.getClass().getAnnotation(org.redkale.util.ResourceType.class);
|
||||
return rt2 == null ? service.getClass() : rt2.value();
|
||||
}
|
||||
|
||||
public static Class getResourceType(Service service) {
|
||||
if (service == null) {
|
||||
return null;
|
||||
}
|
||||
ResourceType type = service.getClass().getAnnotation(ResourceType.class);
|
||||
if (type != null) {
|
||||
return type.value();
|
||||
}
|
||||
org.redkale.util.ResourceType rt2 = service.getClass().getAnnotation(org.redkale.util.ResourceType.class);
|
||||
return rt2 == null ? getServiceType(service) : rt2.value();
|
||||
return rt2 == null ? service.getClass() : rt2.value();
|
||||
}
|
||||
|
||||
public static AnyValue getConf(Service service) {
|
||||
public static AnyValue getResourceConf(Service service) {
|
||||
if (service == null || !isSncpDyn(service)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -111,7 +111,7 @@ public class SncpServer extends Server<Uint128, SncpContext, SncpRequest, SncpRe
|
||||
}
|
||||
SncpDynServlet sds = new SncpDynServlet(BsonFactory.root().getConvert(), Sncp.getResourceName(sncpService),
|
||||
Sncp.getResourceType(sncpService), sncpService, maxTypeLength, maxNameLength);
|
||||
this.dispatcher.addServlet(sds, null, Sncp.getConf(sncpService));
|
||||
this.dispatcher.addServlet(sds, null, Sncp.getResourceConf(sncpService));
|
||||
return sds;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public abstract class AbstractService implements Service {
|
||||
* @return Class
|
||||
*/
|
||||
protected Class serviceType() {
|
||||
return Sncp.getServiceType(this);
|
||||
return Sncp.getResourceType(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user