use of com.xxl.job.core.handler.annotation.JobHandler in project xxl-job by xuxueli.
the class XxlJobExecutor method initJobHandlerRepository.
private static void initJobHandlerRepository(ApplicationContext applicationContext) {
if (applicationContext == null) {
return;
}
// init job handler action
Map<String, Object> serviceBeanMap = applicationContext.getBeansWithAnnotation(JobHandler.class);
if (serviceBeanMap != null && serviceBeanMap.size() > 0) {
for (Object serviceBean : serviceBeanMap.values()) {
if (serviceBean instanceof IJobHandler) {
String name = serviceBean.getClass().getAnnotation(JobHandler.class).value();
IJobHandler handler = (IJobHandler) serviceBean;
if (loadJobHandler(name) != null) {
throw new RuntimeException("xxl-job jobhandler naming conflicts.");
}
registJobHandler(name, handler);
}
}
}
}
use of com.xxl.job.core.handler.annotation.JobHandler in project xxl-job by xuxueli.
the class NutzSetup method init.
@Override
public void init(NutConfig cfg) {
// regist JobHandler
String[] beanNames = cfg.getIoc().getNamesByType(IJobHandler.class);
if (beanNames == null || beanNames.length == 0) {
return;
}
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
PropertiesProxy xxlJobProp = new PropertiesProxy("xxl-job-executor.properties");
// init executor
xxlJobExecutor = new XxlJobExecutor();
xxlJobExecutor.setAdminAddresses(xxlJobProp.get("xxl.job.admin.addresses"));
xxlJobExecutor.setAppName(xxlJobProp.get("xxl.job.executor.appname"));
xxlJobExecutor.setIp(xxlJobProp.get("xxl.job.executor.ip"));
xxlJobExecutor.setPort(xxlJobProp.getInt("xxl.job.executor.port"));
xxlJobExecutor.setAccessToken(xxlJobProp.get("xxl.job.accessToken"));
xxlJobExecutor.setLogPath(xxlJobProp.get("xxl.job.executor.logpath"));
xxlJobExecutor.setLogRetentionDays(xxlJobProp.getInt("xxl.job.executor.logretentiondays"));
// start executor
try {
xxlJobExecutor.start();
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
use of com.xxl.job.core.handler.annotation.JobHandler in project nutzboot by nutzam.
the class XxlJobStarter method start.
public void start() throws Exception {
// 从ioc容器中找出所有实现了IJobHandler接口的对象,注册到XxlJobExecutor
for (IJobHandler jobHandler : appContext.getBeans(IJobHandler.class)) {
// 看看有没有@JobHandler注解
JobHandler annoJobHandler = jobHandler.getClass().getAnnotation(JobHandler.class);
// 得到jobHandlerName
String jobHandlerName = jobHandler.getClass().getSimpleName();
if (annoJobHandler != null && !Strings.isBlank(annoJobHandler.value()))
jobHandlerName = annoJobHandler.value();
// 注册到XxlJobExecutor上下文
XxlJobExecutor.registJobHandler(jobHandlerName, jobHandler);
}
// 获取XxlJobExecutor,从而触发XxlJobExecutor的初始化
appContext.getIoc().getByType(XxlJobExecutor.class);
}
Aggregations