This commit is contained in:
wentch
2016-01-05 17:41:54 +08:00
parent 9b32908906
commit 1568f492ff
6 changed files with 37 additions and 40 deletions

View File

@@ -79,7 +79,7 @@ public final class ServiceWrapper<T extends Service> {
}
public String getName() {
return service.name();
return name;
}
public boolean isRemote() {

View File

@@ -117,7 +117,7 @@ public abstract class Sncp {
* public void createSomeThing(TestBean bean){
* "xxxxx" + bean;
* }
*
*
* &#64;MultiRun
* public String updateSomeThing(String id){
* return "hello" + id;
@@ -126,6 +126,7 @@ public abstract class Sncp {
* </pre></blockquote>
*
* <blockquote><pre>
* &#64;Resource(name = "")
* &#64;SncpDyn(remote = false)
* public final class _DynLocalTestService extends TestService{
*
@@ -141,11 +142,6 @@ public abstract class Sncp {
* private String _selfstring;
*
* &#64;Override
* public final String name() {
* return "";
* }
*
* &#64;Override
* public String toString() {
* return _selfstring == null ? super.toString() : _selfstring;
* }
@@ -162,7 +158,7 @@ public abstract class Sncp {
* if (samerunnable) _client.remote(_convert, _sameGroupTransports, 1, true, false, false, bean);
* if (diffrunnable) _client.remote(_convert, _diffGroupTransports, 1, true, true, false, bean);
* }
*
*
* &#64;Override
* public String updateSomeThing(String id){
* return _updateSomeThing(true, true, true, id);
@@ -214,6 +210,11 @@ public abstract class Sncp {
AnnotationVisitor av0;
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null);
{
av0 = cw.visitAnnotation("Ljavax/annotation/Resource;", true);
av0.visit("name", name);
av0.visitEnd();
}
{
av0 = cw.visitAnnotation(sncpDynDesc, true);
av0.visit("remote", Boolean.FALSE);
@@ -252,13 +253,6 @@ public abstract class Sncp {
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{ // name()
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "name", "()Ljava/lang/String;", null, null));
mv.visitLdcInsn(name);
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{ // toString()
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null));
mv.visitVarInsn(ALOAD, 0);
@@ -775,6 +769,7 @@ public abstract class Sncp {
/**
* <blockquote><pre>
* &#64;Resource(name = "")
* &#64;SncpDyn(remote = true)
* public final class _DynRemoteTestService extends TestService{
*
@@ -788,11 +783,6 @@ public abstract class Sncp {
* private String _selfstring;
*
* &#64;Override
* public final String name() {
* return "";
* }
*
* &#64;Override
* public String toString() {
* return _selfstring == null ? super.toString() : _selfstring;
* }
@@ -875,6 +865,11 @@ public abstract class Sncp {
AnnotationVisitor av0;
cw.visit(V1_8, ACC_PUBLIC + ACC_FINAL + ACC_SUPER, newDynName, null, supDynName, null);
{
av0 = cw.visitAnnotation("Ljavax/annotation/Resource;", true);
av0.visit("name", name);
av0.visitEnd();
}
{
av0 = cw.visitAnnotation(sncpDynDesc, true);
av0.visit("remote", Boolean.TRUE);
@@ -919,13 +914,6 @@ public abstract class Sncp {
mv.visitMaxs(0, 2);
mv.visitEnd();
}
{ // name()
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC + ACC_FINAL, "name", "()Ljava/lang/String;", null, null));
mv.visitLdcInsn(name);
mv.visitInsn(ARETURN);
mv.visitMaxs(1, 1);
mv.visitEnd();
}
{ // toString()
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null));
mv.visitVarInsn(ALOAD, 0);

View File

@@ -156,6 +156,10 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
destroy(null);
}
public String name() {
return this.getClass().getAnnotation(Resource.class).name();
}
@Override
public void destroy(AnyValue conf) {
if (scheduler != null) scheduler.shutdownNow();

View File

@@ -19,7 +19,9 @@ import javax.annotation.Resource;
/**
* 暂时不实现
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
@AutoLoad(false)
@@ -64,6 +66,10 @@ public class DataSQLListenerService implements DataSQLListener, Service {
}
public String name() {
return this.getClass().getAnnotation(Resource.class).name();
}
@Override
public void destroy(AnyValue config) {
if (syncfile != null) syncfile.close();

View File

@@ -41,12 +41,4 @@ public interface Service {
}
/**
* Service的name 一个Service在同一进程内可以包含多个实例 使用name区分
*
* @return 资源名
*/
default String name() {
return "";
}
}

View File

@@ -15,7 +15,9 @@ import javax.annotation.*;
/**
* 如果Resource(name = "$") 表示资源name采用所属对象的name
*
* <p> 详情见: http://www.redkale.org
* <p>
* 详情见: http://www.redkale.org
*
* @author zhangjx
*/
@SuppressWarnings("unchecked")
@@ -185,10 +187,15 @@ public final class ResourceFactory {
String tname = rc.name();
if (tname.contains(RESOURCE_PARENT_NAME)) {
try {
String srcname = (String) src.getClass().getMethod("name").invoke(src);
tname = tname.replace(RESOURCE_PARENT_NAME, srcname);
Resource res = src.getClass().getAnnotation(Resource.class);
if (res == null) {
String srcname = (String) src.getClass().getMethod("name").invoke(src);
tname = tname.replace(RESOURCE_PARENT_NAME, srcname);
} else {
tname = res.name();
}
} catch (Exception e) { // 获取src中的name()方法的值, 异常则忽略
logger.log(Level.SEVERE, src.getClass().getName() + " not found [public String name()] method", e);
logger.log(Level.SEVERE, src.getClass().getName() + " not found @Resource on Class or [public String name()] method", e);
}
}
final String rcname = tname;