forked from lets-blade/blade
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6e50421
commit c35599d
Showing
14 changed files
with
1,926 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.blade.task; | ||
|
||
import com.blade.task.cron.CronExpression; | ||
import lombok.Setter; | ||
|
||
import java.util.concurrent.ScheduledFuture; | ||
|
||
/** | ||
* @author biezhi | ||
* @date 2018/4/9 | ||
*/ | ||
public class TaskContext { | ||
|
||
@Setter | ||
private ScheduledFuture<?> future; | ||
|
||
public void stop() { | ||
if (null != future) { | ||
future.cancel(true); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.blade.task; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author biezhi | ||
* @date 2018/4/9 | ||
*/ | ||
public final class TaskManager { | ||
|
||
private List<TaskStruct> taskStructs; | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.blade.task; | ||
|
||
import com.blade.task.annotation.Cron; | ||
import lombok.Data; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* @author biezhi | ||
* @date 2018/4/9 | ||
*/ | ||
@Data | ||
public class TaskStruct { | ||
|
||
private Cron cron; | ||
private Method method; | ||
private Class<?> type; | ||
private boolean isRunning; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.blade.task.annotation; | ||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Cron expression | ||
* | ||
* @author biezhi | ||
* @date 2018/4/9 | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.METHOD}) | ||
public @interface Cron { | ||
|
||
/** | ||
* cron expression | ||
* | ||
* @return | ||
*/ | ||
String value(); | ||
|
||
/** | ||
* Delay execution, unit millisecond, start the task by default. | ||
* | ||
* @return | ||
*/ | ||
long delay() default 0; | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/blade/task/cron/CronExecutorService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.blade.task.cron; | ||
|
||
import com.blade.task.TaskContext; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.ScheduledFuture; | ||
|
||
/** | ||
* Executor service that schedules a runnable task for execution via a cron expression. | ||
* | ||
* @author Paul Ferraro | ||
*/ | ||
public interface CronExecutorService extends ExecutorService { | ||
|
||
/** | ||
* Schedules the specified task to execute according to the specified cron expression. | ||
* | ||
* @param task the Runnable task to schedule | ||
* @param expression a cron expression | ||
*/ | ||
ScheduledFuture<?> schedule(Runnable task, CronExpression expression, long delay); | ||
|
||
// ScheduledFuture<?> schedule(Runnable task, TaskContext taskContext); | ||
|
||
default ScheduledFuture<?> schedule(Runnable task, CronExpression expression) { | ||
return this.schedule(task, expression, 0L); | ||
} | ||
|
||
} |
Oops, something went wrong.