List of usage examples for org.springframework.batch.core.configuration.annotation JobBuilderFactory JobBuilderFactory
public JobBuilderFactory(JobRepository jobRepository)
From source file:de.langmi.spring.batch.examples.basics.purejava.PureJavaJobFactory.java
public static Job createJob(JobRepository jobRepository, PlatformTransactionManager transactionManager) { JobBuilderFactory jobBuilderFactory = new JobBuilderFactory(jobRepository); StepBuilderFactory stepBuilderFactory = new StepBuilderFactory(jobRepository, transactionManager); Step step = stepBuilderFactory.get("step1").tasklet(new Tasklet() { @Override//from ww w . ja va 2s . c o m public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { // why not using println? because it makes testing harder, *nix and // windows think different about new line as in \n vs \r\n System.out.print("Hello World!"); // we want the step to stop here, the other status // RepeatStatus.CONTINUABLE would start an endless loop return RepeatStatus.FINISHED; } }).build(); return jobBuilderFactory.get("job1").start(step).build(); }
From source file:org.duracloud.snapshot.service.impl.RestoreJobBuilder.java
@Override public Job buildJob(Restoration restoration, SnapshotJobManagerConfig jobManagerConfig) throws SnapshotException { Job job;// www. j a v a2 s . c o m try { DuracloudEndPointConfig destination = restoration.getDestination(); String destinationSpaceId = destination.getSpaceId(); String restoreId = restoration.getRestorationId(); StoreClientUtil clientUtil = new StoreClientUtil(); ContentStore contentStore = clientUtil.createContentStore(destination.getHost(), destination.getPort(), SnapshotServiceConstants.DURASTORE_CONTEXT, jobManagerConfig.getDuracloudUsername(), jobManagerConfig.getDuracloudPassword(), destination.getStoreId()); Step restoreContentStep = buildRestoreContentStep(restoreId, destinationSpaceId, contentStore, jobManagerConfig); Step restorePropertiesStep = buildRestoreContentPropertiesStep(restoreId, destinationSpaceId, contentStore, jobManagerConfig); JobBuilderFactory jobBuilderFactory = new JobBuilderFactory(jobRepository); JobBuilder jobBuilder = jobBuilderFactory.get(SnapshotServiceConstants.RESTORE_JOB_NAME); SimpleJobBuilder simpleJobBuilder = jobBuilder.start(restoreContentStep).next(restorePropertiesStep); simpleJobBuilder.listener(jobListener); job = simpleJobBuilder.build(); log.debug("build job {}", job); } catch (Exception e) { log.error("Error creating job: {}", e.getMessage(), e); throw new SnapshotException(e.getMessage(), e); } return job; }
From source file:org.duracloud.snapshot.service.impl.SnapshotJobBuilder.java
@Override public Job buildJob(Snapshot snapshot, SnapshotJobManagerConfig config) throws SnapshotException { Job job;//from w w w . j ava2 s .c om try { DuracloudEndPointConfig source = snapshot.getSource(); StoreClientUtil clientUtil = new StoreClientUtil(); ContentStore contentStore = clientUtil.createContentStore(source.getHost(), source.getPort(), SnapshotServiceConstants.DURASTORE_CONTEXT, config.getDuracloudUsername(), config.getDuracloudPassword(), source.getStoreId()); List<String> spaces = new ArrayList<>(); spaces.add(source.getSpaceId()); RetrievalSource retrievalSource = new DuraStoreStitchingRetrievalSource(contentStore, spaces, false); ItemReader<ContentItem> itemReader = new SpaceItemReader(retrievalSource); File contentDir = new File( ContentDirUtils.getDestinationPath(snapshot.getName(), config.getContentRootDir())); if (!contentDir.exists()) { contentDir.mkdirs(); } File workDir = config.getWorkDir(); OutputWriter outputWriter = new CSVFileOutputWriter(workDir); BufferedWriter propsWriter = createWriter(contentDir, SnapshotServiceConstants.CONTENT_PROPERTIES_JSON_FILENAME); BufferedWriter md5Writer = createWriter(contentDir, MANIFEST_MD5_TXT_FILE_NAME); BufferedWriter sha256Writer = createWriter(contentDir, MANIFEST_SHA256_TXT_FILE_NAME); ItemWriter itemWriter = new SpaceItemWriter(snapshot, retrievalSource, contentDir, outputWriter, propsWriter, md5Writer, sha256Writer, snapshotManager); SimpleStepFactoryBean<ContentItem, File> stepFactory = new SimpleStepFactoryBean<>(); stepFactory.setJobRepository(jobRepository); stepFactory.setTransactionManager(transactionManager); stepFactory.setBeanName("step1"); stepFactory.setItemReader(itemReader); stepFactory.setItemWriter(itemWriter); stepFactory.setCommitInterval(1); stepFactory.setThrottleLimit(20); stepFactory.setTaskExecutor(taskExecutor); Step step = (Step) stepFactory.getObject(); JobBuilderFactory jobBuilderFactory = new JobBuilderFactory(jobRepository); JobBuilder jobBuilder = jobBuilderFactory.get(SnapshotServiceConstants.SNAPSHOT_JOB_NAME); SimpleJobBuilder simpleJobBuilder = jobBuilder.start(step); simpleJobBuilder.listener(jobListener); job = simpleJobBuilder.build(); log.debug("build job {}", job); } catch (Exception e) { log.error("Error creating job: {}", e.getMessage(), e); throw new SnapshotException(e.getMessage(), e); } return job; }