List of usage examples for org.springframework.batch.item ExecutionContext get
@Nullable
public Object get(String key)
From source file:fr.acxio.tools.agia.alfresco.AlfrescoNodeReader.java
@Override public void open(ExecutionContext sExecutionContext) throws ItemStreamException { String aFullPath = null;// w w w .java2 s . c o m try { baseURI = new URI(getAlfrescoService().getWebappAddress()).resolve(WEBDAV_PATH); aFullPath = getWebDavDirectoryURI(baseURI.getPath() + path).getPath(); } catch (URISyntaxException e) { throw new ItemStreamException(e); } currentDirPath = sExecutionContext.getString(CONTEXT_KEY_CURRENTPATH, aFullPath); Object aCurrentIndexes = sExecutionContext.get(CONTEXT_KEY_CURRENTINDEXES); if (aCurrentIndexes == null) { currentIndexes = new ArrayDeque<Integer>(); currentIndexes.addFirst(0); } else { Integer[] aArray = (Integer[]) aCurrentIndexes; currentIndexes = new ArrayDeque<Integer>(Arrays.asList(aArray)); } sardine = getAlfrescoService().startWebDavSession(); }
From source file:org.springframework.batch.item.xml.StaxEventItemWriter.java
/** * Open the output source// w w w . ja v a 2 s.c o m * * @see org.springframework.batch.item.ItemStream#open(ExecutionContext) */ @SuppressWarnings("unchecked") @Override public void open(ExecutionContext executionContext) { super.open(executionContext); Assert.notNull(resource, "The resource must be set"); long startAtPosition = 0; // if restart data is provided, restart from provided offset // otherwise start from beginning if (executionContext.containsKey(getExecutionContextKey(RESTART_DATA_NAME))) { startAtPosition = executionContext.getLong(getExecutionContextKey(RESTART_DATA_NAME)); currentRecordCount = executionContext.getLong(getExecutionContextKey(WRITE_STATISTICS_NAME)); if (executionContext.containsKey(getExecutionContextKey(UNCLOSED_HEADER_CALLBACK_ELEMENTS_NAME))) { unclosedHeaderCallbackElements = (List<QName>) executionContext .get(getExecutionContextKey(UNCLOSED_HEADER_CALLBACK_ELEMENTS_NAME)); } restarted = true; if (shouldDeleteIfEmpty && currentRecordCount == 0) { // previous execution deleted the output file because no items were written restarted = false; startAtPosition = 0; } else { restarted = true; } } else { currentRecordCount = 0; restarted = false; } open(startAtPosition); if (startAtPosition == 0) { try { if (headerCallback != null) { UnclosedElementCollectingEventWriter headerCallbackWriter = new UnclosedElementCollectingEventWriter( delegateEventWriter); headerCallback.write(headerCallbackWriter); unclosedHeaderCallbackElements = headerCallbackWriter.getUnclosedElements(); } } catch (IOException e) { throw new ItemStreamException("Failed to write headerItems", e); } } this.initialized = true; }
From source file:org.springframework.batch.jsr.item.CheckpointSupport.java
@Override public void open(ExecutionContext executionContext) throws ItemStreamException { try {/*from w ww . ja v a2s . c o m*/ String executionContextKey = getExecutionContextKey(checkpointKey); Serializable checkpoint = (Serializable) executionContext.get(executionContextKey); doOpen(checkpoint); } catch (Exception e) { throw new ItemStreamException(e); } }
From source file:org.springframework.cloud.task.app.composedtaskrunner.TaskLauncherTasklet.java
/** * Executes the task as specified by the taskName with the associated * properties and arguments./*from ww w .j a v a2 s . c om*/ * @param contribution mutable state to be passed back to update the current step execution * @param chunkContext contains the task-execution-id used by the listener. * @return Repeat status of FINISHED. */ @Override public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) throws Exception { String tmpTaskName = this.taskName.substring(0, this.taskName.lastIndexOf('_')); List<String> args = this.arguments; ExecutionContext stepExecutionContext = chunkContext.getStepContext().getStepExecution() .getExecutionContext(); if (stepExecutionContext.containsKey("task-arguments")) { args = (List<String>) stepExecutionContext.get("task-arguments"); } long executionId = this.taskOperations.launch(tmpTaskName, this.properties, args); stepExecutionContext.put("task-execution-id", executionId); stepExecutionContext.put("task-arguments", args); if (!waitForTaskToComplete(executionId)) { throw new TaskExecutionTimeoutException( String.format("Timeout occurred while processing task with Execution Id %s", executionId)); } return RepeatStatus.FINISHED; }