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