This commit is contained in:
@@ -10,6 +10,7 @@ import com.wentch.redkale.net.*;
|
|||||||
import com.wentch.redkale.net.sncp.SncpClient.SncpAction;
|
import com.wentch.redkale.net.sncp.SncpClient.SncpAction;
|
||||||
import com.wentch.redkale.service.*;
|
import com.wentch.redkale.service.*;
|
||||||
import com.wentch.redkale.util.*;
|
import com.wentch.redkale.util.*;
|
||||||
|
import java.lang.annotation.*;
|
||||||
import java.lang.reflect.*;
|
import java.lang.reflect.*;
|
||||||
import java.net.*;
|
import java.net.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -330,6 +331,14 @@ public abstract class Sncp {
|
|||||||
{ //原始方法
|
{ //原始方法
|
||||||
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC + (method.isVarArgs() ? ACC_VARARGS : 0), method.getName(), methodDesc, null, null));
|
mv = new DebugMethodVisitor(cw.visitMethod(ACC_PUBLIC + (method.isVarArgs() ? ACC_VARARGS : 0), method.getName(), methodDesc, null, null));
|
||||||
//mv.setDebug(true);
|
//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.visitVarInsn(ALOAD, 0);
|
||||||
mv.visitInsn(mrun.selfrun() ? ICONST_1 : ICONST_0);
|
mv.visitInsn(mrun.selfrun() ? ICONST_1 : ICONST_0);
|
||||||
mv.visitInsn(mrun.samerun() ? ICONST_1 : ICONST_0);
|
mv.visitInsn(mrun.samerun() ? ICONST_1 : ICONST_0);
|
||||||
@@ -622,6 +631,52 @@ public abstract class Sncp {
|
|||||||
return (Class<T>) newClazz;
|
return (Class<T>) newClazz;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void visitAnnotation(final AnnotationVisitor av, final Annotation ann) {
|
||||||
|
try {
|
||||||
|
for (Method anm : ann.annotationType().getMethods()) {
|
||||||
|
final String mname = anm.getName();
|
||||||
|
if ("equals".equals(mname) || "hashCode".equals(mname) || "toString".equals(mname) || "annotationType".equals(mname)) continue;
|
||||||
|
final Object r = anm.invoke(ann);
|
||||||
|
if (r instanceof String[]) {
|
||||||
|
AnnotationVisitor av1 = av.visitArray(mname);
|
||||||
|
for (String item : (String[]) r) {
|
||||||
|
av1.visit(null, item);
|
||||||
|
}
|
||||||
|
av1.visitEnd();
|
||||||
|
} else if (r instanceof Class[]) {
|
||||||
|
AnnotationVisitor av1 = av.visitArray(mname);
|
||||||
|
for (Class item : (Class[]) r) {
|
||||||
|
av1.visit(null, Type.getType(item));
|
||||||
|
}
|
||||||
|
av1.visitEnd();
|
||||||
|
} else if (r instanceof Enum[]) {
|
||||||
|
AnnotationVisitor av1 = av.visitArray(mname);
|
||||||
|
for (Enum item : (Enum[]) r) {
|
||||||
|
av1.visitEnum(null, Type.getDescriptor(item.getClass()), ((Enum) item).name());
|
||||||
|
}
|
||||||
|
av1.visitEnd();
|
||||||
|
} else if (r instanceof Annotation[]) {
|
||||||
|
AnnotationVisitor av1 = av.visitArray(mname);
|
||||||
|
for (Annotation item : (Annotation[]) r) {
|
||||||
|
visitAnnotation(av1.visitAnnotation(null, Type.getDescriptor(((Annotation) item).annotationType())), item);
|
||||||
|
}
|
||||||
|
av1.visitEnd();
|
||||||
|
} else if (r instanceof Class) {
|
||||||
|
av.visit(mname, Type.getType((Class) r));
|
||||||
|
} else if (r instanceof Enum) {
|
||||||
|
av.visitEnum(mname, Type.getDescriptor(r.getClass()), ((Enum) r).name());
|
||||||
|
} else if (r instanceof Annotation) {
|
||||||
|
visitAnnotation(av.visitAnnotation(null, Type.getDescriptor(((Annotation) r).annotationType())), (Annotation) r);
|
||||||
|
} else {
|
||||||
|
av.visit(mname, r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
av.visitEnd();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* 创建本地模式Service实例
|
* 创建本地模式Service实例
|
||||||
@@ -637,8 +692,12 @@ public abstract class Sncp {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends Service> T createLocalService(final String name, final Consumer<Runnable> executor, final Class<T> serviceClass,
|
public static <T extends Service> T createLocalService(
|
||||||
final InetSocketAddress clientAddress, HashSet<String> groups, Collection<Transport> sameGroupTransports, Collection<Transport> diffGroupTransports) {
|
final String name,
|
||||||
|
final Consumer<Runnable> executor,
|
||||||
|
final Class<T> serviceClass,
|
||||||
|
final InetSocketAddress clientAddress, HashSet<String> groups, Collection<Transport> sameGroupTransports, Collection<Transport> diffGroupTransports
|
||||||
|
) {
|
||||||
try {
|
try {
|
||||||
final Class newClazz = createLocalServiceClass(name, serviceClass);
|
final Class newClazz = createLocalServiceClass(name, serviceClass);
|
||||||
T rs = (T) newClazz.newInstance();
|
T rs = (T) newClazz.newInstance();
|
||||||
@@ -794,8 +853,12 @@ public abstract class Sncp {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public static <T extends Service> T createRemoteService(final String name, final Consumer<Runnable> executor,
|
public static <T extends Service> T createRemoteService(
|
||||||
final Class<T> serviceClass, final InetSocketAddress clientAddress, HashSet<String> groups, final Transport transport) {
|
final String name,
|
||||||
|
final Consumer<Runnable> executor,
|
||||||
|
final Class<T> serviceClass,
|
||||||
|
final InetSocketAddress clientAddress, HashSet<String> groups, final Transport transport
|
||||||
|
) {
|
||||||
if (serviceClass == null) return null;
|
if (serviceClass == null) return null;
|
||||||
if (!Service.class.isAssignableFrom(serviceClass)) return null;
|
if (!Service.class.isAssignableFrom(serviceClass)) return null;
|
||||||
int mod = serviceClass.getModifiers();
|
int mod = serviceClass.getModifiers();
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public final class SncpClient {
|
|||||||
atts[i + 1] = ((SncpCall) ann).value().newInstance();
|
atts[i + 1] = ((SncpCall) ann).value().newInstance();
|
||||||
hasattr = true;
|
hasattr = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.SEVERE, SncpCall.class.getSimpleName() + ".attribute cannot a newInstance for" + method);
|
logger.log(Level.SEVERE, SncpCall.class.getSimpleName() + ".attribute cannot a newInstance for" + method, e);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -388,7 +388,7 @@ public final class SncpDynServlet extends SncpServlet {
|
|||||||
atts[i + 1] = ((SncpCall) ann).value().newInstance();
|
atts[i + 1] = ((SncpCall) ann).value().newInstance();
|
||||||
hasattr = true;
|
hasattr = true;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.log(Level.SEVERE, SncpCall.class.getSimpleName() + ".attribute cannot a newInstance for" + method);
|
logger.log(Level.SEVERE, SncpCall.class.getSimpleName() + ".attribute cannot a newInstance for" + method, e);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,12 @@ public class DebugMethodVisitor {
|
|||||||
this.visitor = visitor;
|
this.visitor = visitor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AnnotationVisitor visitParameterAnnotation(int i, String string, boolean bln) {
|
||||||
|
AnnotationVisitor av = visitor.visitParameterAnnotation(i, string, bln);
|
||||||
|
if (debug) System.out.println("mv.visitParameterAnnotation(" + i + ", \"" + string + "\", " + bln + ");");
|
||||||
|
return av;
|
||||||
|
}
|
||||||
|
|
||||||
public AnnotationVisitor visitAnnotation(String desc, boolean flag) {
|
public AnnotationVisitor visitAnnotation(String desc, boolean flag) {
|
||||||
AnnotationVisitor av = visitor.visitAnnotation(desc, flag);
|
AnnotationVisitor av = visitor.visitAnnotation(desc, flag);
|
||||||
if (debug) System.out.println("mv.visitAnnotation(\"" + desc + "\", " + flag + ");");
|
if (debug) System.out.println("mv.visitAnnotation(\"" + desc + "\", " + flag + ");");
|
||||||
|
|||||||
Reference in New Issue
Block a user