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