This commit is contained in:
redkale
2023-12-26 11:04:23 +08:00
parent cac8da9b4d
commit fd3e33d836
5 changed files with 8 additions and 62 deletions

View File

@@ -20,7 +20,6 @@ import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Consumer;
import java.util.logging.*;
import org.redkale.annotation.Nonnull;
import org.redkale.annotation.Resource;
import org.redkale.asm.AsmMethodBoost;
import org.redkale.boot.ClassFilter.FilterEntry;
import org.redkale.cache.spi.CacheModuleEngine;
@@ -378,29 +377,13 @@ public final class Application {
@Override
public Object load(ResourceFactory rf, String srcResourceName, final Object srcObj, String resourceName, Field field, final Object attachment) {
try {
String resName = null;
Resource res = field.getAnnotation(Resource.class);
if (res != null) {
resName = res.name();
} else {
javax.annotation.Resource res2 = field.getAnnotation(javax.annotation.Resource.class);
if (res2 != null) {
resName = res2.name();
}
}
if (resName == null) {
return null;
}
if (srcObj instanceof Service && Sncp.isRemote((Service) srcObj)) {
return null; //远程模式不得注入
}
Class type = field.getType();
if (type == Application.class) {
field.set(srcObj, application);
return application;
} else if (type == ResourceFactory.class) {
boolean serv = RESNAME_SERVER_RESFACTORY.equals(resName) || resName.equalsIgnoreCase("server");
ResourceFactory rs = serv ? rf : (resName.isEmpty() ? application.resourceFactory : null);
boolean serv = RESNAME_SERVER_RESFACTORY.equals(resourceName) || resourceName.equalsIgnoreCase("server");
ResourceFactory rs = serv ? rf : (resourceName.isEmpty() ? application.resourceFactory : null);
field.set(srcObj, rs);
return rs;
} else if (type == NodeSncpServer.class) {
@@ -409,7 +392,7 @@ public final class Application {
if (ns.getClass() != NodeSncpServer.class) {
continue;
}
if (resName.equals(ns.server.getName())) {
if (resourceName.equals(ns.server.getName())) {
server = ns;
break;
}
@@ -422,7 +405,7 @@ public final class Application {
if (ns.getClass() != NodeHttpServer.class) {
continue;
}
if (resName.equals(ns.server.getName())) {
if (resourceName.equals(ns.server.getName())) {
server = ns;
break;
}
@@ -435,7 +418,7 @@ public final class Application {
if (ns.getClass() != NodeWatchServer.class) {
continue;
}
if (resName.equals(ns.server.getName())) {
if (resourceName.equals(ns.server.getName())) {
server = ns;
break;
}
@@ -463,9 +446,6 @@ public final class Application {
//------------------------------------ 注册 java.net.http.HttpClient ------------------------------------
resourceFactory.register((ResourceFactory rf, String srcResourceName, final Object srcObj, String resourceName, Field field, final Object attachment) -> {
try {
if (field.getAnnotation(Resource.class) == null && field.getAnnotation(javax.annotation.Resource.class) == null) {
return null;
}
java.net.http.HttpClient.Builder builder = java.net.http.HttpClient.newBuilder();
if (resourceName.endsWith(".1.1")) {
builder.version(HttpClient.Version.HTTP_1_1);
@@ -485,9 +465,6 @@ public final class Application {
//------------------------------------ 注册 HttpSimpleClient ------------------------------------
resourceFactory.register((ResourceFactory rf, String srcResourceName, final Object srcObj, String resourceName, Field field, final Object attachment) -> {
try {
if (field.getAnnotation(Resource.class) == null && field.getAnnotation(javax.annotation.Resource.class) == null) {
return null;
}
HttpSimpleClient httpClient = HttpSimpleClient.create(workExecutor, clientAsyncGroup);
field.set(srcObj, httpClient);
rf.inject(resourceName, httpClient, null); // 给其可能包含@Resource的字段赋值;
@@ -501,9 +478,6 @@ public final class Application {
//------------------------------------ 注册 HttpRpcClient ------------------------------------
resourceFactory.register((ResourceFactory rf, String srcResourceName, final Object srcObj, String resourceName, Field field, final Object attachment) -> {
try {
if (field.getAnnotation(Resource.class) == null && field.getAnnotation(javax.annotation.Resource.class) == null) {
return null;
}
ClusterAgent clusterAgent = resourceFactory.find("", ClusterAgent.class);
MessageAgent messageAgent = resourceFactory.find(resourceName, MessageAgent.class);
if (messageAgent != null) {

View File

@@ -129,9 +129,6 @@ public class NodeHttpServer extends NodeServer {
final ResourceFactory regFactory = application.getResourceFactory();
resourceFactory.register((ResourceFactory rf, String srcResourceName, final Object srcObj, final String resourceName, Field field, Object attachment) -> { //主要用于单点的服务
try {
if (field.getAnnotation(Resource.class) == null && field.getAnnotation(javax.annotation.Resource.class) == null) {
return null;
}
if (!(srcObj instanceof WebSocketServlet)) {
return null;
}

View File

@@ -252,12 +252,6 @@ public abstract class NodeServer {
@Override
public Object load(ResourceFactory rf, String srcResourceName, final Object srcObj, final String resourceName, Field field, final Object attachment) {
try {
if (field.getAnnotation(Resource.class) == null && field.getAnnotation(javax.annotation.Resource.class) == null) {
return null;
}
if ((srcObj instanceof Service) && Sncp.isRemote((Service) srcObj)) {
return null; //远程模式不需要注入 WebSocketNode
}
Service nodeService = rf.find(resourceName, WebSocketNode.class);
if (nodeService == null) {
final HashSet<String> groups = new HashSet<>();
@@ -300,15 +294,6 @@ public abstract class NodeServer {
final ResourceFactory appResFactory = application.getResourceFactory();
Class<Service> resServiceType = Service.class;
try {
if (field.getAnnotation(Resource.class) == null && field.getAnnotation(javax.annotation.Resource.class) == null) {
return null;
}
if ((srcObj instanceof Service) && Sncp.isRemote((Service) srcObj)) {
return null; //远程模式不得注入 AutoLoad Service
}
if (!Service.class.isAssignableFrom(field.getType())) {
return null;
}
resServiceType = (Class) field.getType();
if (resServiceType.getAnnotation(Local.class) == null) {
return null;

View File

@@ -15,6 +15,7 @@ import java.util.logging.Level;
import org.redkale.boot.Application;
import org.redkale.boot.ModuleEngine;
import org.redkale.inject.ResourceEvent;
import org.redkale.source.SourceManager;
import org.redkale.util.AnyValue;
import org.redkale.util.AnyValueWriter;
import org.redkale.util.RedkaleClassLoader;
@@ -96,7 +97,8 @@ public class ClusterModuleEngine extends ModuleEngine {
long s = System.currentTimeMillis();
if (this.clusterAgent instanceof CacheClusterAgent) {
String sourceName = ((CacheClusterAgent) clusterAgent).getSourceName(); //必须在inject前调用需要赋值Resourcable.name
//loadCacheSource(sourceName, false);
SourceManager sourceManager = application.getResourceFactory().find(SourceManager.class);
sourceManager.loadCacheSource(sourceName, false);
}
this.resourceFactory.inject(clusterAgent);
clusterAgent.init(clusterAgent.getConfig());

View File

@@ -512,12 +512,6 @@ public class SourceModuleEngine extends ModuleEngine implements SourceManager {
@Override
public Object load(ResourceFactory rf, String srcResourceName, final Object srcObj, final String resourceName, Field field, final Object attachment) {
try {
if (field.getAnnotation(Resource.class) == null && field.getAnnotation(javax.annotation.Resource.class) == null) {
return null;
}
if ((srcObj instanceof Service) && Sncp.isRemote((Service) srcObj)) {
return null; //远程模式不得注入 DataSource
}
DataSource source = loadDataSource(resourceName, false);
field.set(srcObj, source);
return source;
@@ -533,12 +527,6 @@ public class SourceModuleEngine extends ModuleEngine implements SourceManager {
@Override
public Object load(ResourceFactory rf, String srcResourceName, final Object srcObj, final String resourceName, Field field, final Object attachment) {
try {
if (field.getAnnotation(Resource.class) == null && field.getAnnotation(javax.annotation.Resource.class) == null) {
return null;
}
if ((srcObj instanceof Service) && Sncp.isRemote((Service) srcObj)) {
return null; //远程模式不需要注入 CacheSource
}
if (srcObj instanceof Servlet) {
throw new RedkaleException("CacheSource cannot inject in Servlet " + srcObj);
}