Example usage for org.springframework.batch.core.step.factory SimpleStepFactoryBean setCommitInterval

List of usage examples for org.springframework.batch.core.step.factory SimpleStepFactoryBean setCommitInterval

Introduction

In this page you can find the example usage for org.springframework.batch.core.step.factory SimpleStepFactoryBean setCommitInterval.

Prototype

public void setCommitInterval(int commitInterval) 

Source Link

Document

Set the commit interval.

Usage

From source file:org.duracloud.snapshot.service.impl.RestoreJobBuilder.java

/**
 * @param restoration /*ww  w  . j  a v  a  2s  .  c  om*/
 * @param jobManagerConfig 
 * @param reader
 * @param writer
 * @return
 * @throws Exception
 */
private Step buildRestoreContentStep(String restorationId, String destinationSpaceId, ContentStore contentStore,
        SnapshotJobManagerConfig jobManagerConfig) throws Exception {

    SyncEndpoint endpoint = new DuraStoreSyncEndpoint(contentStore, jobManagerConfig.getDuracloudUsername(),
            destinationSpaceId, false, false);

    File watchDir = new File(ContentDirUtils.getSourcePath(restorationId, jobManagerConfig.getContentRootDir())
            + File.separator + "data");

    if (!watchDir.exists()) {
        throw new RuntimeException("The content directory for the restored snapshot "
                + "does not exist in bridge storage: missing watchDir: " + watchDir.getAbsolutePath());
    }

    FileSystemReader reader = new FileSystemReader(watchDir);

    SyncWriter writer = new SyncWriter(restorationId, watchDir, endpoint, contentStore, destinationSpaceId,
            restoreManager);

    SimpleStepFactoryBean<File, File> stepFactory = new SimpleStepFactoryBean<>();
    stepFactory.setJobRepository(jobRepository);
    stepFactory.setTransactionManager(transactionManager);
    stepFactory.setBeanName("restoreContentStep");
    stepFactory.setItemReader(reader);
    stepFactory.setItemWriter(writer);
    stepFactory.setCommitInterval(1);
    stepFactory.setThrottleLimit(20);
    stepFactory.setTaskExecutor(taskExecutor);
    stepFactory.setListeners(new StepListener[] { writer });
    return stepFactory.getObject();
}

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  . ja  v a 2s.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;
}

From source file:org.duracloud.snapshot.service.impl.RestoreJobBuilder.java

/**
 * @param jobManagerConfig //w  w w  . j  a  v  a2s . c o m
 * @param restoration 
 * @return
 */
private Step buildRestoreContentPropertiesStep(String restorationId, String destinationSpaceId,
        ContentStore contentStore, SnapshotJobManagerConfig jobManagerConfig) throws Exception {

    File contentPropertiesJsonFile = new File(
            ContentDirUtils.getSourcePath(restorationId, jobManagerConfig.getContentRootDir()),
            SnapshotServiceConstants.CONTENT_PROPERTIES_JSON_FILENAME);

    if (!contentPropertiesJsonFile.exists()) {
        throw new RuntimeException("The restored content properties file is missing : "
                + contentPropertiesJsonFile.getAbsolutePath());
    }

    ContentPropertiesFileReader reader = new ContentPropertiesFileReader(contentPropertiesJsonFile);

    ContentPropertiesWriter writer = new ContentPropertiesWriter(contentStore, destinationSpaceId);

    SimpleStepFactoryBean<ContentProperties, ContentProperties> stepFactory = new SimpleStepFactoryBean<ContentProperties, ContentProperties>();
    stepFactory.setJobRepository(jobRepository);
    stepFactory.setTransactionManager(transactionManager);
    stepFactory.setBeanName("restoreContentPropertiesStep");
    stepFactory.setItemReader(reader);
    stepFactory.setItemWriter(writer);
    stepFactory.setCommitInterval(1);
    stepFactory.setThrottleLimit(20);
    stepFactory.setTaskExecutor(taskExecutor);
    stepFactory.setListeners(new StepListener[] { writer });
    return stepFactory.getObject();
}