spi
This commit is contained in:
@@ -41,10 +41,12 @@ module org.redkale {
|
||||
exports org.redkale.watch;
|
||||
|
||||
uses org.redkale.boot.PropertiesAgentProvider;
|
||||
uses org.redkale.cache.spi.CacheManagerProvider;
|
||||
uses org.redkale.cluster.ClusterAgentProvider;
|
||||
uses org.redkale.convert.ConvertProvider;
|
||||
uses org.redkale.inject.ResourceAnnotationProvider;
|
||||
uses org.redkale.mq.MessageAgentProvider;
|
||||
uses org.redkale.schedule.spi.ScheduleManagerProvider;
|
||||
uses org.redkale.source.CacheSourceProvider;
|
||||
uses org.redkale.source.DataSourceProvider;
|
||||
uses org.redkale.source.DataNativeSqlParserProvider;
|
||||
|
||||
21
src/main/java/org/redkale/cache/spi/CacheManagerProvider.java
vendored
Normal file
21
src/main/java/org/redkale/cache/spi/CacheManagerProvider.java
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.cache.spi;
|
||||
|
||||
import org.redkale.cache.CacheManager;
|
||||
import org.redkale.util.InstanceProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* 自定义的CacheManager加载器, 如果标记@Priority加载器的优先级需要大于1000, 1000以下预留给官方加载器
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public interface CacheManagerProvider extends InstanceProvider<CacheManager> {
|
||||
|
||||
}
|
||||
@@ -87,10 +87,6 @@ public class CacheManagerService implements CacheManager, Service {
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnyValue getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(AnyValue conf) {
|
||||
this.config = conf;
|
||||
|
||||
@@ -3,10 +3,17 @@
|
||||
*/
|
||||
package org.redkale.cache.spi;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.boot.ModuleEngine;
|
||||
import org.redkale.cache.CacheManager;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.InstanceProvider;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -15,7 +22,9 @@ import org.redkale.util.AnyValue;
|
||||
public class CacheModuleEngine extends ModuleEngine {
|
||||
|
||||
//全局缓存管理器
|
||||
private CacheManagerService cacheManager;
|
||||
private CacheManager cacheManager;
|
||||
|
||||
private AnyValue config;
|
||||
|
||||
public CacheModuleEngine(Application application) {
|
||||
super(application);
|
||||
@@ -42,13 +51,16 @@ public class CacheModuleEngine extends ModuleEngine {
|
||||
/**
|
||||
* 结束Application.init方法前被调用
|
||||
*/
|
||||
@Override
|
||||
public void onAppPostInit() {
|
||||
//设置缓存管理器
|
||||
this.cacheManager = CacheManagerService.create(null).enabled(false);
|
||||
final AnyValue cacheConf = application.getAppConfig().getAnyValue("cache");
|
||||
if (cacheConf != null && !application.isCompileMode()) {
|
||||
this.config = application.getAppConfig().getAnyValue("cache");
|
||||
this.cacheManager = createManager(this.config);
|
||||
if (this.config != null && !application.isCompileMode()) {
|
||||
this.resourceFactory.inject(this.cacheManager);
|
||||
this.cacheManager.init(cacheConf);
|
||||
if (this.cacheManager instanceof Service) {
|
||||
((Service) this.cacheManager).init(this.config);
|
||||
}
|
||||
}
|
||||
this.resourceFactory.register("", CacheManager.class, this.cacheManager);
|
||||
}
|
||||
@@ -56,9 +68,27 @@ public class CacheModuleEngine extends ModuleEngine {
|
||||
/**
|
||||
* 进入Application.shutdown方法被调用
|
||||
*/
|
||||
@Override
|
||||
public void onAppPreShutdown() {
|
||||
if (!application.isCompileMode()) {
|
||||
this.cacheManager.destroy(this.cacheManager.getConfig());
|
||||
if (!application.isCompileMode() && this.cacheManager instanceof Service) {
|
||||
((Service) this.cacheManager).destroy(this.config);
|
||||
}
|
||||
}
|
||||
|
||||
private CacheManager createManager(AnyValue conf) {
|
||||
Iterator<CacheManagerProvider> it = ServiceLoader.load(CacheManagerProvider.class, application.getClassLoader()).iterator();
|
||||
RedkaleClassLoader.putServiceLoader(CacheManagerProvider.class);
|
||||
List<CacheManagerProvider> providers = new ArrayList<>();
|
||||
while (it.hasNext()) {
|
||||
CacheManagerProvider provider = it.next();
|
||||
if (provider != null && provider.acceptsConf(conf)) {
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(provider.getClass(), provider.getClass().getName());
|
||||
providers.add(provider);
|
||||
}
|
||||
}
|
||||
for (CacheManagerProvider provider : InstanceProvider.sort(providers)) {
|
||||
return provider.createInstance();
|
||||
}
|
||||
return CacheManagerService.create(null).enabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.schedule.spi;
|
||||
|
||||
import org.redkale.schedule.ScheduleManager;
|
||||
import org.redkale.util.InstanceProvider;
|
||||
|
||||
/**
|
||||
*
|
||||
* 自定义的ScheduleManager加载器, 如果标记@Priority加载器的优先级需要大于1000, 1000以下预留给官方加载器
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public interface ScheduleManagerProvider extends InstanceProvider<ScheduleManager> {
|
||||
|
||||
}
|
||||
@@ -94,10 +94,6 @@ public class ScheduleManagerService implements ScheduleManager, Service {
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnyValue getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(AnyValue conf) {
|
||||
if (conf == null) {
|
||||
|
||||
@@ -3,11 +3,17 @@
|
||||
*/
|
||||
package org.redkale.schedule.spi;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceLoader;
|
||||
import org.redkale.boot.Application;
|
||||
import org.redkale.boot.ModuleEngine;
|
||||
import org.redkale.schedule.ScheduleManager;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.AnyValue;
|
||||
import org.redkale.util.InstanceProvider;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -16,7 +22,10 @@ import org.redkale.util.AnyValue;
|
||||
public class ScheduleModuleEngine extends ModuleEngine {
|
||||
|
||||
//全局定时任务管理器
|
||||
private ScheduleManagerService scheduleManager;
|
||||
private ScheduleManager scheduleManager;
|
||||
|
||||
//配置
|
||||
protected AnyValue config;
|
||||
|
||||
public ScheduleModuleEngine(Application application) {
|
||||
super(application);
|
||||
@@ -43,13 +52,16 @@ public class ScheduleModuleEngine extends ModuleEngine {
|
||||
/**
|
||||
* 结束Application.init方法前被调用
|
||||
*/
|
||||
@Override
|
||||
public void onAppPostInit() {
|
||||
//设置定时管理器
|
||||
this.scheduleManager = ScheduleManagerService.create(null).enabled(false);
|
||||
final AnyValue scheduleConf = application.getAppConfig().getAnyValue("schedule");
|
||||
if (scheduleConf != null && !application.isCompileMode()) {
|
||||
this.config = application.getAppConfig().getAnyValue("schedule");
|
||||
this.scheduleManager = createManager(this.config);
|
||||
if (this.config != null && !application.isCompileMode()) {
|
||||
this.resourceFactory.inject(this.scheduleManager);
|
||||
this.scheduleManager.init(scheduleConf);
|
||||
if (this.scheduleManager instanceof Service) {
|
||||
((Service) this.scheduleManager).init(this.config);
|
||||
}
|
||||
}
|
||||
this.resourceFactory.register("", ScheduleManager.class, this.scheduleManager);
|
||||
}
|
||||
@@ -59,6 +71,7 @@ public class ScheduleModuleEngine extends ModuleEngine {
|
||||
*
|
||||
* @param service Service
|
||||
*/
|
||||
@Override
|
||||
public void onServicePostInit(Service service) {
|
||||
this.scheduleManager.schedule(service);
|
||||
}
|
||||
@@ -76,9 +89,27 @@ public class ScheduleModuleEngine extends ModuleEngine {
|
||||
/**
|
||||
* 进入Application.shutdown方法被调用
|
||||
*/
|
||||
@Override
|
||||
public void onAppPreShutdown() {
|
||||
if (!application.isCompileMode()) {
|
||||
this.scheduleManager.destroy(this.scheduleManager.getConfig());
|
||||
if (!application.isCompileMode() && this.scheduleManager instanceof Service) {
|
||||
((Service) this.scheduleManager).destroy(this.config);
|
||||
}
|
||||
}
|
||||
|
||||
private ScheduleManager createManager(AnyValue conf) {
|
||||
Iterator<ScheduleManagerProvider> it = ServiceLoader.load(ScheduleManagerProvider.class, application.getClassLoader()).iterator();
|
||||
RedkaleClassLoader.putServiceLoader(ScheduleManagerProvider.class);
|
||||
List<ScheduleManagerProvider> providers = new ArrayList<>();
|
||||
while (it.hasNext()) {
|
||||
ScheduleManagerProvider provider = it.next();
|
||||
if (provider != null && provider.acceptsConf(conf)) {
|
||||
RedkaleClassLoader.putReflectionPublicConstructors(provider.getClass(), provider.getClass().getName());
|
||||
providers.add(provider);
|
||||
}
|
||||
}
|
||||
for (ScheduleManagerProvider provider : InstanceProvider.sort(providers)) {
|
||||
return provider.createInstance();
|
||||
}
|
||||
return ScheduleManagerService.create(null).enabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user