优化
This commit is contained in:
@@ -41,13 +41,20 @@
|
|||||||
-->
|
-->
|
||||||
<executor threads="4"/>
|
<executor threads="4"/>
|
||||||
|
|
||||||
|
<!--
|
||||||
|
【节点全局唯一】 @since 2.8.0
|
||||||
|
全局Serivce的定时任务设置,没配置该节点将自动创建一个。
|
||||||
|
enabled: 是否开启缓存功能。默认: true
|
||||||
|
-->
|
||||||
|
<schedule enabled="true"/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
【节点全局唯一】 @since 2.8.0
|
【节点全局唯一】 @since 2.8.0
|
||||||
全局Serivce的缓存设置,没配置该节点将自动创建一个。
|
全局Serivce的缓存设置,没配置该节点将自动创建一个。
|
||||||
enabled: 是否开启缓存功能。默认: true
|
enabled: 是否开启缓存功能。默认: true
|
||||||
source: 远程CacheSource的资源名
|
source: 远程CacheSource的资源名
|
||||||
-->
|
-->
|
||||||
<caching enabled="true" source="xxx"/>
|
<cache enabled="true" source="xxx"/>
|
||||||
|
|
||||||
<!--
|
<!--
|
||||||
【节点全局唯一】
|
【节点全局唯一】
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ module org.redkale {
|
|||||||
exports org.redkale.convert.ext;
|
exports org.redkale.convert.ext;
|
||||||
exports org.redkale.convert.json;
|
exports org.redkale.convert.json;
|
||||||
exports org.redkale.convert.protobuf;
|
exports org.redkale.convert.protobuf;
|
||||||
exports org.redkale.lock;
|
exports org.redkale.locking;
|
||||||
exports org.redkale.mq;
|
exports org.redkale.mq;
|
||||||
exports org.redkale.net;
|
exports org.redkale.net;
|
||||||
exports org.redkale.net.client;
|
exports org.redkale.net.client;
|
||||||
|
|||||||
@@ -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);
|
this.resourceFactory.inject(this.scheduleManager);
|
||||||
if (!isCompileMode()) {
|
if (!isCompileMode()) {
|
||||||
this.scheduleManager.init(scheduleConf);
|
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);
|
this.resourceFactory.inject(this.cacheManager);
|
||||||
if (!isCompileMode() && cacheConf != null) {
|
if (!isCompileMode() && cacheConf != null) {
|
||||||
this.cacheManager.init(cacheConf);
|
this.cacheManager.init(cacheConf);
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
@Documented
|
@Documented
|
||||||
@Target(METHOD)
|
@Target(METHOD)
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
public @interface Caching {
|
public @interface Cached {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 缓存的key,支持参数动态组合,比如"key_#{id}"
|
* 缓存的key,支持参数动态组合,比如"key_#{id}"
|
||||||
@@ -87,7 +87,7 @@ public class CacheManagerService implements CacheManager, Service {
|
|||||||
this.enabled = conf.getBoolValue("enabled", true);
|
this.enabled = conf.getBoolValue("enabled", true);
|
||||||
if (this.enabled) {
|
if (this.enabled) {
|
||||||
this.localSource.init(conf);
|
this.localSource.init(conf);
|
||||||
String remoteSourceName = conf.getValue("remoteSource");
|
String remoteSourceName = conf.getValue("source");
|
||||||
if (remoteSource == null && application != null && Utility.isNotBlank(remoteSourceName)) {
|
if (remoteSource == null && application != null && Utility.isNotBlank(remoteSourceName)) {
|
||||||
CacheSource source = application.loadCacheSource(remoteSourceName, false);
|
CacheSource source = application.loadCacheSource(remoteSourceName, false);
|
||||||
if (source == null) {
|
if (source == null) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
package org.redkale.lock;
|
package org.redkale.locking;
|
||||||
|
|
||||||
import java.lang.annotation.Documented;
|
import java.lang.annotation.Documented;
|
||||||
import static java.lang.annotation.ElementType.METHOD;
|
import static java.lang.annotation.ElementType.METHOD;
|
||||||
@@ -29,6 +29,6 @@ import java.lang.annotation.Target;
|
|||||||
@Documented
|
@Documented
|
||||||
@Target(METHOD)
|
@Target(METHOD)
|
||||||
@Retention(RUNTIME)
|
@Retention(RUNTIME)
|
||||||
public @interface Locking {
|
public @interface Locked {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -22,7 +22,6 @@ import org.redkale.convert.bson.BsonConvert;
|
|||||||
import org.redkale.mq.MessageAgent;
|
import org.redkale.mq.MessageAgent;
|
||||||
import org.redkale.net.http.WebSocketNode;
|
import org.redkale.net.http.WebSocketNode;
|
||||||
import org.redkale.net.sncp.SncpRemoteInfo.SncpRemoteAction;
|
import org.redkale.net.sncp.SncpRemoteInfo.SncpRemoteAction;
|
||||||
import org.redkale.schedule.Scheduling;
|
|
||||||
import org.redkale.service.*;
|
import org.redkale.service.*;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
import org.redkale.util.RedkaleClassLoader;
|
import org.redkale.util.RedkaleClassLoader;
|
||||||
@@ -31,6 +30,7 @@ import org.redkale.util.ResourceFactory;
|
|||||||
import org.redkale.util.TypeToken;
|
import org.redkale.util.TypeToken;
|
||||||
import org.redkale.util.Uint128;
|
import org.redkale.util.Uint128;
|
||||||
import org.redkale.util.Utility;
|
import org.redkale.util.Utility;
|
||||||
|
import org.redkale.schedule.Scheduled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Service Node Communicate Protocol
|
* Service Node Communicate Protocol
|
||||||
@@ -75,11 +75,11 @@ public abstract class Sncp {
|
|||||||
|
|
||||||
private String methodName;
|
private String methodName;
|
||||||
|
|
||||||
private Scheduling schedule;
|
private Scheduled schedule;
|
||||||
|
|
||||||
private Runnable task;
|
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(serviceType);
|
||||||
Objects.requireNonNull(methodName);
|
Objects.requireNonNull(methodName);
|
||||||
Objects.requireNonNull(schedule);
|
Objects.requireNonNull(schedule);
|
||||||
@@ -98,7 +98,7 @@ public abstract class Sncp {
|
|||||||
return methodName;
|
return methodName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Scheduling getSchedule() {
|
public Scheduled getSchedule() {
|
||||||
return schedule;
|
return schedule;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -134,10 +134,10 @@ public abstract class Sncp {
|
|||||||
if (method.isSynthetic()) {
|
if (method.isSynthetic()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (method.getAnnotation(Scheduling.class) != null) {
|
if (method.getAnnotation(Scheduled.class) != null) {
|
||||||
if (Modifier.isStatic(method.getModifiers())
|
if (Modifier.isStatic(method.getModifiers())
|
||||||
|| method.getParameterCount() > 0) {
|
|| 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);
|
RedkaleClassLoader.putReflectionMethod(serviceTypeOrImplClass.getName(), method);
|
||||||
continue;
|
continue;
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ import java.util.concurrent.TimeUnit;
|
|||||||
*/
|
*/
|
||||||
@Target({ElementType.METHOD})
|
@Target({ElementType.METHOD})
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface Scheduling {
|
public @interface Scheduled {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 名称
|
* 名称
|
||||||
@@ -31,14 +31,14 @@ import org.redkale.annotation.Nullable;
|
|||||||
import org.redkale.annotation.Resource;
|
import org.redkale.annotation.Resource;
|
||||||
import org.redkale.annotation.ResourceType;
|
import org.redkale.annotation.ResourceType;
|
||||||
import org.redkale.boot.Application;
|
import org.redkale.boot.Application;
|
||||||
import org.redkale.schedule.ScheduleManager;
|
|
||||||
import org.redkale.schedule.Scheduling;
|
|
||||||
import org.redkale.service.Local;
|
import org.redkale.service.Local;
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
import org.redkale.util.AnyValue;
|
import org.redkale.util.AnyValue;
|
||||||
import org.redkale.util.RedkaleClassLoader;
|
import org.redkale.util.RedkaleClassLoader;
|
||||||
import org.redkale.util.RedkaleException;
|
import org.redkale.util.RedkaleException;
|
||||||
import org.redkale.util.Utility;
|
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);
|
WeakReference ref = new WeakReference(service);
|
||||||
do {
|
do {
|
||||||
for (final Method method : clazz.getDeclaredMethods()) {
|
for (final Method method : clazz.getDeclaredMethods()) {
|
||||||
if (method.getAnnotation(Scheduling.class) == null) {
|
if (method.getAnnotation(Scheduled.class) == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (tasks.containsKey(method.getName())) {
|
if (tasks.containsKey(method.getName())) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (method.getParameterCount() > 0) {
|
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);
|
ScheduledTask task = schedule(ref, method);
|
||||||
if (task == null) {
|
if (task == null) {
|
||||||
@@ -185,7 +185,7 @@ public class ScheduleManagerService implements ScheduleManager, Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected ScheduledTask schedule(WeakReference ref, Method method) {
|
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 name = getProperty(ann.name());
|
||||||
String cron = getProperty(ann.cron());
|
String cron = getProperty(ann.cron());
|
||||||
String fixedDelay = getProperty(ann.fixedDelay());
|
String fixedDelay = getProperty(ann.fixedDelay());
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.redkale.test.schedule;
|
package org.redkale.test.schedule;
|
||||||
|
|
||||||
import org.redkale.schedule.Scheduling;
|
|
||||||
import org.redkale.service.Service;
|
import org.redkale.service.Service;
|
||||||
import org.redkale.util.Times;
|
import org.redkale.util.Times;
|
||||||
|
import org.redkale.schedule.Scheduled;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -13,18 +13,18 @@ import org.redkale.util.Times;
|
|||||||
*/
|
*/
|
||||||
public class ScheduleService implements Service {
|
public class ScheduleService implements Service {
|
||||||
|
|
||||||
@Scheduling(cron = "0/1 * * * * ?")
|
@Scheduled(cron = "0/1 * * * * ?")
|
||||||
public void task1() {
|
public void task1() {
|
||||||
System.out.println(Times.nowMillis() + "每秒-----------执行task1");
|
System.out.println(Times.nowMillis() + "每秒-----------执行task1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduling(cron = "0/1 * * * * ?")
|
@Scheduled(cron = "0/1 * * * * ?")
|
||||||
public String task2() {
|
public String task2() {
|
||||||
System.out.println(Times.nowMillis() + "每秒*****执行task2");
|
System.out.println(Times.nowMillis() + "每秒*****执行task2");
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Scheduling(cron = "0/1 * * * * ?")
|
@Scheduled(cron = "0/1 * * * * ?")
|
||||||
private void task3() {
|
private void task3() {
|
||||||
System.out.println(Times.nowMillis() + "每秒执行task3");
|
System.out.println(Times.nowMillis() + "每秒执行task3");
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user