From e66ee1bab3dea49362614e7b4714b58c794c5ab5 Mon Sep 17 00:00:00 2001 From: wentch <22250530@qq.com> Date: Wed, 6 Jan 2016 10:03:42 +0800 Subject: [PATCH] --- src/org/redkale/net/sncp/Sncp.java | 56 ++++++++++++++++-------- src/org/redkale/net/sncp/SncpClient.java | 22 ++++++---- 2 files changed, 51 insertions(+), 27 deletions(-) diff --git a/src/org/redkale/net/sncp/Sncp.java b/src/org/redkale/net/sncp/Sncp.java index b47b222bd..0653e3996 100644 --- a/src/org/redkale/net/sncp/Sncp.java +++ b/src/org/redkale/net/sncp/Sncp.java @@ -109,13 +109,13 @@ public abstract class Sncp { *
* public class TestService implements Service{
*
- * public String queryNode(){
+ * public String findSomeThing(){
* return "hello";
* }
*
* @MultiRun(selfrun = false)
* public void createSomeThing(TestBean bean){
- * "xxxxx" + bean;
+ * //do something
* }
*
* @MultiRun
@@ -148,28 +148,28 @@ public abstract class Sncp {
*
* @Override
* public void createSomeThing(TestBean bean){
- * _createSomeThing(false, true, true, bean);
+ * this._createSomeThing(false, true, true, bean);
* }
*
* @SncpDyn(remote = false, index = 0)
* public void _createSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, TestBean bean){
* if(selfrunnable) super.createSomeThing(bean);
* if (_client== null) return;
- * if (samerunnable) _client.remote(_convert, _sameGroupTransports, 1, true, false, false, bean);
- * if (diffrunnable) _client.remote(_convert, _diffGroupTransports, 1, true, true, false, bean);
+ * if (samerunnable) _client.remote(_convert, _sameGroupTransports, 0, true, false, false, bean);
+ * if (diffrunnable) _client.remote(_convert, _diffGroupTransports, 0, true, true, false, bean);
* }
*
* @Override
* public String updateSomeThing(String id){
- * return _updateSomeThing(true, true, true, id);
+ * return this._updateSomeThing(true, true, true, id);
* }
*
* @SncpDyn(remote = false, index = 1)
* public String _updateSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, String id){
* String rs = super.updateSomeThing(id);
* if (_client== null) return;
- * if (samerunnable) _client.remote(_convert, _sameGroupTransports, 0, true, false, false, id);
- * if (diffrunnable) _client.remote(_convert, _diffGroupTransports, 0, true, true, false, id);
+ * if (samerunnable) _client.remote(_convert, _sameGroupTransports, 1, true, false, false, id);
+ * if (diffrunnable) _client.remote(_convert, _diffGroupTransports, 1, true, true, false, id);
* return rs;
* }
* }
@@ -189,7 +189,7 @@ public abstract class Sncp {
int mod = serviceClass.getModifiers();
if (!java.lang.reflect.Modifier.isPublic(mod)) return serviceClass;
if (java.lang.reflect.Modifier.isAbstract(mod)) return serviceClass;
- final List methods = SncpClient.parseMethod(serviceClass, false);
+ final List methods = SncpClient.parseMethod(serviceClass);
final boolean hasMultiRun = methods.stream().filter(x -> x.getAnnotation(MultiRun.class) != null).findAny().isPresent();
final String supDynName = serviceClass.getName().replace('.', '/');
final String clientName = SncpClient.class.getName().replace('.', '/');
@@ -293,6 +293,7 @@ public abstract class Sncp {
final Annotation[][] anns = method.getParameterAnnotations();
for (int k = 0; k < anns.length; k++) {
for (Annotation ann : anns[k]) {
+ if (ann instanceof SncpDyn || ann instanceof MultiRun) continue; //必须过滤掉 MultiRun、SncpDyn,否则生成远程模式Service时会出错
visitAnnotation(mv.visitParameterAnnotation(k, Type.getDescriptor(ann.annotationType()), true), ann);
}
}
@@ -345,6 +346,7 @@ public abstract class Sncp {
final Annotation[][] anns = method.getParameterAnnotations();
for (int k = 0; k < anns.length; k++) {
for (Annotation ann : anns[k]) {
+ if (ann instanceof SncpDyn || ann instanceof MultiRun) continue; //必须过滤掉 MultiRun、SncpDyn,否则生成远程模式Service时会出错
visitAnnotation(mv.visitParameterAnnotation(k, Type.getDescriptor(ann.annotationType()), true), ann);
}
}
@@ -722,7 +724,7 @@ public abstract class Sncp {
try {
Field e = newClazz.getDeclaredField("_client");
e.setAccessible(true);
- client = new SncpClient(name, executor, hash(serviceClass), false, newClazz, true, clientAddress, groups);
+ client = new SncpClient(name, executor, hash(serviceClass), false, newClazz, clientAddress, groups);
e.set(rs, client);
} catch (NoSuchFieldException ne) {
}
@@ -794,19 +796,29 @@ public abstract class Sncp {
* return _selfstring == null ? super.toString() : _selfstring;
* }
*
- * @Override
- * public boolean testChange(TestBean bean) {
- * return _client.remote(_convert, _transport, 0, bean);
+ * @SncpDyn(remote = false, index = 0)
+ * public void _createSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, TestBean bean){
+ * _client.remote(_convert, _transport, 0, selfrunnable, samerunnable, diffrunnable, bean);
+ * }
+ *
+ * @SncpDyn(remote = false, index = 1)
+ * public String _updateSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, String id){
+ * return _client.remote(_convert, _transport, 1, selfrunnable, samerunnable, diffrunnable, id);
* }
*
* @Override
- * public TestBean findTestBean(long id) {
- * return _client.remote(_convert, _transport, 1, id);
+ * public void createSomeThing(TestBean bean){
+ * _client.remote(_convert, _transport, 2, bean);
* }
*
* @Override
- * public void runTestBean(long id, TestBean bean) {
- * _client.remote(_convert, _transport, 2, id, bean);
+ * public String findSomeThing(){
+ * return _client.remote(_convert, _transport, 3);
+ * }
+ *
+ * @Override
+ * public String updateSomeThing(String id){
+ * return _client.remote(_convert, _transport, 4, id);
* }
* }
*
@@ -840,7 +852,7 @@ public abstract class Sncp {
final String anyValueDesc = Type.getDescriptor(AnyValue.class);
ClassLoader loader = Sncp.class.getClassLoader();
String newDynName = supDynName.substring(0, supDynName.lastIndexOf('/') + 1) + REMOTEPREFIX + serviceClass.getSimpleName();
- final SncpClient client = new SncpClient(name, executor, hash(serviceClass), true, createLocalServiceClass(name, serviceClass), false, clientAddress, groups);
+ final SncpClient client = new SncpClient(name, executor, hash(serviceClass), true, createLocalServiceClass(name, serviceClass), clientAddress, groups);
try {
Class newClazz = Class.forName(newDynName.replace('/', '.'));
T rs = (T) newClazz.newInstance();
@@ -946,6 +958,14 @@ public abstract class Sncp {
{
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, method.getName(), Type.getMethodDescriptor(method), null, null));
//mv.setDebug(true);
+ { //给参数加上 Annotation
+ final Annotation[][] anns = method.getParameterAnnotations();
+ for (int k = 0; k < anns.length; k++) {
+ for (Annotation ann : anns[k]) {
+ visitAnnotation(mv.visitParameterAnnotation(k, Type.getDescriptor(ann.annotationType()), true), ann);
+ }
+ }
+ }
mv.visitVarInsn(ALOAD, 0);
mv.visitFieldInsn(GETFIELD, newDynName, "_client", clientDesc);
mv.visitVarInsn(ALOAD, 0);
diff --git a/src/org/redkale/net/sncp/SncpClient.java b/src/org/redkale/net/sncp/SncpClient.java
index aeb89ef7f..8bfa1ab16 100644
--- a/src/org/redkale/net/sncp/SncpClient.java
+++ b/src/org/redkale/net/sncp/SncpClient.java
@@ -144,7 +144,7 @@ public final class SncpClient {
protected final Consumer