This commit is contained in:
@@ -363,8 +363,8 @@ public final class Application {
|
||||
this.resourceFactory.register((ResourceFactory rf, final Object src, String resourceName, Field field, final Object attachment) -> {
|
||||
try {
|
||||
Resource res = field.getAnnotation(Resource.class);
|
||||
if (res == null || !res.name().isEmpty()) return;
|
||||
if (!(src instanceof WatchService) || Sncp.isRemote((Service) src)) return; //远程模式不得注入
|
||||
if (res == null || !res.name().isEmpty()) return false;
|
||||
if (!(src instanceof WatchService) || Sncp.isRemote((Service) src)) return false; //远程模式不得注入
|
||||
Class type = field.getType();
|
||||
if (type == Application.class) {
|
||||
field.set(src, application);
|
||||
@@ -374,6 +374,7 @@ public final class Application {
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Resource inject error", e);
|
||||
}
|
||||
return false;
|
||||
}, Application.class, WatchFactory.class);
|
||||
//--------------------------------------------------------------------------
|
||||
initResources();
|
||||
|
||||
@@ -92,8 +92,8 @@ public class NodeHttpServer extends NodeServer {
|
||||
final ResourceFactory regFactory = application.getResourceFactory();
|
||||
resourceFactory.register((ResourceFactory rf, final Object src, final String resourceName, Field field, Object attachment) -> { //主要用于单点的服务
|
||||
try {
|
||||
if (field.getAnnotation(Resource.class) == null) return;
|
||||
if (!(src instanceof WebSocketServlet)) return;
|
||||
if (field.getAnnotation(Resource.class) == null) return true;
|
||||
if (!(src instanceof WebSocketServlet)) return true;
|
||||
synchronized (regFactory) {
|
||||
Service nodeService = (Service) rf.find(resourceName, WebSocketNode.class);
|
||||
if (nodeService == null) {
|
||||
@@ -107,6 +107,7 @@ public class NodeHttpServer extends NodeServer {
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "WebSocketNode inject error", e);
|
||||
}
|
||||
return true;
|
||||
}, WebSocketNode.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -212,10 +212,10 @@ public abstract class NodeServer {
|
||||
resourceFactory.register((ResourceFactory rf, final Object src, String resourceName, Field field, final Object attachment) -> {
|
||||
try {
|
||||
Resource res = field.getAnnotation(Resource.class);
|
||||
if (res == null || !res.name().startsWith("properties.")) return;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return; //远程模式不得注入 DataSource
|
||||
if (res == null || !res.name().startsWith("properties.")) return true;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return true; //远程模式不得注入 DataSource
|
||||
Class type = field.getType();
|
||||
if (type != AnyValue.class && type != AnyValue[].class) return;
|
||||
if (type != AnyValue.class && type != AnyValue[].class) return true;
|
||||
Object resource = null;
|
||||
final AnyValue properties = resources == null ? null : resources.getAnyValue("properties");
|
||||
if (properties != null && type == AnyValue.class) {
|
||||
@@ -229,13 +229,14 @@ public abstract class NodeServer {
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "Resource inject error", e);
|
||||
}
|
||||
return true;
|
||||
}, AnyValue.class, AnyValue[].class);
|
||||
|
||||
//------------------------------------- 注册DataSource --------------------------------------------------------
|
||||
resourceFactory.register((ResourceFactory rf, final Object src, String resourceName, Field field, final Object attachment) -> {
|
||||
try {
|
||||
if (field.getAnnotation(Resource.class) == null) return;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return; //远程模式不得注入 DataSource
|
||||
if (field.getAnnotation(Resource.class) == null) return true;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return true; //远程模式不得注入 DataSource
|
||||
DataSource source = DataSources.createDataSource(resourceName);
|
||||
application.dataSources.add(source);
|
||||
appResFactory.register(resourceName, DataSource.class, source);
|
||||
@@ -261,13 +262,14 @@ public abstract class NodeServer {
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "DataSource inject error", e);
|
||||
}
|
||||
return true;
|
||||
}, DataSource.class);
|
||||
|
||||
//------------------------------------- 注册CacheSource --------------------------------------------------------
|
||||
resourceFactory.register((ResourceFactory rf, final Object src, final String resourceName, Field field, final Object attachment) -> {
|
||||
try {
|
||||
if (field.getAnnotation(Resource.class) == null) return;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return; //远程模式不需要注入 CacheSource
|
||||
if (field.getAnnotation(Resource.class) == null) return true;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return true; //远程模式不需要注入 CacheSource
|
||||
final Service srcService = (Service) src;
|
||||
SncpClient client = Sncp.getSncpClient(srcService);
|
||||
Transport sameGroupTransport = Sncp.getSameGroupTransport(srcService);
|
||||
@@ -303,6 +305,7 @@ public abstract class NodeServer {
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "DataSource inject error", e);
|
||||
}
|
||||
return true;
|
||||
}, CacheSource.class);
|
||||
}
|
||||
|
||||
@@ -373,6 +376,7 @@ public abstract class NodeServer {
|
||||
if (entry.isExpect()) {
|
||||
ResourceFactory.ResourceLoader resourceLoader = (ResourceFactory rf, final Object src, final String resourceName, Field field, final Object attachment) -> {
|
||||
runner.accept(rf, true);
|
||||
return true;
|
||||
};
|
||||
ResourceType rty = entry.getType().getAnnotation(ResourceType.class);
|
||||
Class[] resTypes = rty == null ? new Class[]{} : rty.value();
|
||||
|
||||
Reference in New Issue
Block a user