CacheManagerService
This commit is contained in:
@@ -31,7 +31,7 @@ import org.redkale.mq.*;
|
||||
import org.redkale.net.*;
|
||||
import org.redkale.net.http.*;
|
||||
import org.redkale.net.sncp.*;
|
||||
import org.redkale.scheduling.ScheduleEngine;
|
||||
import org.redkale.scheduling.ScheduleManagerService;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.util.*;
|
||||
@@ -209,7 +209,7 @@ public final class Application {
|
||||
final ResourceFactory resourceFactory = ResourceFactory.create();
|
||||
|
||||
//全局定时任务管理器
|
||||
private final ScheduleEngine scheduleEngine;
|
||||
private final ScheduleManagerService scheduleManager;
|
||||
|
||||
//服务配置项
|
||||
final AnyValue config;
|
||||
@@ -626,8 +626,8 @@ public final class Application {
|
||||
}
|
||||
|
||||
{ //设置定时管理
|
||||
this.scheduleEngine = ScheduleEngine.create(this::getPropertyValue).enabled(!isCompileMode());
|
||||
this.resourceFactory.register("", this.scheduleEngine);
|
||||
this.scheduleManager = ScheduleManagerService.create(this::getPropertyValue).enabled(!isCompileMode());
|
||||
this.resourceFactory.register("", this.scheduleManager);
|
||||
}
|
||||
|
||||
{ //加载原生sql解析器
|
||||
@@ -2163,11 +2163,11 @@ public final class Application {
|
||||
}
|
||||
|
||||
public void schedule(Object service) {
|
||||
this.scheduleEngine.schedule(service);
|
||||
this.scheduleManager.schedule(service);
|
||||
}
|
||||
|
||||
public void unschedule(Object service) {
|
||||
this.scheduleEngine.unschedule(service);
|
||||
this.scheduleManager.unschedule(service);
|
||||
}
|
||||
|
||||
void updateEnvironmentProperties(String namespace, List<ResourceEvent> events) {
|
||||
@@ -2633,7 +2633,7 @@ public final class Application {
|
||||
if (this.workExecutor != null) {
|
||||
this.workExecutor.shutdownNow();
|
||||
}
|
||||
this.scheduleEngine.destroy();
|
||||
this.scheduleManager.destroy();
|
||||
|
||||
long intms = System.currentTimeMillis() - f;
|
||||
String ms = String.valueOf(intms);
|
||||
@@ -2747,8 +2747,8 @@ public final class Application {
|
||||
return clusterAgent;
|
||||
}
|
||||
|
||||
public ScheduleEngine getScheduleEngine() {
|
||||
return this.scheduleEngine;
|
||||
public ScheduleManagerService getScheduleManager() {
|
||||
return this.scheduleManager;
|
||||
}
|
||||
|
||||
public MessageAgent getMessageAgent(String name) {
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.redkale.util.TypeToken;
|
||||
@Component
|
||||
@AutoLoad(false)
|
||||
@ResourceType(CacheManager.class)
|
||||
public class CacheEngine implements CacheManager, Service {
|
||||
public class CacheManagerService implements CacheManager, Service {
|
||||
|
||||
//缓存配置项
|
||||
protected boolean enabled = true;
|
||||
@@ -45,12 +45,12 @@ public class CacheEngine implements CacheManager, Service {
|
||||
//远程缓存Source
|
||||
protected CacheSource remoteSource;
|
||||
|
||||
protected CacheEngine(@Nullable CacheSource remoteSource) {
|
||||
protected CacheManagerService(@Nullable CacheSource remoteSource) {
|
||||
this.remoteSource = remoteSource;
|
||||
}
|
||||
|
||||
public static CacheEngine create(@Nullable CacheSource remoteSource) {
|
||||
return new CacheEngine(remoteSource);
|
||||
public static CacheManagerService create(@Nullable CacheSource remoteSource) {
|
||||
return new CacheManagerService(remoteSource);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -76,7 +76,7 @@ public class CacheEngine implements CacheManager, Service {
|
||||
return enabled;
|
||||
}
|
||||
|
||||
public CacheEngine addHash(String hash) {
|
||||
public CacheManagerService addHash(String hash) {
|
||||
this.hashNames.add(hash);
|
||||
return this;
|
||||
}
|
||||
@@ -49,7 +49,7 @@ import org.redkale.util.Utility;
|
||||
@Component
|
||||
@AutoLoad(false)
|
||||
@ResourceType(ScheduleManager.class)
|
||||
public class ScheduleEngine implements ScheduleManager, Service {
|
||||
public class ScheduleManagerService implements ScheduleManager, Service {
|
||||
|
||||
protected final Logger logger = Logger.getLogger(this.getClass().getSimpleName());
|
||||
|
||||
@@ -64,17 +64,17 @@ public class ScheduleEngine implements ScheduleManager, Service {
|
||||
|
||||
private boolean enabled = true;
|
||||
|
||||
protected ScheduleEngine(UnaryOperator<String> propertyFunc) {
|
||||
protected ScheduleManagerService(UnaryOperator<String> propertyFunc) {
|
||||
this.propertyFunc = propertyFunc;
|
||||
this.scheduler = new ScheduledThreadPoolExecutor(Utility.cpus(), Utility.newThreadFactory("Scheduled-Task-Thread-%s"));
|
||||
this.scheduler.setRemoveOnCancelPolicy(true);
|
||||
}
|
||||
|
||||
public static ScheduleEngine create(UnaryOperator<String> propertyFunc) {
|
||||
return new ScheduleEngine(propertyFunc);
|
||||
public static ScheduleManagerService create(UnaryOperator<String> propertyFunc) {
|
||||
return new ScheduleManagerService(propertyFunc);
|
||||
}
|
||||
|
||||
public ScheduleEngine enabled(boolean val) {
|
||||
public ScheduleManagerService enabled(boolean val) {
|
||||
this.enabled = val;
|
||||
return this;
|
||||
}
|
||||
@@ -6,7 +6,7 @@ package org.redkale.test.caching;
|
||||
import java.time.Duration;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.redkale.caching.CacheEngine;
|
||||
import org.redkale.caching.CacheManagerService;
|
||||
import org.redkale.convert.json.JsonConvert;
|
||||
import org.redkale.source.CacheMemorySource;
|
||||
import org.redkale.util.Utility;
|
||||
@@ -26,7 +26,7 @@ public class CachingTest {
|
||||
public void run() throws Exception {
|
||||
CacheMemorySource remoteSource = new CacheMemorySource("remote");
|
||||
remoteSource.init(null);
|
||||
CacheEngine cache = CacheEngine.create(remoteSource);
|
||||
CacheManagerService cache = CacheManagerService.create(remoteSource);
|
||||
cache.init(null);
|
||||
Duration expire = Duration.ofMillis(490);
|
||||
cache.localSetString("user", "name:haha", "myha", expire);
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package org.redkale.test.scheduling;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.redkale.scheduling.ScheduleEngine;
|
||||
import org.redkale.scheduling.ScheduleManagerService;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
@@ -20,7 +20,7 @@ public class ScheduleTest {
|
||||
|
||||
@Test
|
||||
public void run() throws Exception {
|
||||
ScheduleEngine factory = ScheduleEngine.create(null);
|
||||
ScheduleManagerService factory = ScheduleManagerService.create(null);
|
||||
ScheduleService service = new ScheduleService();
|
||||
factory.schedule(service);
|
||||
Utility.sleep(3000);
|
||||
|
||||
Reference in New Issue
Block a user