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

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

Introduction

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

Prototype

public int getInt(String key, int defaultInt) 

Source Link

Document

Typesafe Getter for the Integer represented by the provided key with default value to return if key is not represented.

Usage

From source file:org.trpr.example.batch.greeting.reader.GreetingJobReader.java

/**
 * Interface method implementation. Stores the partition index, if any, to be appended to the data item
 * @see SimpleRangePartitioner#TOTAL_PARTITIIONS, {@link SimpleRangePartitioner#PARTITION_INDEX}
 * @see org.springframework.batch.item.ItemStream#open(org.springframework.batch.item.ExecutionContext)
 *//*from  w  ww  . j  a  v  a  2  s  .  c  o  m*/
public void open(ExecutionContext context) throws ItemStreamException {
    this.partitionIndex = context.getInt(SimpleRangePartitioner.PARTITION_INDEX, -1);
}

From source file:be.ordina.springbatch.batch.writer.FineInformationWriter.java

private void upTheTally(Fine fine) {
    ExecutionContext executionContext = stepExecution.getExecutionContext();
    executionContext.put(fine.getLicensePlate().getType().name(),
            executionContext.getInt(fine.getLicensePlate().getType().name(), 0) + 1);
    executionContext.put("total", executionContext.getDouble("total", 0L) + fine.getAmountToPay());
    if (fine.isGraveError()) {
        executionContext.put("graveErrors", executionContext.getInt("graveErrors", 0) + 1);
    }//  w w  w . j av  a2 s  .  c  o m
}

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

@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
    File directory = new File(directoryName);
    if (directory.isDirectory()) {
        this.files = directory.listFiles((FileFilter) FileFilterUtils.fileFileFilter());
        if (files.length > 1) {
            Arrays.sort(files, new NameFileComparator());
        }/*from  w  w w. ja  v a 2  s. c o m*/
    } else {
        throw new IllegalArgumentException(directoryName + " is not a directory");
    }
    currentCount = executionContext.getInt(key, 0);
}

From source file:org.springframework.batch.core.step.item.ChunkMonitor.java

@Override
public void open(ExecutionContext executionContext) throws ItemStreamException {
    super.open(executionContext);
    if (streamsRegistered) {
        stream.open(executionContext);//  ww w.j av  a 2  s.  c  o  m
        ChunkMonitorData data = new ChunkMonitorData(executionContext.getInt(getExecutionContextKey(OFFSET), 0),
                0);
        holder.set(data);
        if (reader == null) {
            logger.warn("No ItemReader set (must be concurrent step), so ignoring offset data.");
            return;
        }
        for (int i = 0; i < data.offset; i++) {
            try {
                reader.read();
            } catch (Exception e) {
                throw new ItemStreamException("Could not position reader with offset: " + data.offset, e);
            }
        }

        resetOffset();
    }
}