This commit is contained in:
@@ -99,76 +99,78 @@ public abstract class Sncp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isRemote(Service service) {
|
public static boolean isRemote(Service service) {
|
||||||
return service.getClass().getName().startsWith(REMOTEPREFIX);
|
SncpDyn dyn = service.getClass().getAnnotation(SncpDyn.class);
|
||||||
|
return dyn != null && dyn.remote();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* public class TestService implements Service{
|
* public class TestService implements Service{
|
||||||
*
|
*
|
||||||
* public String queryNode(){
|
* public String queryNode(){
|
||||||
* return "hello";
|
* return "hello";
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @MultiRun
|
* @MultiRun
|
||||||
* public String updateSomeThing(String id){
|
* public String updateSomeThing(String id){
|
||||||
* return "hello" + id;
|
* return "hello" + id;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @MultiRun(selfrun = false)
|
* @MultiRun(selfrun = false)
|
||||||
* public void createSomeThing(TestBean bean){
|
* public void createSomeThing(TestBean bean){
|
||||||
* "xxxxx" + bean;
|
* "xxxxx" + bean;
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
|
* @SncpDyn
|
||||||
* public final class _DynLocalTestService extends TestService{
|
* public final class _DynLocalTestService extends TestService{
|
||||||
*
|
*
|
||||||
* @Resource
|
* @Resource
|
||||||
* private BsonConvert _convert;
|
* private BsonConvert _convert;
|
||||||
*
|
*
|
||||||
* private Transport[] _sameGroupTransports;
|
* private Transport[] _sameGroupTransports;
|
||||||
*
|
*
|
||||||
* private Transport[] _diffGroupTransports;
|
* private Transport[] _diffGroupTransports;
|
||||||
*
|
*
|
||||||
* private SncpClient _client;
|
* private SncpClient _client;
|
||||||
*
|
*
|
||||||
* private String _selfstring;
|
* private String _selfstring;
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public final String name() {
|
* public final String name() {
|
||||||
* return "";
|
* return "";
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public String toString() {
|
* public String toString() {
|
||||||
* return _selfstring == null ? super.toString() : _selfstring;
|
* return _selfstring == null ? super.toString() : _selfstring;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public String updateSomeThing(String id){
|
* public String updateSomeThing(String id){
|
||||||
* return _updateSomeThing(true, true, true, id);
|
* return _updateSomeThing(true, true, true, id);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @SncpDyn
|
* @SncpDyn
|
||||||
* public String _updateSomeThing(boolean canselfrun, boolean cansamerun, boolean candiffrun, String id){
|
* public String _updateSomeThing(boolean canselfrun, boolean cansamerun, boolean candiffrun, String id){
|
||||||
* String rs = super.updateSomeThing(id);
|
* String rs = super.updateSomeThing(id);
|
||||||
* if (_client== null) return;
|
* if (_client== null) return;
|
||||||
* _client.remote(_convert, _sameGroupTransports, cansamerun, 0, true, false, false, id);
|
* _client.remote(_convert, _sameGroupTransports, cansamerun, 0, true, false, false, id);
|
||||||
* _client.remote(_convert, _diffGroupTransports, candiffrun, 0, true, true, false, id);
|
* _client.remote(_convert, _diffGroupTransports, candiffrun, 0, true, true, false, id);
|
||||||
* return rs;
|
* return rs;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public void createSomeThing(TestBean bean){
|
* public void createSomeThing(TestBean bean){
|
||||||
* _createSomeThing(false, true, true, bean);
|
* _createSomeThing(false, true, true, bean);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @SncpDyn
|
* @SncpDyn
|
||||||
* public void _createSomeThing(boolean canselfrun, boolean cansamerun, boolean candiffrun, TestBean bean){
|
* public void _createSomeThing(boolean canselfrun, boolean cansamerun, boolean candiffrun, TestBean bean){
|
||||||
* if(canselfrun) super.createSomeThing(bean);
|
* if(canselfrun) super.createSomeThing(bean);
|
||||||
* if (_client== null) return;
|
* if (_client== null) return;
|
||||||
* _client.remote(_convert, _sameGroupTransports, cansamerun, 1, true, false, false, bean);
|
* _client.remote(_convert, _sameGroupTransports, cansamerun, 1, true, false, false, bean);
|
||||||
* _client.remote(_convert, _diffGroupTransports, candiffrun, 1, true, true, false, bean);
|
* _client.remote(_convert, _diffGroupTransports, candiffrun, 1, true, true, false, bean);
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* 创建Service的本地模式Class
|
* 创建Service的本地模式Class
|
||||||
@@ -214,6 +216,7 @@ public abstract class Sncp {
|
|||||||
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null);
|
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null);
|
||||||
{
|
{
|
||||||
av0 = cw.visitAnnotation(sncpDynDesc, true);
|
av0 = cw.visitAnnotation(sncpDynDesc, true);
|
||||||
|
av0.visit("remote", Boolean.FALSE);
|
||||||
av0.visitEnd();
|
av0.visitEnd();
|
||||||
}
|
}
|
||||||
if (hasMultiRun) {
|
if (hasMultiRun) {
|
||||||
@@ -346,6 +349,7 @@ public abstract class Sncp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
av0 = mv.visitAnnotation(sncpDynDesc, true);
|
av0 = mv.visitAnnotation(sncpDynDesc, true);
|
||||||
|
av0.visit("remote", Boolean.FALSE);
|
||||||
av0.visit("index", index);
|
av0.visit("index", index);
|
||||||
av0.visitEnd();
|
av0.visitEnd();
|
||||||
Label l1 = new Label();
|
Label l1 = new Label();
|
||||||
@@ -762,41 +766,42 @@ public abstract class Sncp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @SncpDyn(remote = true)
|
||||||
* public final class _DynRemoteTestService extends TestService{
|
* public final class _DynRemoteTestService extends TestService{
|
||||||
*
|
*
|
||||||
* @Resource
|
* @Resource
|
||||||
* private BsonConvert _convert;
|
* private BsonConvert _convert;
|
||||||
*
|
*
|
||||||
* private Transport _transport;
|
* private Transport _transport;
|
||||||
*
|
*
|
||||||
* private SncpClient _client;
|
* private SncpClient _client;
|
||||||
*
|
*
|
||||||
* private String _selfstring;
|
* private String _selfstring;
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public final String name() {
|
* public final String name() {
|
||||||
* return "";
|
* return "";
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public String toString() {
|
* public String toString() {
|
||||||
* return _selfstring == null ? super.toString() : _selfstring;
|
* return _selfstring == null ? super.toString() : _selfstring;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public boolean testChange(TestBean bean) {
|
* public boolean testChange(TestBean bean) {
|
||||||
* return _client.remote(_convert, _transport, 0, bean);
|
* return _client.remote(_convert, _transport, 0, bean);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public TestBean findTestBean(long id) {
|
* public TestBean findTestBean(long id) {
|
||||||
* return _client.remote(_convert, _transport, 1, id);
|
* return _client.remote(_convert, _transport, 1, id);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public void runTestBean(long id, TestBean bean) {
|
* public void runTestBean(long id, TestBean bean) {
|
||||||
* _client.remote(_convert, _transport, 2, id, bean);
|
* _client.remote(_convert, _transport, 2, id, bean);
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* 创建远程模式的Service实例
|
* 创建远程模式的Service实例
|
||||||
@@ -861,6 +866,7 @@ public abstract class Sncp {
|
|||||||
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null);
|
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null);
|
||||||
{
|
{
|
||||||
av0 = cw.visitAnnotation(sncpDynDesc, true);
|
av0 = cw.visitAnnotation(sncpDynDesc, true);
|
||||||
|
av0.visit("remote", Boolean.TRUE);
|
||||||
av0.visitEnd();
|
av0.visitEnd();
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 修饰由SNCP协议动态生成的class、和method
|
* 修饰由SNCP协议动态生成的class、和method
|
||||||
* 本地模式:动态生成的_DynLocalXXXService类、其带有@MultiRun方法均会打上@SncpDyn 的注解
|
* 本地模式:动态生成的_DynLocalXXXService类、其带有@MultiRun方法均会打上@SncpDyn(remote = false, index=N) 的注解
|
||||||
* 远程模式:动态生成的_DynRemoteXXXService类会打上@SncpDyn 的注解
|
* 远程模式:动态生成的_DynRemoteXXXService类会打上@SncpDyn(remote = true) 的注解
|
||||||
*
|
*
|
||||||
* @see http://www.redkale.org
|
* @see http://www.redkale.org
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
@@ -23,5 +23,7 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
public @interface SncpDyn {
|
public @interface SncpDyn {
|
||||||
|
|
||||||
int index() default 0; //排列顺序, 一般用于Method
|
boolean remote();
|
||||||
|
|
||||||
|
int index() default 0; //排列顺序, 主要用于Method
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user