parent
ca2ab5cfe0
commit
525cf9239a
@ -0,0 +1,57 @@
|
|||||||
|
package com.xxl.job.core.executor.impl;
|
||||||
|
|
||||||
|
import org.noear.solon.annotation.Bean;
|
||||||
|
import org.noear.solon.annotation.Configuration;
|
||||||
|
import org.noear.solon.annotation.Inject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author noear 2021/5/22 created
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class XxlJobSolonAutoConfig {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(XxlJobSolonAutoConfig.class);
|
||||||
|
|
||||||
|
@Inject("${xxl.job.admin.addresses}")
|
||||||
|
private String adminAddresses;
|
||||||
|
|
||||||
|
@Inject("${xxl.job.accessToken}")
|
||||||
|
private String accessToken;
|
||||||
|
|
||||||
|
@Inject("${xxl.job.executor.appname}")
|
||||||
|
private String appname;
|
||||||
|
|
||||||
|
@Inject("${xxl.job.executor.address}")
|
||||||
|
private String address;
|
||||||
|
|
||||||
|
@Inject("${xxl.job.executor.ip}")
|
||||||
|
private String ip;
|
||||||
|
|
||||||
|
@Inject("${xxl.job.executor.port}")
|
||||||
|
private int port;
|
||||||
|
|
||||||
|
@Inject("${xxl.job.executor.logpath}")
|
||||||
|
private String logPath;
|
||||||
|
|
||||||
|
@Inject("${xxl.job.executor.logretentiondays}")
|
||||||
|
private int logRetentionDays;
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
public XxlJobSolonExecutor xxlJobExecutor() {
|
||||||
|
logger.info(">>>>>>>>>>> xxl-job config init.");
|
||||||
|
|
||||||
|
XxlJobSolonExecutor executor = new XxlJobSolonExecutor();
|
||||||
|
|
||||||
|
executor.setAdminAddresses(adminAddresses);
|
||||||
|
executor.setAppname(appname);
|
||||||
|
executor.setAddress(address);
|
||||||
|
executor.setIp(ip);
|
||||||
|
executor.setPort(port);
|
||||||
|
executor.setAccessToken(accessToken);
|
||||||
|
executor.setLogPath(logPath);
|
||||||
|
executor.setLogRetentionDays(logRetentionDays);
|
||||||
|
|
||||||
|
return executor;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,72 @@
|
|||||||
|
package com.xxl.job.core.executor.impl;
|
||||||
|
|
||||||
|
import com.xxl.job.core.executor.XxlJobExecutor;
|
||||||
|
import com.xxl.job.core.handler.annotation.XxlJob;
|
||||||
|
import com.xxl.job.core.handler.impl.MethodJobHandler;
|
||||||
|
import org.noear.solon.SolonApp;
|
||||||
|
import org.noear.solon.core.Aop;
|
||||||
|
import org.noear.solon.core.BeanExtractor;
|
||||||
|
import org.noear.solon.core.BeanWrap;
|
||||||
|
import org.noear.solon.core.Plugin;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author noear 2021/5/22 created
|
||||||
|
*/
|
||||||
|
public class XxlJobSolonPlugin implements Plugin, BeanExtractor<XxlJob> {
|
||||||
|
@Override
|
||||||
|
public void start(SolonApp app) {
|
||||||
|
Aop.context().beanExtractorAdd(XxlJob.class, this);
|
||||||
|
Aop.context().beanMake(XxlJobSolonAutoConfig.class);
|
||||||
|
|
||||||
|
XxlJobSolonExecutor executor = Aop.get(XxlJobSolonExecutor.class);
|
||||||
|
|
||||||
|
Aop.beanOnloaded(() -> {
|
||||||
|
try {
|
||||||
|
executor.start();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doExtract(BeanWrap wrap, Method method, XxlJob anno) {
|
||||||
|
String name = anno.value();
|
||||||
|
|
||||||
|
if (name.trim().length() == 0) {
|
||||||
|
throw new RuntimeException("xxl-job method-jobhandler name invalid, for[" + wrap.clz() + "#" + method.getName() + "] .");
|
||||||
|
}
|
||||||
|
if (XxlJobExecutor.loadJobHandler(name) != null) {
|
||||||
|
throw new RuntimeException("xxl-job jobhandler[" + name + "] naming conflicts.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
method.setAccessible(true);
|
||||||
|
|
||||||
|
// init and destory
|
||||||
|
Method initMethod = null;
|
||||||
|
Method destroyMethod = null;
|
||||||
|
|
||||||
|
if (anno.init().trim().length() > 0) {
|
||||||
|
try {
|
||||||
|
initMethod = wrap.clz().getDeclaredMethod(anno.init());
|
||||||
|
initMethod.setAccessible(true);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException("xxl-job method-jobhandler initMethod invalid, for[" + wrap.clz() + "#" + method.getName() + "] .");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (anno.destroy().trim().length() > 0) {
|
||||||
|
try {
|
||||||
|
destroyMethod = wrap.clz().getDeclaredMethod(anno.destroy());
|
||||||
|
destroyMethod.setAccessible(true);
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
throw new RuntimeException("xxl-job method-jobhandler destroyMethod invalid, for[" + wrap.clz() + "#" + method.getName() + "] .");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// registry jobhandler
|
||||||
|
XxlJobExecutor.registJobHandler(name, new MethodJobHandler(wrap.raw(), method, initMethod, destroyMethod));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
solon.plugin=com.xxl.job.core.executor.impl.XxlJobSolonPlugin
|
Loading…
Reference in new issue