forked from Linyuzai/concept
-
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
Showing
8 changed files
with
134 additions
and
0 deletions.
There are no files selected for viewing
19 changes: 19 additions & 0 deletions
19
...-job/concept-job-core/src/main/java/com/github/linyuzai/job/core/concept/AbstractJob.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,19 @@ | ||
package com.github.linyuzai.job.core.concept; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.Map; | ||
|
||
@Getter | ||
@Setter | ||
public abstract class AbstractJob implements Job { | ||
|
||
private String id; | ||
|
||
private String name; | ||
|
||
private String description; | ||
|
||
private Map<String, String> params; | ||
} |
10 changes: 10 additions & 0 deletions
10
concept-job/concept-job-core/src/main/java/com/github/linyuzai/job/core/concept/Job.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 |
---|---|---|
@@ -1,10 +1,20 @@ | ||
package com.github.linyuzai.job.core.concept; | ||
|
||
import java.util.Map; | ||
|
||
public interface Job { | ||
|
||
String getId(); | ||
|
||
String getName(); | ||
|
||
String getDescription(); | ||
|
||
Map<String, String> getParams(); | ||
|
||
Object run(Map<String, String> params) throws Throwable; | ||
|
||
default Object run() throws Throwable { | ||
return run(getParams()); | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...t-job/concept-job-core/src/main/java/com/github/linyuzai/job/core/concept/JobConcept.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 |
---|---|---|
@@ -1,4 +1,20 @@ | ||
package com.github.linyuzai.job.core.concept; | ||
|
||
public interface JobConcept { | ||
|
||
void initialize(); | ||
|
||
void destroy(); | ||
|
||
void add(Object bean); | ||
|
||
void update(Job job); | ||
|
||
void remove(String jobId); | ||
|
||
void start(String jobId); | ||
|
||
void stop(String jobId); | ||
|
||
Job get(String jobId); | ||
} |
35 changes: 35 additions & 0 deletions
35
...pt-job/concept-job-core/src/main/java/com/github/linyuzai/job/core/concept/MethodJob.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,35 @@ | ||
package com.github.linyuzai.job.core.concept; | ||
|
||
import com.github.linyuzai.job.core.context.JobContext; | ||
import com.github.linyuzai.job.core.context.JobContextImpl; | ||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Map; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class MethodJob extends AbstractJob { | ||
|
||
private final Object target; | ||
|
||
private final Method method; | ||
|
||
@Override | ||
public Object run(Map<String, String> params) throws Throwable { | ||
Class<?>[] types = method.getParameterTypes(); | ||
Object[] args = new Object[types.length]; | ||
for (int i = 0; i < types.length; i++) { | ||
Class<?> type = types[i]; | ||
if (JobContext.class.isAssignableFrom(type)) { | ||
JobContext context = new JobContextImpl(params); | ||
args[i] = context; | ||
} | ||
if (Map.class.isAssignableFrom(type)) { | ||
args[i] = params; | ||
} | ||
} | ||
return method.invoke(target, args); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
...t-job/concept-job-core/src/main/java/com/github/linyuzai/job/core/context/JobContext.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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
package com.github.linyuzai.job.core.context; | ||
|
||
import java.util.Map; | ||
|
||
public interface JobContext { | ||
|
||
Map<String, String> getParams(); | ||
} |
13 changes: 13 additions & 0 deletions
13
...b/concept-job-core/src/main/java/com/github/linyuzai/job/core/context/JobContextImpl.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,13 @@ | ||
package com.github.linyuzai.job.core.context; | ||
|
||
import lombok.Getter; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import java.util.Map; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
public class JobContextImpl implements JobContext { | ||
|
||
private final Map<String, String> params; | ||
} |
12 changes: 12 additions & 0 deletions
12
...t-job/concept-job-core/src/main/java/com/github/linyuzai/job/core/factory/JobFactory.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,12 @@ | ||
package com.github.linyuzai.job.core.factory; | ||
|
||
import java.util.Collection; | ||
|
||
import com.github.linyuzai.job.core.concept.Job; | ||
|
||
public interface JobFactory { | ||
|
||
boolean support(Object o); | ||
|
||
Collection<Job> create(Object o); | ||
} |
25 changes: 25 additions & 0 deletions
25
...concept-job-core/src/main/java/com/github/linyuzai/job/core/factory/MethodJobFactory.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,25 @@ | ||
package com.github.linyuzai.job.core.factory; | ||
|
||
import com.github.linyuzai.job.core.concept.Job; | ||
import com.github.linyuzai.job.core.concept.MethodJob; | ||
import com.github.linyuzai.job.core.context.JobContext; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
public class MethodJobFactory implements JobFactory { | ||
|
||
@Override | ||
public boolean support(Object o) { | ||
return o instanceof JobContext; | ||
} | ||
|
||
@Override | ||
public Collection<Job> create(Object o) { | ||
JobContext context = (JobContext) o; | ||
List<Job> jobs = new ArrayList<>(); | ||
jobs.add(new MethodJob(null, null)); | ||
return jobs; | ||
} | ||
} |