parent
a1d4f1aeda
commit
ca2ab5cfe0
@ -0,0 +1,87 @@
|
|||||||
|
package com.xxl.job.core.executor.impl;
|
||||||
|
|
||||||
|
import com.xxl.job.core.executor.XxlJobExecutor;
|
||||||
|
import com.xxl.job.core.glue.GlueFactory;
|
||||||
|
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 org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xxl-job executor (for solon)
|
||||||
|
*
|
||||||
|
* @author noear 2021/5/22 created
|
||||||
|
*/
|
||||||
|
public class XxlJobSolonExecutor extends XxlJobExecutor implements Plugin, BeanExtractor<XxlJob> {
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(XxlJobSolonExecutor.class);
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(SolonApp app) {
|
||||||
|
// init JobHandler Repository (for method)
|
||||||
|
Aop.context().beanExtractorAdd(XxlJob.class, this);
|
||||||
|
|
||||||
|
// refresh GlueFactory
|
||||||
|
GlueFactory.refreshInstance(2);
|
||||||
|
|
||||||
|
// super start
|
||||||
|
try {
|
||||||
|
super.start();
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// destroy
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
super.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@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 (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
|
||||||
|
registJobHandler(name, new MethodJobHandler(wrap.raw(), method, initMethod, destroyMethod));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
package com.xxl.job.core.glue.impl;
|
||||||
|
|
||||||
|
import com.xxl.job.core.glue.GlueFactory;
|
||||||
|
import org.noear.solon.Solon;
|
||||||
|
import org.noear.solon.core.Aop;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author noear 2021/5/22 created
|
||||||
|
*/
|
||||||
|
public class SolonGlueFactory extends GlueFactory {
|
||||||
|
private static Logger logger = LoggerFactory.getLogger(SolonGlueFactory.class);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* inject action of solon
|
||||||
|
* @param instance
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void injectService(Object instance){
|
||||||
|
if (instance==null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Solon.global() == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Aop.inject(instance);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package com.xxl.job.executor;
|
||||||
|
|
||||||
|
import org.noear.solon.Solon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author xuxueli 2018-10-28 00:38:13
|
||||||
|
* @author noear 2021/5/22 created
|
||||||
|
*/
|
||||||
|
public class XxlJobExecutorApp {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Solon.start(XxlJobExecutorApp.class, args);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
package com.xxl.job.executor.config;
|
||||||
|
|
||||||
|
import com.xxl.job.core.executor.impl.XxlJobSolonExecutor;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* xxl-job config
|
||||||
|
*
|
||||||
|
* @author xuxueli 2017-04-28
|
||||||
|
* @author noear 2021/5/22 created
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
public class XxlJobConfig {
|
||||||
|
private Logger logger = LoggerFactory.getLogger(XxlJobConfig.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,14 @@
|
|||||||
|
package com.xxl.job.executor.controller;//package com.xxl.job.executor.mvc.controller;
|
||||||
|
|
||||||
|
//import org.noear.solon.annotation.Controller;
|
||||||
|
//import org.noear.solon.annotation.Mapping;
|
||||||
|
//
|
||||||
|
//@Controller
|
||||||
|
//public class IndexController {
|
||||||
|
//
|
||||||
|
// @Mapping("/")
|
||||||
|
// public String index() {
|
||||||
|
// return "xxl job executor running.";
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//}
|
@ -0,0 +1,21 @@
|
|||||||
|
# web port
|
||||||
|
server.port=8081
|
||||||
|
|
||||||
|
|
||||||
|
### xxl-job admin address list, such as "http://address" or "http://address01,http://address02"
|
||||||
|
xxl.job.admin.addresses=http://127.0.0.1:8080/xxl-job-admin
|
||||||
|
|
||||||
|
### xxl-job, access token
|
||||||
|
xxl.job.accessToken=
|
||||||
|
|
||||||
|
### xxl-job executor appname
|
||||||
|
xxl.job.executor.appname=xxl-job-executor-sample
|
||||||
|
### xxl-job executor registry-address: default use address to registry , otherwise use ip:port if address is null
|
||||||
|
xxl.job.executor.address=
|
||||||
|
### xxl-job executor server-info
|
||||||
|
xxl.job.executor.ip=
|
||||||
|
xxl.job.executor.port=9999
|
||||||
|
### xxl-job executor log-path
|
||||||
|
xxl.job.executor.logpath=/data/applogs/xxl-job/jobhandler
|
||||||
|
### xxl-job executor log-retention-days
|
||||||
|
xxl.job.executor.logretentiondays=30
|
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<configuration debug="false" scan="true" scanPeriod="1 seconds">
|
||||||
|
|
||||||
|
<contextName>logback</contextName>
|
||||||
|
<property name="log.path" value="/data/applogs/xxl-job/xxl-job-executor-sample-solon.log"/>
|
||||||
|
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{HH:mm:ss.SSS} %contextName [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<!-- <appender name="file" class="ch.qos.logback.core.rolling.RollingFileAppender">-->
|
||||||
|
<!-- <file>${log.path}</file>-->
|
||||||
|
<!-- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">-->
|
||||||
|
<!-- <fileNamePattern>${log.path}.%d{yyyy-MM-dd}.zip</fileNamePattern>-->
|
||||||
|
<!-- </rollingPolicy>-->
|
||||||
|
<!-- <encoder>-->
|
||||||
|
<!-- <pattern>%date %level [%thread] %logger{36} [%file : %line] %msg%n-->
|
||||||
|
<!-- </pattern>-->
|
||||||
|
<!-- </encoder>-->
|
||||||
|
<!-- </appender>-->
|
||||||
|
|
||||||
|
<root level="info">
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
<!-- <appender-ref ref="file"/>-->
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
Loading…
Reference in new issue