This commit is contained in:
@@ -361,12 +361,11 @@ public abstract class NodeServer {
|
||||
}
|
||||
if (SncpClient.parseMethod(serviceImplClass).isEmpty()) return; //class没有可用的方法, 通常为BaseService
|
||||
//final ServiceWrapper wrapper = new ServiceWrapper(serviceImplClass, service, resourceName, localed ? NodeServer.this.sncpGroup : null, groups, entry.getProperty());
|
||||
for (final Class restype : Sncp.getResourceTypes(service)) {
|
||||
if (rf.find(resourceName, restype) == null) {
|
||||
regFactory.register(resourceName, restype, service);
|
||||
} else if (isSNCP() && !entry.isAutoload()) {
|
||||
throw new RuntimeException(restype.getSimpleName() + "(class:" + serviceImplClass.getName() + ", name:" + resourceName + ", group:" + groups + ") is repeat.");
|
||||
}
|
||||
final Class restype = Sncp.getResourceType(service);
|
||||
if (rf.find(resourceName, restype) == null) {
|
||||
regFactory.register(resourceName, restype, service);
|
||||
} else if (isSNCP() && !entry.isAutoload()) {
|
||||
throw new RuntimeException(restype.getSimpleName() + "(class:" + serviceImplClass.getName() + ", name:" + resourceName + ", group:" + groups + ") is repeat.");
|
||||
}
|
||||
if (Sncp.isRemote(service)) {
|
||||
remoteServices.add(service);
|
||||
@@ -384,10 +383,7 @@ public abstract class NodeServer {
|
||||
};
|
||||
if (entry.isExpect()) {
|
||||
ResourceType rty = entry.getType().getAnnotation(ResourceType.class);
|
||||
Class[] resTypes = rty == null ? new Class[]{} : rty.value();
|
||||
for (final Class restype : resTypes) {
|
||||
resourceFactory.register(resourceLoader, restype);
|
||||
}
|
||||
resourceFactory.register(resourceLoader, rty == null ? entry.getType() : rty.value());
|
||||
} else {
|
||||
resourceLoader.load(resourceFactory, null, entry.getName(), null, false);
|
||||
}
|
||||
@@ -416,7 +412,7 @@ public abstract class NodeServer {
|
||||
//----------------- init -----------------
|
||||
List<Service> swlist = new ArrayList<>(localServices);
|
||||
Collections.sort(swlist, (o1, o2) -> {
|
||||
int rs = Sncp.getResourceTypes(o1)[0].getName().compareTo(Sncp.getResourceTypes(o2)[0].getName());
|
||||
int rs = Sncp.getResourceType(o1).getName().compareTo(Sncp.getResourceType(o2).getName());
|
||||
if (rs == 0) rs = Sncp.getResourceName(o1).compareTo(Sncp.getResourceName(o2));
|
||||
return rs;
|
||||
});
|
||||
@@ -448,16 +444,7 @@ public abstract class NodeServer {
|
||||
|
||||
private void calcMaxLength(Service y) { //计算toString中的长度
|
||||
maxNameLength = Math.max(maxNameLength, Sncp.getResourceName(y).length());
|
||||
StringBuilder s = new StringBuilder();
|
||||
Class[] types = Sncp.getResourceTypes(y);
|
||||
if (types.length == 1) {
|
||||
s.append(types[0].getName());
|
||||
} else {
|
||||
s.append('[');
|
||||
s.append(Arrays.asList(types).stream().map((Class t) -> t.getName()).collect(Collectors.joining(",")));
|
||||
s.append(']');
|
||||
}
|
||||
maxClassNameLength = Math.max(maxClassNameLength, s.length() + 1);
|
||||
maxClassNameLength = Math.max(maxClassNameLength, Sncp.getResourceType(y).getName().length() + 1);
|
||||
}
|
||||
|
||||
protected List<Transport> loadTransports(final HashSet<String> groups) {
|
||||
|
||||
@@ -11,7 +11,6 @@ import java.net.InetSocketAddress;
|
||||
import java.security.*;
|
||||
import java.util.*;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.Collectors;
|
||||
import javax.annotation.Resource;
|
||||
import static jdk.internal.org.objectweb.asm.ClassWriter.COMPUTE_FRAMES;
|
||||
import jdk.internal.org.objectweb.asm.*;
|
||||
@@ -110,10 +109,10 @@ public abstract class Sncp {
|
||||
}
|
||||
}
|
||||
|
||||
public static Class[] getResourceTypes(Service service) {
|
||||
public static Class getResourceType(Service service) {
|
||||
if (service == null) return null;
|
||||
ResourceType types = service.getClass().getAnnotation(ResourceType.class);
|
||||
return types == null ? new Class[]{getServiceType(service)} : types.value();
|
||||
ResourceType type = service.getClass().getAnnotation(ResourceType.class);
|
||||
return type == null ? getServiceType(service) : type.value();
|
||||
}
|
||||
|
||||
public static String getSncpGroup(Service service) {
|
||||
@@ -224,20 +223,10 @@ public abstract class Sncp {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(isRemote(service) ? "RemoteService" : "LocalService ");
|
||||
int len;
|
||||
Class[] types = getResourceTypes(service);
|
||||
Class type = getResourceType(service);
|
||||
String name = getResourceName(service);
|
||||
if (types.length == 1) {
|
||||
sb.append("(type= ").append(types[0].getName());
|
||||
len = maxClassNameLength - types[0].getName().length();
|
||||
} else {
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append('[');
|
||||
s.append(Arrays.asList(types).stream().map((Class t) -> t.getName()).collect(Collectors.joining(",")));
|
||||
s.append(']');
|
||||
sb.append("(types=").append(s);
|
||||
len = maxClassNameLength - s.length();
|
||||
}
|
||||
|
||||
sb.append("(type= ").append(type.getName());
|
||||
len = maxClassNameLength - type.getName().length();
|
||||
for (int i = 0; i < len; i++) {
|
||||
sb.append(' ');
|
||||
}
|
||||
@@ -272,7 +261,7 @@ public abstract class Sncp {
|
||||
* <blockquote><pre>
|
||||
* @Resource(name = "")
|
||||
* @SncpDyn(remote = false)
|
||||
* @ResourceType({TestService.class})
|
||||
* @ResourceType(TestService.class)
|
||||
* public final class _DynLocalTestService extends TestService{
|
||||
*
|
||||
* private static final Class _redkale_service_type = TestService.class;
|
||||
@@ -396,18 +385,8 @@ public abstract class Sncp {
|
||||
}
|
||||
{
|
||||
av0 = cw.visitAnnotation(Type.getDescriptor(ResourceType.class), true);
|
||||
{
|
||||
AnnotationVisitor av1 = av0.visitArray("value");
|
||||
ResourceType rty = serviceImplClass.getAnnotation(ResourceType.class);
|
||||
if (rty == null) {
|
||||
av1.visit(null, Type.getType(Type.getDescriptor(serviceImplClass)));
|
||||
} else {
|
||||
for (Class cl : rty.value()) {
|
||||
av1.visit(null, Type.getType(Type.getDescriptor(cl)));
|
||||
}
|
||||
}
|
||||
av1.visitEnd();
|
||||
}
|
||||
ResourceType rty = serviceImplClass.getAnnotation(ResourceType.class);
|
||||
av0.visit("value", Type.getType(Type.getDescriptor(rty == null ? serviceImplClass : rty.value())));
|
||||
av0.visitEnd();
|
||||
}
|
||||
{
|
||||
@@ -898,7 +877,7 @@ public abstract class Sncp {
|
||||
* @param executor 线程池
|
||||
* @param resourceFactory 资源容器
|
||||
* @param serviceImplClass Service类
|
||||
* @param clientSncpAddress 本地IP地址
|
||||
* @param clientSncpAddress 本地IP地址
|
||||
* @param sncpGroup 自身的组节点名 可能为null
|
||||
* @param groups 所有的组节点,包含自身
|
||||
* @param conf 启动配置项
|
||||
@@ -1043,7 +1022,7 @@ public abstract class Sncp {
|
||||
* <blockquote><pre>
|
||||
* @Resource(name = "")
|
||||
* @SncpDyn(remote = true)
|
||||
* @ResourceType({TestService.class})
|
||||
* @ResourceType(TestService.class)
|
||||
* public final class _DynRemoteTestService extends TestService{
|
||||
*
|
||||
* private static final Class _redkale_service_type = TestService.class;
|
||||
@@ -1178,18 +1157,8 @@ public abstract class Sncp {
|
||||
}
|
||||
{
|
||||
av0 = cw.visitAnnotation(Type.getDescriptor(ResourceType.class), true);
|
||||
{
|
||||
AnnotationVisitor av1 = av0.visitArray("value");
|
||||
ResourceType rty = serviceTypeOrImplClass.getAnnotation(ResourceType.class);
|
||||
if (rty == null) {
|
||||
av1.visit(null, Type.getType(Type.getDescriptor(serviceTypeOrImplClass)));
|
||||
} else {
|
||||
for (Class cl : rty.value()) {
|
||||
av1.visit(null, Type.getType(Type.getDescriptor(cl)));
|
||||
}
|
||||
}
|
||||
av1.visitEnd();
|
||||
}
|
||||
ResourceType rty = serviceTypeOrImplClass.getAnnotation(ResourceType.class);
|
||||
av0.visit("value", Type.getType(Type.getDescriptor(rty == null ? serviceTypeOrImplClass : rty.value())));
|
||||
av0.visitEnd();
|
||||
}
|
||||
{
|
||||
|
||||
@@ -172,7 +172,7 @@ public final class SncpClient {
|
||||
this.name = serviceName;
|
||||
Class tn = serviceTypeOrImplClass;
|
||||
ResourceType rt = (ResourceType) tn.getAnnotation(ResourceType.class);
|
||||
if (rt != null && rt.value().length > 0) tn = rt.value()[0];
|
||||
if (rt != null) tn = rt.value();
|
||||
this.serviceid = Sncp.hash(tn.getName() + ':' + serviceName);
|
||||
final List<SncpAction> methodens = new ArrayList<>();
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
@@ -94,19 +94,13 @@ public class SncpServer extends Server<DLong, SncpContext, SncpRequest, SncpResp
|
||||
* @return SncpServlet
|
||||
*/
|
||||
public SncpServlet removeSncpServlet(Service sncpService) {
|
||||
SncpServlet servlet = null;
|
||||
String resname = Sncp.getResourceName(sncpService);
|
||||
for (Class type : Sncp.getResourceTypes(sncpService)) {
|
||||
servlet = ((SncpPrepareServlet) this.prepare).removeSncpServlet(resname, type);
|
||||
}
|
||||
return servlet;
|
||||
return ((SncpPrepareServlet) this.prepare).removeSncpServlet(resname, Sncp.getResourceType(sncpService));
|
||||
}
|
||||
|
||||
public void addSncpServlet(Service sncpService) {
|
||||
for (Class type : Sncp.getResourceTypes(sncpService)) {
|
||||
SncpDynServlet sds = new SncpDynServlet(BsonFactory.root().getConvert(), Sncp.getResourceName(sncpService), type, sncpService);
|
||||
this.prepare.addServlet(sds, null, Sncp.getConf(sncpService));
|
||||
}
|
||||
SncpDynServlet sds = new SncpDynServlet(BsonFactory.root().getConvert(), Sncp.getResourceName(sncpService), Sncp.getResourceType(sncpService), sncpService);
|
||||
this.prepare.addServlet(sds, null, Sncp.getConf(sncpService));
|
||||
}
|
||||
|
||||
public <T extends Service> void addSncpServlet(Class<T> serviceTypeClass, String name, T service, AnyValue conf) {
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.redkale.util.*;
|
||||
* @author zhangjx
|
||||
*/
|
||||
@AutoLoad(false)
|
||||
@ResourceType({DataCacheListenerService.class, DataCacheListener.class})
|
||||
@ResourceType(DataCacheListener.class)
|
||||
public class DataCacheListenerService implements DataCacheListener, Service {
|
||||
|
||||
@Resource(name = "$")
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.redkale.util.*;
|
||||
* @author zhangjx
|
||||
*/
|
||||
@AutoLoad(false)
|
||||
@ResourceType({WebSocketNode.class, WebSocketNodeService.class})
|
||||
@ResourceType(WebSocketNode.class)
|
||||
public class WebSocketNodeService extends WebSocketNode implements Service {
|
||||
|
||||
@Override
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.redkale.util.*;
|
||||
*/
|
||||
@Local
|
||||
@AutoLoad(false)
|
||||
@ResourceType({CacheSource.class})
|
||||
@ResourceType(CacheSource.class)
|
||||
public class CacheMemorySource<K extends Serializable, V extends Object> extends AbstractService implements CacheSource<K, V>, Service, AutoCloseable, Resourcable {
|
||||
|
||||
@Resource(name = "APP_HOME")
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.redkale.util.*;
|
||||
@Local
|
||||
@AutoLoad(false)
|
||||
@SuppressWarnings("unchecked")
|
||||
@ResourceType({DataSource.class})
|
||||
@ResourceType(DataSource.class)
|
||||
public class DataJdbcSource extends AbstractService implements DataSource, Service, DataCacheListener, Function<Class, EntityInfo>, AutoCloseable, Resourcable {
|
||||
|
||||
private static final Flipper FLIPPER_ONE = new Flipper(1);
|
||||
|
||||
@@ -176,10 +176,8 @@ public final class ResourceFactory {
|
||||
return (A) register(autoSync, name, claz, rs);
|
||||
} else {
|
||||
A old = null;
|
||||
for (Class cl : rtype.value()) {
|
||||
A t = (A) register(autoSync, name, cl, rs);
|
||||
if (t != null) old = t;
|
||||
}
|
||||
A t = (A) register(autoSync, name, rtype.value(), rs);
|
||||
if (t != null) old = t;
|
||||
return old;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,5 +25,5 @@ import java.lang.annotation.*;
|
||||
@Retention(RUNTIME)
|
||||
public @interface ResourceType {
|
||||
|
||||
Class[] value();
|
||||
Class value();
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.redkale.util.*;
|
||||
*
|
||||
* @author zhangjx
|
||||
*/
|
||||
@ResourceType({SncpTestIService.class})
|
||||
@ResourceType(SncpTestIService.class)
|
||||
public class SncpTestServiceImpl implements SncpTestIService {
|
||||
|
||||
@Override
|
||||
@@ -107,7 +107,7 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
||||
System.out.println(method);
|
||||
}
|
||||
System.out.println("-----------------------------------");
|
||||
service = Sncp.createSimpleRemoteService("", SncpTestServiceImpl.class, new InetSocketAddress("127.0.0.1", 7070), null);
|
||||
service = Sncp.createSimpleRemoteService("", SncpTestServiceImpl.class, new InetSocketAddress("127.0.0.1", 7070), null);
|
||||
for (Method method : service.getClass().getDeclaredMethods()) {
|
||||
System.out.println(method);
|
||||
}
|
||||
@@ -116,7 +116,7 @@ public class SncpTestServiceImpl implements SncpTestIService {
|
||||
System.out.println(method);
|
||||
}
|
||||
System.out.println("-----------------------------------");
|
||||
service = Sncp.createSimpleRemoteService("", SncpTestIService.class, new InetSocketAddress("127.0.0.1", 7070), null);
|
||||
service = Sncp.createSimpleRemoteService("", SncpTestIService.class, new InetSocketAddress("127.0.0.1", 7070), null);
|
||||
for (Method method : service.getClass().getDeclaredMethods()) {
|
||||
System.out.println(method);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user