List of usage examples for org.springframework.batch.item ExecutionContext getInt
public int getInt(String key)
From source file:es.fcs.batch.integration.chunk.MyChunkMessageChannelItemWriter.java
public void open(ExecutionContext executionContext) throws ItemStreamException { if (executionContext.containsKey(EXPECTED)) { localState.open(executionContext.getInt(EXPECTED), executionContext.getInt(ACTUAL)); if (!waitForResults()) { throw new ItemStreamException("Timed out waiting for back log on open"); }//ww w . j a v a 2 s. co m } }
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(); }// ww w . ja v a2s. 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:fr.acxio.tools.agia.file.ExtendedMultiResourceItemReader.java
/** * Figure out which resource to start with in case of restart, open the * delegate and restore delegate's position in the resource. *///from w ww. j av a 2s.c o m public void open(ExecutionContext executionContext) throws ItemStreamException { Assert.isTrue((resources != null) || (resourcesFactory != null), "Resources and ResourcesFactory must not be both null"); try { if ((resources == null) && (resourcesFactory != null)) { Map<String, Object> aSourceParams = new HashMap<String, Object>(); aSourceParams.put(ResourceFactoryConstants.PARAM_STEP_EXEC, stepExecution); resources = resourcesFactory.getResources(aSourceParams); isResourcesSet = false; } } catch (ResourceCreationException e) { throw new ItemStreamException(e); } noInput = false; if ((resources == null) || (resources.length == 0)) { if (strict) { throw new IllegalStateException( "No resources to read. Set strict=false if this is not an error condition."); } else { LOGGER.warn("No resources to read. Set strict=true if this should be an error condition."); noInput = true; return; } } Arrays.sort(resources, comparator); if (executionContext.containsKey(executionContextUserSupport.getKey(RESOURCE_KEY))) { currentResource = executionContext.getInt(executionContextUserSupport.getKey(RESOURCE_KEY)); // context could have been saved before reading anything if (currentResource == -1) { currentResource = 0; } delegate.setResource(resources[currentResource]); delegate.open(executionContext); } else { currentResource = -1; } }
From source file:org.geoserver.backuprestore.reader.CatalogMultiResourceItemReader.java
/** * Figure out which resource to start with in case of restart, open the delegate and restore delegate's position in the resource. *//*from w ww .j av a 2 s . c o m*/ @Override public void open(ExecutionContext executionContext) throws ItemStreamException { super.open(executionContext); Assert.notNull(resources, "Resources must be set"); noInput = false; if (resources.length == 0) { if (strict) { throw new IllegalStateException( "No resources to read. Set strict=false if this is not an error condition."); } else { logger.warn("No resources to read. Set strict=true if this should be an error condition."); noInput = true; return; } } Arrays.sort(resources, comparator); if (executionContext.containsKey(getExecutionContextKey(RESOURCE_KEY))) { currentResource = executionContext.getInt(getExecutionContextKey(RESOURCE_KEY)); // context could have been saved before reading anything if (currentResource == -1) { currentResource = 0; } delegate.setResource(resources[currentResource]); delegate.open(executionContext); } else { currentResource = -1; } }