[New] added StrolchJobsHandler.register(StrolchJob) method
This commit is contained in:
parent
5736cead97
commit
ba13b981c1
|
@ -38,8 +38,7 @@ public class StrolchJobsHandler extends StrolchComponent {
|
||||||
super.initialize(configuration);
|
super.initialize(configuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
public StrolchJob registerAndScheduleJob(Class<? extends StrolchJob> strolchJobClass) {
|
private StrolchJob instantiateStrolchJob(Class<? extends StrolchJob> strolchJobClass) {
|
||||||
|
|
||||||
StrolchJob strolchJob;
|
StrolchJob strolchJob;
|
||||||
try {
|
try {
|
||||||
Constructor<? extends StrolchJob> constructor = strolchJobClass.getConstructor(StrolchAgent.class);
|
Constructor<? extends StrolchJob> constructor = strolchJobClass.getConstructor(StrolchAgent.class);
|
||||||
|
@ -47,13 +46,22 @@ public class StrolchJobsHandler extends StrolchComponent {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new IllegalArgumentException("Failed to instantiate class " + strolchJobClass.getName(), e);
|
throw new IllegalArgumentException("Failed to instantiate class " + strolchJobClass.getName(), e);
|
||||||
}
|
}
|
||||||
|
return strolchJob;
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrolchJob registerAndScheduleJob(Class<? extends StrolchJob> strolchJobClass) {
|
||||||
|
return register(instantiateStrolchJob(strolchJobClass)).schedule();
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrolchJob register(Class<? extends StrolchJob> strolchJobClass) {
|
||||||
|
return register(instantiateStrolchJob(strolchJobClass));
|
||||||
|
}
|
||||||
|
|
||||||
|
public StrolchJob register(StrolchJob strolchJob) {
|
||||||
if (this.jobs.containsKey(strolchJob.getName()))
|
if (this.jobs.containsKey(strolchJob.getName()))
|
||||||
throw new IllegalArgumentException("Job " + strolchJob.getName() + " is already registered!");
|
throw new IllegalArgumentException("Job " + strolchJob.getName() + " is already registered!");
|
||||||
|
|
||||||
strolchJob.schedule();
|
|
||||||
|
|
||||||
this.jobs.put(strolchJob.getName(), strolchJob);
|
this.jobs.put(strolchJob.getName(), strolchJob);
|
||||||
|
|
||||||
return strolchJob;
|
return strolchJob;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue