CacheSource和DataSource支持资源复用

This commit is contained in:
redkale
2023-01-30 21:10:28 +08:00
parent 18afbd6bae
commit 9bafeccd38
5 changed files with 27 additions and 5 deletions

View File

@@ -1246,6 +1246,13 @@ public final class Application {
logger.info("Load CacheSource resourceName = " + sourceName + ", source = " + source + " in " + (System.currentTimeMillis() - st) + " ms");
return source;
}
if (!sourceConf.getValue(AbstractCacheSource.CACHE_SOURCE_SOURCE, "").isEmpty()) {
CacheSource source = loadCacheSource(sourceConf.getValue(AbstractCacheSource.CACHE_SOURCE_SOURCE), autoMemory);
if (source != null) {
resourceFactory.register(sourceName, CacheSource.class, source);
}
return source;
}
try {
CacheSource source = AbstractCacheSource.createCacheSource(serverClassLoader, resourceFactory, sourceConf, sourceName, compileMode);
cacheSources.add(source);
@@ -1282,6 +1289,17 @@ public final class Application {
logger.info("Load DataSource resourceName = " + sourceName + ", source = " + source);
return source;
}
if (!sourceConf.getValue(AbstractDataSource.DATA_SOURCE_SOURCE, "").isEmpty()) {
DataSource source = loadDataSource(sourceConf.getValue(AbstractDataSource.DATA_SOURCE_SOURCE), autoMemory);
if (source != null) {
if (source instanceof DataMemorySource && DataMemorySource.isSearchType(sourceConf)) {
resourceFactory.register(sourceName, SearchSource.class, source);
} else {
resourceFactory.register(sourceName, DataSource.class, source);
}
}
return source;
}
try {
DataSource source = AbstractDataSource.createDataSource(serverClassLoader, resourceFactory, sourceConf, sourceName, compileMode);
dataSources.add(source);

View File

@@ -300,9 +300,7 @@ public abstract class Server<K extends Serializable, C extends Context, R extend
this.dispatcher.init(this.context, config); //不能在init方法内执行因Server.init执行后会调用loadService,loadServlet, 再执行Server.start
this.postPrepareInit();
this.serverChannel = ProtocolServer.create(this.netprotocol, context, this.serverClassLoader);
if (application != null) { //main函数调试时可能为null
application.getResourceFactory().inject(this.serverChannel);
}
this.resourceFactory.inject(this.serverChannel);
this.serverChannel.open(config);
serverChannel.bind(address, backlog);
SocketAddress localAddress = serverChannel.getLocalAddress();

View File

@@ -3563,7 +3563,7 @@ public final class Rest {
}
this.methodIdx = methodIndex;
this.ignore = mapping.ignore();
String n = formatMappingName(mapping.name());
String n = mapping.name();
if (n.isEmpty()) {
n = method.getName();
}
@@ -3586,7 +3586,7 @@ public final class Rest {
}
}
this.existsPound = pound;
this.newMethodName = this.name.replace('/', '$').replace('.', '_');
this.newMethodName = formatMappingName(this.name.replace('/', '$').replace('.', '_'));
this.newActionClassName = "_Dyn_" + this.newMethodName + "_ActionHttpServlet";
}

View File

@@ -24,6 +24,9 @@ import org.redkale.util.*;
@ResourceType(CacheSource.class)
public abstract class AbstractCacheSource extends AbstractService implements CacheSource, AutoCloseable, Resourcable {
//@since 2.8.0 复用另一source资源
public static final String CACHE_SOURCE_SOURCE = "source";
//@since 2.7.0
public static final String CACHE_SOURCE_URL = "url";

View File

@@ -39,6 +39,9 @@ import org.redkale.util.*;
@ResourceType(DataSource.class)
public abstract class AbstractDataSource extends AbstractService implements DataSource, AutoCloseable, Resourcable {
//@since 2.8.0 复用另一source资源
public static final String DATA_SOURCE_SOURCE = "source";
//@since 2.7.0 格式: x.x.x.x:yyyy
public static final String DATA_SOURCE_PROXY_ADDRESS = "proxy-address";