use of com.dangdang.elasticjob.lite.annotation.ElasticSimpleJob in project LinkAgent by shulieTech.
the class JobExecutorFactoryGetJobExecutorInterceptor method processWithoutSpring.
private boolean processWithoutSpring(ShadowJob shadowJob) {
boolean ok = false;
Map<String, SimpleJob> map = PradarSpringUtil.getBeanFactory().getBeansOfType(SimpleJob.class);
for (Map.Entry<String, SimpleJob> entry : map.entrySet()) {
SimpleJob simpleJob = entry.getValue();
if (!simpleJob.getClass().getName().equals(shadowJob.getClassName())) {
continue;
}
ZookeeperRegistryCenter regCenter = getRegisterConter();
Object originJob = simpleJob;
ElasticSimpleJob elasticSimpleJobAnnotation = simpleJob.getClass().getAnnotation(ElasticSimpleJob.class);
Class ptJobClass = PtElasticJobSimpleJob.class;
String cron = StringUtils.defaultIfBlank(elasticSimpleJobAnnotation.cron(), elasticSimpleJobAnnotation.value());
SimpleJobConfiguration simpleJobConfiguration = new SimpleJobConfiguration(JobCoreConfiguration.newBuilder(ptJobClass.getName(), cron, elasticSimpleJobAnnotation.shardingTotalCount()).shardingItemParameters(elasticSimpleJobAnnotation.shardingItemParameters()).build(), simpleJob.getClass().getCanonicalName());
LiteJobConfiguration liteJobConfiguration = LiteJobConfiguration.newBuilder(simpleJobConfiguration).overwrite(true).build();
DefaultListableBeanFactory defaultListableBeanFactory = PradarSpringUtil.getBeanFactory();
BeanDefinitionBuilder beanSimple = BeanDefinitionBuilder.rootBeanDefinition(ptJobClass);
defaultListableBeanFactory.registerBeanDefinition(ptJobClass.getSimpleName() + originJob.getClass().getName(), beanSimple.getBeanDefinition());
ElasticJob ptJob = (ElasticJob) PradarSpringUtil.getBeanFactory().getBean(ptJobClass.getSimpleName() + originJob.getClass().getName());
String dataSourceRef = elasticSimpleJobAnnotation.dataSource();
if (StringUtils.isNotBlank(dataSourceRef)) {
if (!PradarSpringUtil.getBeanFactory().containsBean(dataSourceRef)) {
throw new RuntimeException("not exist datasource [" + dataSourceRef + "] !");
}
DataSource dataSource = (DataSource) PradarSpringUtil.getBeanFactory().getBean(dataSourceRef);
JobEventRdbConfiguration jobEventRdbConfiguration = new JobEventRdbConfiguration(dataSource);
SpringJobScheduler jobScheduler = new SpringJobScheduler(ptJob, regCenter, liteJobConfiguration, jobEventRdbConfiguration);
jobScheduler.init();
if (originJob instanceof SimpleJob) {
((PtElasticJobSimpleJob) Reflect.on(jobScheduler).get("elasticJob")).setSimpleJob((SimpleJob) originJob);
}
ok = true;
break;
} else {
SpringJobScheduler jobScheduler = new SpringJobScheduler(ptJob, regCenter, liteJobConfiguration);
jobScheduler.init();
if (originJob instanceof SimpleJob) {
((PtElasticJobSimpleJob) Reflect.on(jobScheduler).get("elasticJob")).setSimpleJob((SimpleJob) originJob);
}
ok = true;
break;
}
}
return ok;
}
Aggregations