Example usage for org.springframework.batch.item ExecutionContext putInt

List of usage examples for org.springframework.batch.item ExecutionContext putInt

Introduction

In this page you can find the example usage for org.springframework.batch.item ExecutionContext putInt.

Prototype

public void putInt(String key, int value) 

Source Link

Document

Adds an Integer value to the context.

Usage

From source file:org.trpr.platform.batch.impl.spring.partitioner.SimpleRangePartitioner.java

public Map<String, ExecutionContext> partition(int gridSize) {
    Map<String, ExecutionContext> map = new HashMap<String, ExecutionContext>(gridSize);
    for (int i = 0; i < gridSize; i++) {
        ExecutionContext context = new ExecutionContext();
        context.putInt(TOTAL_PARTITIIONS, gridSize);
        context.putInt(PARTITION_INDEX, i);
        map.put(PARTITION_KEY + i, context);
    }//w w w  .j ava 2  s .  c  o  m
    return map;
}

From source file:org.springframework.cloud.dataflow.server.support.StepExecutionJacksonMixInTests.java

private StepExecution getStepExecution() {
    JobExecution jobExecution = new JobExecution(1L, null, "hi");
    final StepExecution stepExecution = new StepExecution("step1", jobExecution);
    jobExecution.createStepExecution("step1");
    final ExecutionContext executionContext = stepExecution.getExecutionContext();

    executionContext.putInt("counter", 1234);
    executionContext.putDouble("myDouble", 1.123456d);
    executionContext.putLong("Josh", 4444444444L);
    executionContext.putString("awesomeString", "Yep");
    executionContext.put("hello", "world");
    executionContext.put("counter2", 9999);

    return stepExecution;
}

From source file:ru.xxlabaza.test.batch.job.RangePartitioner.java

@Override
public Map<String, ExecutionContext> partition(int gridSize) {
    long totalItems = personRepository.count();
    System.out.println("\nTotal items: " + totalItems);

    int range = (int) totalItems / gridSize;
    if (range < chunkSize) {
        throw new IllegalArgumentException();
    }/*w  w  w.jav  a 2 s  . c om*/

    return IntStream.range(0, gridSize).boxed().map(index -> {
        ExecutionContext context = new ExecutionContext();
        context.putString("name", "partition-" + index);
        context.putInt("from", index * range);
        int nextIndex = index + 1;
        int to = nextIndex * range - 1;
        if (nextIndex == gridSize) {
            to += totalItems % gridSize;
        }
        context.putInt("to", to);
        return context;
    }).map(context -> {
        System.out.format("\nCREATED PARTITION: '%s', RANGE FROM %d, TO %d\n", context.getString("name"),
                context.getInt("from"), context.getInt("to"));
        return context;
    }).collect(toMap(context -> context.getString("name"), Function.identity()));
}

From source file:com.ifeng.computing.batch.job.partitioner.RangePartitioner.java

@Override
public Map<String, ExecutionContext> partition(int gridSize) {

    Map<String, ExecutionContext> result = new HashMap<String, ExecutionContext>();

    int range = 100;
    int fromId = 81289;
    int toId = range + fromId;

    for (int i = 1; i <= gridSize; i++) {
        ExecutionContext value = new ExecutionContext();

        log.debug("\nStarting : Thread" + i);
        log.debug("fromId : " + fromId);
        log.debug("toId : " + toId);

        value.putInt("fromId", fromId);
        value.putInt("toId", toId);

        // give each thread a name, thread 1,2,3
        value.putString("name", "Thread" + i);

        result.put("partition" + i, value);

        fromId = toId + 1;//w  w  w  .j  a va2  s .  c  o  m
        toId += range;

    }

    return result;
}

From source file:com.victorjabur.springbatch.partitioner.ColumnRangePartitioner.java

/**
 * Partition a database table assuming that the data in the column specified
 * are uniformly distributed. The execution context values will have keys
 * <code>minValue</code> and <code>maxValue</code> specifying the range of
 * values to consider in each partition.
 *
 * @see Partitioner#partition(int)/*from   www  .jav a2  s.co m*/
 */
@Override
public Map<String, ExecutionContext> partition(int gridSize) {
    int min = jdbcTemplate.queryForObject("SELECT MIN(" + column + ") from " + table, Integer.class);
    int max = jdbcTemplate.queryForObject("SELECT MAX(" + column + ") from " + table, Integer.class);
    int targetSize = (max - min) / gridSize + 1;

    Map<String, ExecutionContext> result = new HashMap<String, ExecutionContext>();
    int number = 0;
    int start = min;
    int end = start + targetSize - 1;

    while (start <= max) {
        ExecutionContext value = new ExecutionContext();
        result.put("partition" + number, value);

        if (end >= max) {
            end = max;
        }
        value.putInt("minValue", start);
        value.putInt("maxValue", end);
        start += targetSize;
        end += targetSize;
        number++;
    }

    return result;
}

From source file:io.spring.batch.ColumnRangePartitioner.java

/**
 * Partition a database table assuming that the data in the column specified
 * are uniformly distributed. The execution context values will have keys
 * <code>minValue</code> and <code>maxValue</code> specifying the range of
 * values to consider in each partition.
 *
 * @see Partitioner#partition(int)//from ww  w  . j a v a 2 s .c om
 */
@Override
public Map<String, ExecutionContext> partition(int gridSize) {
    if (gridSize == 1) {
        gridSize = 4;
    }

    int min = jdbcTemplate.queryForObject("SELECT MIN(" + column + ") from " + table, Integer.class);
    int max = jdbcTemplate.queryForObject("SELECT MAX(" + column + ") from " + table, Integer.class);
    int targetSize = (max - min) / gridSize + 1;

    Map<String, ExecutionContext> result = new HashMap<String, ExecutionContext>();
    int number = 0;
    int start = min;
    int end = start + targetSize - 1;

    while (start <= max) {
        ExecutionContext value = new ExecutionContext();
        result.put("partition" + number, value);

        if (end >= max) {
            end = max;
        }
        value.putInt("minValue", start);
        value.putInt("maxValue", end);
        start += targetSize;
        end += targetSize;
        number++;
    }

    return result;
}

From source file:lcn.module.batch.web.guide.support.ColumnRangePartitioner.java

/**
 * DB??  ? ? Data? "? " ?  . ExecutionContext ?
 * <code>minValue</code>  <code>maxValue</code> ?  , ?   ???
 * ?  ?  .//  w w w  . j a  va  2  s  .c om
 */
public Map<String, ExecutionContext> partition(int gridSize) {
    // ?? ?  ? 
    int min = jdbcTemplate.queryForInt("SELECT MIN(" + column + ") from " + table);

    //  ?? ?  ? 
    int max = jdbcTemplate.queryForInt("SELECT MAX(" + column + ") from " + table);

    // ? Execution? ? Data? (?)
    int targetSize = (max - min) / gridSize + 1;

    Map<String, ExecutionContext> result = new HashMap<String, ExecutionContext>();
    int number = 0;
    int start = min;
    // targetSize ? ? Data
    int end = start + targetSize - 1;

    // ? ? ? ExecutionContext ? minVlaue  maxValue  
    while (start <= max) {

        ExecutionContext value = new ExecutionContext();
        result.put("partition" + number, value);

        if (end >= max) {
            end = max;
        }
        value.putInt("minValue", start);
        value.putInt("maxValue", end);
        start += targetSize;
        end += targetSize;
        number++;
    }

    return result;

}

From source file:fr.acxio.tools.agia.file.ExtendedMultiResourceItemReader.java

/**
 * Store the current resource index and position in the resource.
 *//*from w ww  .  j a  v a2  s.  c o  m*/
public void update(ExecutionContext executionContext) throws ItemStreamException {
    if (saveState) {
        executionContext.putInt(executionContextUserSupport.getKey(RESOURCE_KEY), currentResource);
        delegate.update(executionContext);
    }
}

From source file:es.fcs.batch.integration.chunk.MyChunkMessageChannelItemWriter.java

public void update(ExecutionContext executionContext) throws ItemStreamException {
    executionContext.putInt(EXPECTED, localState.expected.intValue());
    executionContext.putInt(ACTUAL, localState.actual.intValue());
}

From source file:org.emonocot.harvest.common.DirectoryReader.java

@Override
public void update(ExecutionContext executionContext) throws ItemStreamException {
    executionContext.putInt(key, currentCount);
}