This commit is contained in:
RedKale
2016-04-13 16:12:03 +08:00
parent a5b1b0e036
commit 7fe0fe0d47

View File

@@ -5,27 +5,27 @@
*/ */
package org.redkale.net.sncp; package org.redkale.net.sncp;
import org.redkale.net.sncp.SncpClient.SncpAction; import java.lang.annotation.Annotation;
import java.lang.annotation.*;
import java.lang.reflect.*; import java.lang.reflect.*;
import java.net.*; import java.net.InetSocketAddress;
import java.security.*; import java.security.*;
import java.util.*; import java.util.*;
import java.util.function.*; import java.util.function.Consumer;
import jdk.internal.org.objectweb.asm.*; import javax.annotation.Resource;
import static jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES; import static jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
import jdk.internal.org.objectweb.asm.*;
import static jdk.internal.org.objectweb.asm.Opcodes.*; import static jdk.internal.org.objectweb.asm.Opcodes.*;
import jdk.internal.org.objectweb.asm.Type; import jdk.internal.org.objectweb.asm.Type;
import org.redkale.convert.bson.*; import org.redkale.convert.bson.BsonConvert;
import org.redkale.net.*; import org.redkale.net.Transport;
import org.redkale.net.sncp.SncpClient.SncpAction;
import org.redkale.service.*; import org.redkale.service.*;
import org.redkale.util.*; import org.redkale.util.*;
import org.redkale.service.DynRemote;
/** /**
* Service Node Communicate Protocol * Service Node Communicate Protocol
* 生成Service的本地模式或远程模式Service-Class的工具类 * 生成Service的本地模式或远程模式Service-Class的工具类
* * <p>
* <p> * <p>
* 详情见: http://redkale.org * 详情见: http://redkale.org
* *
@@ -96,50 +96,50 @@ public abstract class Sncp {
/** /**
* <blockquote><pre> * <blockquote><pre>
* public class TestService implements Service{ * public class TestService implements Service{
* * <p>
* public String findSomeThing(){ * public String findSomeThing(){
* return "hello"; * return "hello";
* } * }
* * <p>
* &#64;MultiRun(selfrun = false) * &#64;MultiRun(selfrun = false)
* public void createSomeThing(TestBean bean){ * public void createSomeThing(TestBean bean){
* //do something * //do something
* } * }
* * <p>
* &#64;MultiRun * &#64;MultiRun
* public String updateSomeThing(String id){ * public String updateSomeThing(String id){
* return "hello" + id; * return "hello" + id;
* } * }
* } * }
* </pre></blockquote> * </pre></blockquote>
* * <p>
* <blockquote><pre> * <blockquote><pre>
* &#64;Resource(name = "") * &#64;Resource(name = "")
* &#64;SncpDyn(remote = false) * &#64;SncpDyn(remote = false)
* &#64;ResourceType({TestService.class}) * &#64;ResourceType({TestService.class})
* public final class _DynLocalTestService extends TestService{ * public final class _DynLocalTestService extends TestService{
* * <p>
* &#64;Resource * &#64;Resource
* private BsonConvert _convert; * private BsonConvert _convert;
* * <p>
* private Transport _sameGroupTransport; * private Transport _sameGroupTransport;
* * <p>
* private Transport[] _diffGroupTransports; * private Transport[] _diffGroupTransports;
* * <p>
* private SncpClient _client; * private SncpClient _client;
* * <p>
* private String _selfstring; * private String _selfstring;
* * <p>
* &#64;Override * &#64;Override
* public String toString() { * public String toString() {
* return _selfstring == null ? super.toString() : _selfstring; * return _selfstring == null ? super.toString() : _selfstring;
* } * }
* * <p>
* &#64;Override * &#64;Override
* public void createSomeThing(TestBean bean){ * public void createSomeThing(TestBean bean){
* this._createSomeThing(false, true, true, bean); * this._createSomeThing(false, true, true, bean);
* } * }
* * <p>
* &#64;SncpDyn(remote = false, index = 0) * &#64;SncpDyn(remote = false, index = 0)
* public void _createSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, TestBean bean){ * public void _createSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, TestBean bean){
* if(selfrunnable) super.createSomeThing(bean); * if(selfrunnable) super.createSomeThing(bean);
@@ -147,12 +147,12 @@ public abstract class Sncp {
* if (samerunnable) _client.remoteSameGroup(_convert, _sameGroupTransport, 0, true, false, false, bean); * if (samerunnable) _client.remoteSameGroup(_convert, _sameGroupTransport, 0, true, false, false, bean);
* if (diffrunnable) _client.remoteDiffGroup(_convert, _diffGroupTransports, 0, true, true, false, bean); * if (diffrunnable) _client.remoteDiffGroup(_convert, _diffGroupTransports, 0, true, true, false, bean);
* } * }
* * <p>
* &#64;Override * &#64;Override
* public String updateSomeThing(String id){ * public String updateSomeThing(String id){
* return this._updateSomeThing(true, true, true, id); * return this._updateSomeThing(true, true, true, id);
* } * }
* * <p>
* &#64;SncpDyn(remote = false, index = 1) * &#64;SncpDyn(remote = false, index = 1)
* public String _updateSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, String id){ * public String _updateSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, String id){
* String rs = super.updateSomeThing(id); * String rs = super.updateSomeThing(id);
@@ -163,7 +163,7 @@ public abstract class Sncp {
* } * }
* } * }
* </pre></blockquote> * </pre></blockquote>
* * <p>
* 创建Service的本地模式Class * 创建Service的本地模式Class
* *
* @param <T> Service子类 * @param <T> Service子类
@@ -216,6 +216,12 @@ public abstract class Sncp {
av0.visit("remote", Boolean.FALSE); av0.visit("remote", Boolean.FALSE);
av0.visitEnd(); av0.visitEnd();
} }
{ //给新类加上 原有的Annotation
for (Annotation ann : serviceClass.getAnnotations()) {
if (ann instanceof Resource || ann instanceof SncpDyn || ann instanceof ResourceType) continue;
visitAnnotation(cw.visitAnnotation(Type.getDescriptor(ann.annotationType()), true), ann);
}
}
{ {
av0 = cw.visitAnnotation(Type.getDescriptor(ResourceType.class), true); av0 = cw.visitAnnotation(Type.getDescriptor(ResourceType.class), true);
{ {
@@ -782,48 +788,48 @@ public abstract class Sncp {
* &#64;SncpDyn(remote = true) * &#64;SncpDyn(remote = true)
* &#64;ResourceType({TestService.class}) * &#64;ResourceType({TestService.class})
* public final class _DynRemoteTestService extends TestService{ * public final class _DynRemoteTestService extends TestService{
* * <p>
* &#64;Resource * &#64;Resource
* private BsonConvert _convert; * private BsonConvert _convert;
* * <p>
* private Transport _transport; * private Transport _transport;
* * <p>
* private SncpClient _client; * private SncpClient _client;
* * <p>
* private String _selfstring; * private String _selfstring;
* * <p>
* &#64;Override * &#64;Override
* public String toString() { * public String toString() {
* return _selfstring == null ? super.toString() : _selfstring; * return _selfstring == null ? super.toString() : _selfstring;
* } * }
* * <p>
* &#64;SncpDyn(remote = false, index = 0) * &#64;SncpDyn(remote = false, index = 0)
* public void _createSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, TestBean bean){ * public void _createSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, TestBean bean){
* _client.remote(_convert, _transport, 0, selfrunnable, samerunnable, diffrunnable, bean); * _client.remote(_convert, _transport, 0, selfrunnable, samerunnable, diffrunnable, bean);
* } * }
* * <p>
* &#64;SncpDyn(remote = false, index = 1) * &#64;SncpDyn(remote = false, index = 1)
* public String _updateSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, String id){ * public String _updateSomeThing(boolean selfrunnable, boolean samerunnable, boolean diffrunnable, String id){
* return _client.remote(_convert, _transport, 1, selfrunnable, samerunnable, diffrunnable, id); * return _client.remote(_convert, _transport, 1, selfrunnable, samerunnable, diffrunnable, id);
* } * }
* * <p>
* &#64;Override * &#64;Override
* public void createSomeThing(TestBean bean){ * public void createSomeThing(TestBean bean){
* _client.remote(_convert, _transport, 2, bean); * _client.remote(_convert, _transport, 2, bean);
* } * }
* * <p>
* &#64;Override * &#64;Override
* public String findSomeThing(){ * public String findSomeThing(){
* return _client.remote(_convert, _transport, 3); * return _client.remote(_convert, _transport, 3);
* } * }
* * <p>
* &#64;Override * &#64;Override
* public String updateSomeThing(String id){ * public String updateSomeThing(String id){
* return _client.remote(_convert, _transport, 4, id); * return _client.remote(_convert, _transport, 4, id);
* } * }
* } * }
* </pre></blockquote> * </pre></blockquote>
* * <p>
* 创建远程模式的Service实例 * 创建远程模式的Service实例
* *
* @param <T> Service泛型 * @param <T> Service泛型
@@ -910,6 +916,12 @@ public abstract class Sncp {
av0.visit("remote", Boolean.TRUE); av0.visit("remote", Boolean.TRUE);
av0.visitEnd(); av0.visitEnd();
} }
{ //给新类加上 原有的Annotation
for (Annotation ann : serviceClass.getAnnotations()) {
if (ann instanceof Resource || ann instanceof SncpDyn || ann instanceof ResourceType) continue;
visitAnnotation(cw.visitAnnotation(Type.getDescriptor(ann.annotationType()), true), ann);
}
}
{ {
fv = cw.visitField(ACC_PRIVATE, "_convert", convertDesc, null, null); fv = cw.visitField(ACC_PRIVATE, "_convert", convertDesc, null, null);
av0 = fv.visitAnnotation("Ljavax/annotation/Resource;", true); av0 = fv.visitAnnotation("Ljavax/annotation/Resource;", true);