This commit is contained in:
redkale
2023-12-11 22:18:17 +08:00
parent a2f6578503
commit f7e3f7d7ec
10 changed files with 31 additions and 24 deletions

View File

@@ -41,13 +41,20 @@
-->
<executor threads="4"/>
<!--
【节点全局唯一】 @since 2.8.0
全局Serivce的定时任务设置没配置该节点将自动创建一个。
enabled 是否开启缓存功能。默认: true
-->
<schedule enabled="true"/>
<!--
【节点全局唯一】 @since 2.8.0
全局Serivce的缓存设置没配置该节点将自动创建一个。
enabled 是否开启缓存功能。默认: true
source: 远程CacheSource的资源名
-->
<caching enabled="true" source="xxx"/>
<cache enabled="true" source="xxx"/>
<!--
【节点全局唯一】

View File

@@ -25,7 +25,7 @@ module org.redkale {
exports org.redkale.convert.ext;
exports org.redkale.convert.json;
exports org.redkale.convert.protobuf;
exports org.redkale.lock;
exports org.redkale.locking;
exports org.redkale.mq;
exports org.redkale.net;
exports org.redkale.net.client;

View File

@@ -1223,7 +1223,7 @@ public final class Application {
}
{ //设置定时管理器
final AnyValue scheduleConf = config.getAnyValue("scheduling", true);
final AnyValue scheduleConf = config.getAnyValue("schedule", true);
this.resourceFactory.inject(this.scheduleManager);
if (!isCompileMode()) {
this.scheduleManager.init(scheduleConf);
@@ -1232,7 +1232,7 @@ public final class Application {
}
{ //设置缓存管理器
final AnyValue cacheConf = config.getAnyValue("caching");
final AnyValue cacheConf = config.getAnyValue("cache");
this.resourceFactory.inject(this.cacheManager);
if (!isCompileMode() && cacheConf != null) {
this.cacheManager.init(cacheConf);

View File

@@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
@Documented
@Target(METHOD)
@Retention(RUNTIME)
public @interface Caching {
public @interface Cached {
/**
* 缓存的key支持参数动态组合比如"key_#{id}"

View File

@@ -87,7 +87,7 @@ public class CacheManagerService implements CacheManager, Service {
this.enabled = conf.getBoolValue("enabled", true);
if (this.enabled) {
this.localSource.init(conf);
String remoteSourceName = conf.getValue("remoteSource");
String remoteSourceName = conf.getValue("source");
if (remoteSource == null && application != null && Utility.isNotBlank(remoteSourceName)) {
CacheSource source = application.loadCacheSource(remoteSourceName, false);
if (source == null) {

View File

@@ -1,7 +1,7 @@
/*
*
*/
package org.redkale.lock;
package org.redkale.locking;
import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.METHOD;
@@ -29,6 +29,6 @@ import java.lang.annotation.Target;
@Documented
@Target(METHOD)
@Retention(RUNTIME)
public @interface Locking {
public @interface Locked {
}

View File

@@ -22,7 +22,6 @@ import org.redkale.convert.bson.BsonConvert;
import org.redkale.mq.MessageAgent;
import org.redkale.net.http.WebSocketNode;
import org.redkale.net.sncp.SncpRemoteInfo.SncpRemoteAction;
import org.redkale.schedule.Scheduling;
import org.redkale.service.*;
import org.redkale.util.AnyValue;
import org.redkale.util.RedkaleClassLoader;
@@ -31,6 +30,7 @@ import org.redkale.util.ResourceFactory;
import org.redkale.util.TypeToken;
import org.redkale.util.Uint128;
import org.redkale.util.Utility;
import org.redkale.schedule.Scheduled;
/**
* Service Node Communicate Protocol
@@ -75,11 +75,11 @@ public abstract class Sncp {
private String methodName;
private Scheduling schedule;
private Scheduled schedule;
private Runnable task;
public SchedulingEntry(Class serviceType, String methodName, Scheduling schedule, Runnable task) {
public SchedulingEntry(Class serviceType, String methodName, Scheduled schedule, Runnable task) {
Objects.requireNonNull(serviceType);
Objects.requireNonNull(methodName);
Objects.requireNonNull(schedule);
@@ -98,7 +98,7 @@ public abstract class Sncp {
return methodName;
}
public Scheduling getSchedule() {
public Scheduled getSchedule() {
return schedule;
}
@@ -134,10 +134,10 @@ public abstract class Sncp {
if (method.isSynthetic()) {
continue;
}
if (method.getAnnotation(Scheduling.class) != null) {
if (method.getAnnotation(Scheduled.class) != null) {
if (Modifier.isStatic(method.getModifiers())
|| method.getParameterCount() > 0) {
throw new SncpException(Scheduling.class.getSimpleName() + " must be on protected and non-parameter method, but on " + method);
throw new SncpException(Scheduled.class.getSimpleName() + " must be on protected and non-parameter method, but on " + method);
}
RedkaleClassLoader.putReflectionMethod(serviceTypeOrImplClass.getName(), method);
continue;

View File

@@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit;
*/
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface Scheduling {
public @interface Scheduled {
/**
* 名称

View File

@@ -31,14 +31,14 @@ import org.redkale.annotation.Nullable;
import org.redkale.annotation.Resource;
import org.redkale.annotation.ResourceType;
import org.redkale.boot.Application;
import org.redkale.schedule.ScheduleManager;
import org.redkale.schedule.Scheduling;
import org.redkale.service.Local;
import org.redkale.service.Service;
import org.redkale.util.AnyValue;
import org.redkale.util.RedkaleClassLoader;
import org.redkale.util.RedkaleException;
import org.redkale.util.Utility;
import org.redkale.schedule.Scheduled;
import org.redkale.schedule.ScheduleManager;
/**
* 定时任务管理器
@@ -157,14 +157,14 @@ public class ScheduleManagerService implements ScheduleManager, Service {
WeakReference ref = new WeakReference(service);
do {
for (final Method method : clazz.getDeclaredMethods()) {
if (method.getAnnotation(Scheduling.class) == null) {
if (method.getAnnotation(Scheduled.class) == null) {
continue;
}
if (tasks.containsKey(method.getName())) {
continue;
}
if (method.getParameterCount() > 0) {
throw new RedkaleException("@" + Scheduling.class.getSimpleName() + " must be on non-parameter method, but on " + method);
throw new RedkaleException("@" + Scheduled.class.getSimpleName() + " must be on non-parameter method, but on " + method);
}
ScheduledTask task = schedule(ref, method);
if (task == null) {
@@ -185,7 +185,7 @@ public class ScheduleManagerService implements ScheduleManager, Service {
}
protected ScheduledTask schedule(WeakReference ref, Method method) {
Scheduling ann = method.getAnnotation(Scheduling.class);
Scheduled ann = method.getAnnotation(Scheduled.class);
String name = getProperty(ann.name());
String cron = getProperty(ann.cron());
String fixedDelay = getProperty(ann.fixedDelay());

View File

@@ -3,9 +3,9 @@
*/
package org.redkale.test.schedule;
import org.redkale.schedule.Scheduling;
import org.redkale.service.Service;
import org.redkale.util.Times;
import org.redkale.schedule.Scheduled;
/**
*
@@ -13,18 +13,18 @@ import org.redkale.util.Times;
*/
public class ScheduleService implements Service {
@Scheduling(cron = "0/1 * * * * ?")
@Scheduled(cron = "0/1 * * * * ?")
public void task1() {
System.out.println(Times.nowMillis() + "每秒-----------执行task1");
}
@Scheduling(cron = "0/1 * * * * ?")
@Scheduled(cron = "0/1 * * * * ?")
public String task2() {
System.out.println(Times.nowMillis() + "每秒*****执行task2");
return "";
}
@Scheduling(cron = "0/1 * * * * ?")
@Scheduled(cron = "0/1 * * * * ?")
private void task3() {
System.out.println(Times.nowMillis() + "每秒执行task3");
}