|
|
@ -1,8 +1,10 @@ |
|
|
|
package com.xuxueli.executor.sample.nutz.config; |
|
|
|
package com.xuxueli.executor.sample.nutz.config; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.xuxueli.executor.sample.nutz.jobhandler.CommandJobHandler; |
|
|
|
|
|
|
|
import com.xuxueli.executor.sample.nutz.jobhandler.DemoJobHandler; |
|
|
|
|
|
|
|
import com.xuxueli.executor.sample.nutz.jobhandler.HttpJobHandler; |
|
|
|
|
|
|
|
import com.xuxueli.executor.sample.nutz.jobhandler.ShardingJobHandler; |
|
|
|
import com.xxl.job.core.executor.XxlJobExecutor; |
|
|
|
import com.xxl.job.core.executor.XxlJobExecutor; |
|
|
|
import com.xxl.job.core.handler.IJobHandler; |
|
|
|
|
|
|
|
import com.xxl.job.core.handler.annotation.JobHandler; |
|
|
|
|
|
|
|
import org.nutz.ioc.impl.PropertiesProxy; |
|
|
|
import org.nutz.ioc.impl.PropertiesProxy; |
|
|
|
import org.nutz.mvc.NutConfig; |
|
|
|
import org.nutz.mvc.NutConfig; |
|
|
|
import org.nutz.mvc.Setup; |
|
|
|
import org.nutz.mvc.Setup; |
|
|
@ -16,23 +18,17 @@ import org.slf4j.LoggerFactory; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class NutzSetup implements Setup { |
|
|
|
public class NutzSetup implements Setup { |
|
|
|
private Logger logger = LoggerFactory.getLogger(NutzSetup.class); |
|
|
|
private Logger logger = LoggerFactory.getLogger(NutzSetup.class); |
|
|
|
//public static final Log logger = Logs.get();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private XxlJobExecutor xxlJobExecutor = null; |
|
|
|
private XxlJobExecutor xxlJobExecutor = null; |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void init(NutConfig cfg) { |
|
|
|
public void init(NutConfig cfg) { |
|
|
|
|
|
|
|
|
|
|
|
// regist JobHandler
|
|
|
|
// registry jobhandler
|
|
|
|
String[] beanNames = cfg.getIoc().getNamesByType(IJobHandler.class); |
|
|
|
XxlJobExecutor.registJobHandler("demoJobHandler", new DemoJobHandler()); |
|
|
|
if (beanNames==null || beanNames.length==0) { |
|
|
|
XxlJobExecutor.registJobHandler("shardingJobHandler", new ShardingJobHandler()); |
|
|
|
return; |
|
|
|
XxlJobExecutor.registJobHandler("httpJobHandler", new HttpJobHandler()); |
|
|
|
} |
|
|
|
XxlJobExecutor.registJobHandler("commandJobHandler", new CommandJobHandler()); |
|
|
|
for (String beanName : beanNames) { |
|
|
|
|
|
|
|
IJobHandler jobHandler = cfg.getIoc().get(IJobHandler.class, beanName); |
|
|
|
|
|
|
|
String name = jobHandler.getClass().getAnnotation(JobHandler.class).value(); |
|
|
|
|
|
|
|
XxlJobExecutor.registJobHandler(name, jobHandler); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// load executor prop
|
|
|
|
// load executor prop
|
|
|
|
PropertiesProxy xxlJobProp = new PropertiesProxy("xxl-job-executor.properties"); |
|
|
|
PropertiesProxy xxlJobProp = new PropertiesProxy("xxl-job-executor.properties"); |
|
|
|