优化SncpDyn
This commit is contained in:
@@ -451,7 +451,7 @@ public abstract class NodeServer {
|
||||
if (!Modifier.isPublic(serviceImplClass.getModifiers())) {
|
||||
continue;
|
||||
}
|
||||
if (serviceImplClass.getAnnotation(SncpDyn.class) != null) {
|
||||
if (Sncp.isSncpDyn(serviceImplClass)) {
|
||||
continue; //动态生成的跳过
|
||||
}
|
||||
if (entry.isExpect()) {
|
||||
|
||||
@@ -5,7 +5,10 @@
|
||||
*/
|
||||
package org.redkale.net.sncp;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import static java.lang.annotation.ElementType.METHOD;
|
||||
import static java.lang.annotation.ElementType.TYPE;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
import java.lang.annotation.*;
|
||||
import java.lang.reflect.*;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.ByteBuffer;
|
||||
@@ -54,6 +57,29 @@ public abstract class Sncp {
|
||||
md5 = d;
|
||||
}
|
||||
|
||||
/**
|
||||
* 修饰由SNCP协议动态生成的class、和method
|
||||
* 本地模式:动态生成的_DynLocalXXXXService类会打上@SncpDyn(remote = false) 的注解
|
||||
* 远程模式:动态生成的_DynRemoteXXXService类会打上@SncpDyn(remote = true) 的注解
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@Inherited
|
||||
@Documented
|
||||
@Target({METHOD, TYPE})
|
||||
@Retention(RUNTIME)
|
||||
public static @interface SncpDyn {
|
||||
|
||||
boolean remote();
|
||||
|
||||
Class type();
|
||||
|
||||
int index() default 0; //排列顺序, 主要用于Method
|
||||
}
|
||||
|
||||
private Sncp() {
|
||||
}
|
||||
|
||||
@@ -116,6 +142,10 @@ public abstract class Sncp {
|
||||
return service.getClass().getAnnotation(SncpDyn.class) != null;
|
||||
}
|
||||
|
||||
public static boolean isSncpDyn(Class serviceType) {
|
||||
return serviceType.getAnnotation(SncpDyn.class) != null;
|
||||
}
|
||||
|
||||
public static int getVersion(Service service) {
|
||||
if (service == null) {
|
||||
return -1;
|
||||
@@ -398,6 +428,7 @@ public abstract class Sncp {
|
||||
{
|
||||
av0 = cw.visitAnnotation(sncpDynDesc, true);
|
||||
av0.visit("remote", Boolean.FALSE);
|
||||
av0.visit("type", Type.getType(Type.getDescriptor(serviceImplClass)));
|
||||
av0.visitEnd();
|
||||
}
|
||||
{ //给新类加上 原有的Annotation
|
||||
@@ -719,6 +750,7 @@ public abstract class Sncp {
|
||||
{
|
||||
av0 = cw.visitAnnotation(sncpDynDesc, true);
|
||||
av0.visit("remote", Boolean.TRUE);
|
||||
av0.visit("type", Type.getType(Type.getDescriptor(serviceTypeOrImplClass)));
|
||||
av0.visitEnd();
|
||||
}
|
||||
{ //给新类加上 原有的Annotation
|
||||
|
||||
@@ -18,6 +18,7 @@ import org.redkale.convert.bson.*;
|
||||
import org.redkale.convert.json.*;
|
||||
import org.redkale.mq.*;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.net.sncp.Sncp.SncpDyn;
|
||||
import static org.redkale.net.sncp.SncpRequest.*;
|
||||
import static org.redkale.net.sncp.SncpResponse.fillRespHeader;
|
||||
import org.redkale.service.*;
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package org.redkale.net.sncp;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
import static java.lang.annotation.ElementType.*;
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* 修饰由SNCP协议动态生成的class、和method
|
||||
* 本地模式:动态生成的_DynLocalXXXXService类会打上@SncpDyn(remote = false) 的注解
|
||||
* 远程模式:动态生成的_DynRemoteXXXService类会打上@SncpDyn(remote = true) 的注解
|
||||
*
|
||||
* <p> 详情见: https://redkale.org
|
||||
* @author zhangjx
|
||||
*/
|
||||
@Inherited
|
||||
@Documented
|
||||
@Target({METHOD, TYPE})
|
||||
@Retention(RUNTIME)
|
||||
public @interface SncpDyn {
|
||||
|
||||
boolean remote();
|
||||
|
||||
int index() default 0; //排列顺序, 主要用于Method
|
||||
}
|
||||
@@ -99,12 +99,15 @@ public class SncpServer extends Server<Uint128, SncpContext, SncpRequest, SncpRe
|
||||
* @return SncpServlet
|
||||
*/
|
||||
public SncpServlet removeSncpServlet(Service sncpService) {
|
||||
if (!Sncp.isSncpDyn(sncpService)) {
|
||||
throw new SncpException(sncpService + " is not sncp dynamic-gen service");
|
||||
}
|
||||
return ((SncpDispatcherServlet) this.dispatcher).removeSncpServlet(sncpService);
|
||||
}
|
||||
|
||||
public SncpDynServlet addSncpServlet(Service sncpService) {
|
||||
if (!Sncp.isSncpDyn(sncpService)) {
|
||||
return null;
|
||||
throw new SncpException(sncpService + " is not sncp dynamic-gen service");
|
||||
}
|
||||
SncpDynServlet sds = new SncpDynServlet(BsonFactory.root().getConvert(), Sncp.getResourceName(sncpService),
|
||||
Sncp.getResourceType(sncpService), sncpService, maxTypeLength, maxNameLength);
|
||||
|
||||
@@ -927,7 +927,11 @@ public final class ResourceFactory {
|
||||
field.set(srcObj, rs);
|
||||
}
|
||||
if (rs == null && !skipCheckRequired && rc1 != null && rc1.required()) {
|
||||
throw new ResourceInjectException("resource(type=" + field.getType().getSimpleName() + ".class, field=" + field.getName() + ", name='" + rcname + "') must exists in " + srcObj.getClass().getName());
|
||||
String t = srcObj.getClass().getName();
|
||||
if (srcObj.getClass().getSimpleName().startsWith("_Dyn")) {
|
||||
t = srcObj.getClass().getSuperclass().getName();
|
||||
}
|
||||
throw new ResourceInjectException("resource(type=" + field.getType().getSimpleName() + ".class, field=" + field.getName() + ", name='" + rcname + "') must exists in " + t);
|
||||
}
|
||||
}
|
||||
} while ((clazz = clazz.getSuperclass()) != Object.class);
|
||||
|
||||
Reference in New Issue
Block a user