This commit is contained in:
@@ -79,7 +79,7 @@ public final class ServiceWrapper<T extends Service> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return service.name();
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isRemote() {
|
public boolean isRemote() {
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ public abstract class Sncp {
|
|||||||
* public void createSomeThing(TestBean bean){
|
* public void createSomeThing(TestBean bean){
|
||||||
* "xxxxx" + bean;
|
* "xxxxx" + bean;
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @MultiRun
|
* @MultiRun
|
||||||
* public String updateSomeThing(String id){
|
* public String updateSomeThing(String id){
|
||||||
* return "hello" + id;
|
* return "hello" + id;
|
||||||
@@ -126,6 +126,7 @@ public abstract class Sncp {
|
|||||||
* </pre></blockquote>
|
* </pre></blockquote>
|
||||||
*
|
*
|
||||||
* <blockquote><pre>
|
* <blockquote><pre>
|
||||||
|
* @Resource(name = "")
|
||||||
* @SncpDyn(remote = false)
|
* @SncpDyn(remote = false)
|
||||||
* public final class _DynLocalTestService extends TestService{
|
* public final class _DynLocalTestService extends TestService{
|
||||||
*
|
*
|
||||||
@@ -141,11 +142,6 @@ public abstract class Sncp {
|
|||||||
* private String _selfstring;
|
* private String _selfstring;
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public final String name() {
|
|
||||||
* return "";
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* @Override
|
|
||||||
* public String toString() {
|
* public String toString() {
|
||||||
* return _selfstring == null ? super.toString() : _selfstring;
|
* 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 (samerunnable) _client.remote(_convert, _sameGroupTransports, 1, true, false, false, bean);
|
||||||
* if (diffrunnable) _client.remote(_convert, _diffGroupTransports, 1, true, true, false, bean);
|
* if (diffrunnable) _client.remote(_convert, _diffGroupTransports, 1, true, true, false, bean);
|
||||||
* }
|
* }
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public String updateSomeThing(String id){
|
* public String updateSomeThing(String id){
|
||||||
* return _updateSomeThing(true, true, true, id);
|
* return _updateSomeThing(true, true, true, id);
|
||||||
@@ -214,6 +210,11 @@ public abstract class Sncp {
|
|||||||
AnnotationVisitor av0;
|
AnnotationVisitor av0;
|
||||||
|
|
||||||
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("Ljavax/annotation/Resource;", true);
|
||||||
|
av0.visit("name", name);
|
||||||
|
av0.visitEnd();
|
||||||
|
}
|
||||||
{
|
{
|
||||||
av0 = cw.visitAnnotation(sncpDynDesc, true);
|
av0 = cw.visitAnnotation(sncpDynDesc, true);
|
||||||
av0.visit("remote", Boolean.FALSE);
|
av0.visit("remote", Boolean.FALSE);
|
||||||
@@ -252,13 +253,6 @@ public abstract class Sncp {
|
|||||||
mv.visitMaxs(1, 1);
|
mv.visitMaxs(1, 1);
|
||||||
mv.visitEnd();
|
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()
|
{ // toString()
|
||||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null));
|
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null));
|
||||||
mv.visitVarInsn(ALOAD, 0);
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
@@ -775,6 +769,7 @@ public abstract class Sncp {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <blockquote><pre>
|
* <blockquote><pre>
|
||||||
|
* @Resource(name = "")
|
||||||
* @SncpDyn(remote = true)
|
* @SncpDyn(remote = true)
|
||||||
* public final class _DynRemoteTestService extends TestService{
|
* public final class _DynRemoteTestService extends TestService{
|
||||||
*
|
*
|
||||||
@@ -788,11 +783,6 @@ public abstract class Sncp {
|
|||||||
* private String _selfstring;
|
* private String _selfstring;
|
||||||
*
|
*
|
||||||
* @Override
|
* @Override
|
||||||
* public final String name() {
|
|
||||||
* return "";
|
|
||||||
* }
|
|
||||||
*
|
|
||||||
* @Override
|
|
||||||
* public String toString() {
|
* public String toString() {
|
||||||
* return _selfstring == null ? super.toString() : _selfstring;
|
* return _selfstring == null ? super.toString() : _selfstring;
|
||||||
* }
|
* }
|
||||||
@@ -875,6 +865,11 @@ public abstract class Sncp {
|
|||||||
AnnotationVisitor av0;
|
AnnotationVisitor av0;
|
||||||
|
|
||||||
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("Ljavax/annotation/Resource;", true);
|
||||||
|
av0.visit("name", name);
|
||||||
|
av0.visitEnd();
|
||||||
|
}
|
||||||
{
|
{
|
||||||
av0 = cw.visitAnnotation(sncpDynDesc, true);
|
av0 = cw.visitAnnotation(sncpDynDesc, true);
|
||||||
av0.visit("remote", Boolean.TRUE);
|
av0.visit("remote", Boolean.TRUE);
|
||||||
@@ -919,13 +914,6 @@ public abstract class Sncp {
|
|||||||
mv.visitMaxs(0, 2);
|
mv.visitMaxs(0, 2);
|
||||||
mv.visitEnd();
|
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()
|
{ // toString()
|
||||||
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null));
|
mv = new AsmMethodVisitor(cw.visitMethod(ACC_PUBLIC, "toString", "()Ljava/lang/String;", null, null));
|
||||||
mv.visitVarInsn(ALOAD, 0);
|
mv.visitVarInsn(ALOAD, 0);
|
||||||
|
|||||||
@@ -156,6 +156,10 @@ public class CacheSourceService<K extends Serializable, V extends Object> implem
|
|||||||
destroy(null);
|
destroy(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return this.getClass().getAnnotation(Resource.class).name();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy(AnyValue conf) {
|
public void destroy(AnyValue conf) {
|
||||||
if (scheduler != null) scheduler.shutdownNow();
|
if (scheduler != null) scheduler.shutdownNow();
|
||||||
|
|||||||
@@ -19,7 +19,9 @@ import javax.annotation.Resource;
|
|||||||
/**
|
/**
|
||||||
* 暂时不实现
|
* 暂时不实现
|
||||||
*
|
*
|
||||||
* <p> 详情见: http://www.redkale.org
|
* <p>
|
||||||
|
* 详情见: http://www.redkale.org
|
||||||
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@AutoLoad(false)
|
@AutoLoad(false)
|
||||||
@@ -64,6 +66,10 @@ public class DataSQLListenerService implements DataSQLListener, Service {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String name() {
|
||||||
|
return this.getClass().getAnnotation(Resource.class).name();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void destroy(AnyValue config) {
|
public void destroy(AnyValue config) {
|
||||||
if (syncfile != null) syncfile.close();
|
if (syncfile != null) syncfile.close();
|
||||||
|
|||||||
@@ -41,12 +41,4 @@ public interface Service {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Service的name, 一个Service在同一进程内可以包含多个实例, 使用name区分
|
|
||||||
*
|
|
||||||
* @return 资源名
|
|
||||||
*/
|
|
||||||
default String name() {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,9 @@ import javax.annotation.*;
|
|||||||
/**
|
/**
|
||||||
* 如果Resource(name = "$") 表示资源name采用所属对象的name
|
* 如果Resource(name = "$") 表示资源name采用所属对象的name
|
||||||
*
|
*
|
||||||
* <p> 详情见: http://www.redkale.org
|
* <p>
|
||||||
|
* 详情见: http://www.redkale.org
|
||||||
|
*
|
||||||
* @author zhangjx
|
* @author zhangjx
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@@ -185,10 +187,15 @@ public final class ResourceFactory {
|
|||||||
String tname = rc.name();
|
String tname = rc.name();
|
||||||
if (tname.contains(RESOURCE_PARENT_NAME)) {
|
if (tname.contains(RESOURCE_PARENT_NAME)) {
|
||||||
try {
|
try {
|
||||||
String srcname = (String) src.getClass().getMethod("name").invoke(src);
|
Resource res = src.getClass().getAnnotation(Resource.class);
|
||||||
tname = tname.replace(RESOURCE_PARENT_NAME, srcname);
|
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()方法的值, 异常则忽略
|
} 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;
|
final String rcname = tname;
|
||||||
|
|||||||
Reference in New Issue
Block a user