This commit is contained in:
@@ -70,8 +70,8 @@ public final class NodeHttpServer extends NodeServer {
|
||||
final ResourceFactory regFactory = application.getResourceFactory();
|
||||
factory.add(WebSocketNode.class, (ResourceFactory rf, final Object src, final String resourceName, Field field, Object attachment) -> { //主要用于单点的服务
|
||||
try {
|
||||
if (field.getAnnotation(Resource.class) == null) return null;
|
||||
if (!(src instanceof WebSocketServlet)) return null;
|
||||
if (field.getAnnotation(Resource.class) == null) return;
|
||||
if (!(src instanceof WebSocketServlet)) return;
|
||||
synchronized (regFactory) {
|
||||
Service nodeService = (Service) rf.find(resourceName, WebSocketNode.class);
|
||||
if (nodeService == null) {
|
||||
@@ -81,11 +81,9 @@ public final class NodeHttpServer extends NodeServer {
|
||||
logger.fine("[" + Thread.currentThread().getName() + "] Load Service " + nodeService);
|
||||
}
|
||||
field.set(src, nodeService);
|
||||
return nodeService;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "WebSocketNode inject error", e);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -158,8 +158,8 @@ public abstract class NodeServer {
|
||||
final ResourceFactory regFactory = application.getResourceFactory();
|
||||
factory.add(DataSource.class, (ResourceFactory rf, final Object src, String resourceName, Field field, final Object attachment) -> {
|
||||
try {
|
||||
if (field.getAnnotation(Resource.class) == null) return null;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return null; //远程模式不得注入 DataSource
|
||||
if (field.getAnnotation(Resource.class) == null) return;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return; //远程模式不得注入 DataSource
|
||||
DataSource source = new DataDefaultSource(resourceName);
|
||||
application.dataSources.add(source);
|
||||
regFactory.register(resourceName, DataSource.class, source);
|
||||
@@ -196,16 +196,14 @@ public abstract class NodeServer {
|
||||
}
|
||||
field.set(src, source);
|
||||
rf.inject(source, self); // 给 "datasource.nodeid" 赋值;
|
||||
return source;
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "DataSource inject error", e);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
factory.add(CacheSource.class, (ResourceFactory rf, final Object src, final String resourceName, Field field, final Object attachment) -> {
|
||||
try {
|
||||
if (field.getAnnotation(Resource.class) == null) return null;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return null; //远程模式不得注入 CacheSource
|
||||
if (field.getAnnotation(Resource.class) == null) return;
|
||||
if ((src instanceof Service) && Sncp.isRemote((Service) src)) return; //远程模式不得注入 CacheSource
|
||||
|
||||
SncpClient client = null;
|
||||
Transport sameGroupTransport = null;
|
||||
@@ -246,10 +244,8 @@ public abstract class NodeServer {
|
||||
if (finer) logger.finer("[" + Thread.currentThread().getName() + "] Load Service " + wrapper.getService());
|
||||
}
|
||||
logger.finer("[" + Thread.currentThread().getName() + "] Load Source " + source);
|
||||
return source;
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, "DataSource inject error", e);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -263,8 +263,10 @@ public final class ResourceFactory {
|
||||
}
|
||||
if (re == null) {
|
||||
ResourceLoader it = findLoader(field.getGenericType(), field);
|
||||
Object rs = it.load(this, src, rcname, field, attachment);
|
||||
if (rs != null) re = genctype == classtype ? findEntry(rcname, classtype) : findEntry(rcname, genctype);
|
||||
if (it != null) {
|
||||
it.load(this, src, rcname, field, attachment);
|
||||
re = genctype == classtype ? findEntry(rcname, classtype) : findEntry(rcname, genctype);
|
||||
}
|
||||
}
|
||||
if (re == null) continue;
|
||||
Object rs = re.value;
|
||||
@@ -373,7 +375,7 @@ public final class ResourceFactory {
|
||||
|
||||
public static interface ResourceLoader {
|
||||
|
||||
public Object load(ResourceFactory factory, Object src, String resourceName, Field field, Object attachment);
|
||||
public void load(ResourceFactory factory, Object src, String resourceName, Field field, Object attachment);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user