This commit is contained in:
redkale
2023-12-09 11:12:33 +08:00
parent c2f66b61ec
commit 6d9f2ec6be
6 changed files with 44 additions and 15 deletions

View File

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

View File

@@ -0,0 +1,29 @@
/*
*
*/
package org.redkale.annotation;
import java.lang.annotation.Documented;
import static java.lang.annotation.ElementType.METHOD;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Target;
/**
* @TODO 待实现
*
* 标记在Service的锁接口, 方法有以下限制: <br>
* 1、方法返回类型不能是void
* 2、方法必须是protected/public
* 3、方法不能是final
*
* @since 2.8.0
*/
@Inherited
@Documented
@Target(METHOD)
@Retention(RUNTIME)
public @interface Locking {
}

View File

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

View File

@@ -74,11 +74,11 @@ public abstract class Sncp {
private String methodName; private String methodName;
private Scheduled schedule; private Scheduling schedule;
private Runnable task; private Runnable task;
public SchedulingEntry(Class serviceType, String methodName, Scheduled schedule, Runnable task) { public SchedulingEntry(Class serviceType, String methodName, Scheduling schedule, Runnable task) {
Objects.requireNonNull(serviceType); Objects.requireNonNull(serviceType);
Objects.requireNonNull(methodName); Objects.requireNonNull(methodName);
Objects.requireNonNull(schedule); Objects.requireNonNull(schedule);
@@ -97,7 +97,7 @@ public abstract class Sncp {
return methodName; return methodName;
} }
public Scheduled getSchedule() { public Scheduling getSchedule() {
return schedule; return schedule;
} }
@@ -133,10 +133,10 @@ public abstract class Sncp {
if (method.isSynthetic()) { if (method.isSynthetic()) {
continue; continue;
} }
if (method.getAnnotation(Scheduled.class) != null) { if (method.getAnnotation(Scheduling.class) != null) {
if (Modifier.isStatic(method.getModifiers()) if (Modifier.isStatic(method.getModifiers())
|| method.getParameterCount() > 0) { || method.getParameterCount() > 0) {
throw new SncpException(Scheduled.class.getSimpleName() + " must be on protected and non-parameter method, but on " + method); throw new SncpException(Scheduling.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;

View File

@@ -26,10 +26,10 @@ import java.util.function.UnaryOperator;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.redkale.annotation.Nullable; import org.redkale.annotation.Nullable;
import org.redkale.annotation.Scheduled;
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.annotation.Scheduling;
/** /**
* 定时任务工厂 * 定时任务工厂
@@ -106,14 +106,14 @@ public class ScheduledFactory {
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(Scheduled.class) == null) { if (method.getAnnotation(Scheduling.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("@" + Scheduled.class.getSimpleName() + " must be on non-parameter method, but on " + method); throw new RedkaleException("@" + Scheduling.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) {
@@ -134,7 +134,7 @@ public class ScheduledFactory {
} }
protected ScheduledTask schedule(WeakReference ref, Method method) { protected ScheduledTask schedule(WeakReference ref, Method method) {
Scheduled ann = method.getAnnotation(Scheduled.class); Scheduling ann = method.getAnnotation(Scheduling.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());

View File

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