Cacheing
This commit is contained in:
@@ -25,7 +25,7 @@ import java.util.concurrent.TimeUnit;
|
||||
@Documented
|
||||
@Target(METHOD)
|
||||
@Retention(RUNTIME)
|
||||
public @interface Cached {
|
||||
public @interface Cacheing {
|
||||
|
||||
/**
|
||||
* 缓存的key,支持参数动态组合,比如"key_#{id}"
|
||||
29
src/main/java/org/redkale/annotation/Locking.java
Normal file
29
src/main/java/org/redkale/annotation/Locking.java
Normal 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 {
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import java.util.concurrent.TimeUnit;
|
||||
*/
|
||||
@Target({ElementType.METHOD})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
public @interface Scheduled {
|
||||
public @interface Scheduling {
|
||||
|
||||
/**
|
||||
* 名称
|
||||
@@ -74,11 +74,11 @@ public abstract class Sncp {
|
||||
|
||||
private String methodName;
|
||||
|
||||
private Scheduled schedule;
|
||||
private Scheduling schedule;
|
||||
|
||||
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(methodName);
|
||||
Objects.requireNonNull(schedule);
|
||||
@@ -97,7 +97,7 @@ public abstract class Sncp {
|
||||
return methodName;
|
||||
}
|
||||
|
||||
public Scheduled getSchedule() {
|
||||
public Scheduling getSchedule() {
|
||||
return schedule;
|
||||
}
|
||||
|
||||
@@ -133,10 +133,10 @@ public abstract class Sncp {
|
||||
if (method.isSynthetic()) {
|
||||
continue;
|
||||
}
|
||||
if (method.getAnnotation(Scheduled.class) != null) {
|
||||
if (method.getAnnotation(Scheduling.class) != null) {
|
||||
if (Modifier.isStatic(method.getModifiers())
|
||||
|| 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);
|
||||
continue;
|
||||
|
||||
@@ -26,10 +26,10 @@ import java.util.function.UnaryOperator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import org.redkale.annotation.Nullable;
|
||||
import org.redkale.annotation.Scheduled;
|
||||
import org.redkale.util.RedkaleClassLoader;
|
||||
import org.redkale.util.RedkaleException;
|
||||
import org.redkale.util.Utility;
|
||||
import org.redkale.annotation.Scheduling;
|
||||
|
||||
/**
|
||||
* 定时任务工厂
|
||||
@@ -106,14 +106,14 @@ public class ScheduledFactory {
|
||||
WeakReference ref = new WeakReference(service);
|
||||
do {
|
||||
for (final Method method : clazz.getDeclaredMethods()) {
|
||||
if (method.getAnnotation(Scheduled.class) == null) {
|
||||
if (method.getAnnotation(Scheduling.class) == null) {
|
||||
continue;
|
||||
}
|
||||
if (tasks.containsKey(method.getName())) {
|
||||
continue;
|
||||
}
|
||||
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);
|
||||
if (task == null) {
|
||||
@@ -134,7 +134,7 @@ public class ScheduledFactory {
|
||||
}
|
||||
|
||||
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 cron = getProperty(ann.cron());
|
||||
String fixedDelay = getProperty(ann.fixedDelay());
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
*/
|
||||
package org.redkale.test.scheduling;
|
||||
|
||||
import org.redkale.annotation.Scheduled;
|
||||
import org.redkale.service.Service;
|
||||
import org.redkale.util.Times;
|
||||
import org.redkale.annotation.Scheduling;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -13,18 +13,18 @@ import org.redkale.util.Times;
|
||||
*/
|
||||
public class ScheduleService implements Service {
|
||||
|
||||
@Scheduled(cron = "0/1 * * * * ?")
|
||||
@Scheduling(cron = "0/1 * * * * ?")
|
||||
public void task1() {
|
||||
System.out.println(Times.nowMillis() + "每秒-----------执行task1");
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0/1 * * * * ?")
|
||||
@Scheduling(cron = "0/1 * * * * ?")
|
||||
public String task2() {
|
||||
System.out.println(Times.nowMillis() + "每秒*****执行task2");
|
||||
return "";
|
||||
}
|
||||
|
||||
@Scheduled(cron = "0/1 * * * * ?")
|
||||
@Scheduling(cron = "0/1 * * * * ?")
|
||||
private void task3() {
|
||||
System.out.println(Times.nowMillis() + "每秒执行task3");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user