use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration 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;
}
use of com.dangdang.ddframe.job.lite.config.LiteJobConfiguration in project project by Ahaochan.
the class ElasticJobRegister method init.
private void init(DefaultJobProperties defaultProperties, BaseJobProperties jobProperties) {
String beanName = jobProperties.getBeanName();
ElasticJob elasticJob = StringUtils.isEmpty(beanName) ? null : ctx.getBean(jobProperties.getBeanName(), ElasticJob.class);
Class<?> clazz = elasticJob == null ? null : elasticJob.getClass();
JobCoreConfiguration coreConfig = jobProperties.generateJobCoreConfig(defaultProperties);
JobTypeConfiguration typeConfig = jobProperties.generateJobTypeConfig(coreConfig, clazz);
LiteJobConfiguration liteConfig = jobProperties.generateLiteJobConfig(defaultProperties, typeConfig);
registerSpringJobSchedulerV2(defaultProperties, jobProperties, liteConfig, elasticJob);
}
Aggregations