List of usage examples for org.springframework.batch.core StepContribution incrementWriteSkipCount
public void incrementWriteSkipCount()
From source file:es.fcs.batch.integration.chunk.MyRemoteChunkHandlerFactoryBean.java
/** * Update a StepContribution with all the data from a StepContributionSource. The filter and write conuts plus the * exit status will be updated to reflect the data in the source. * //from w ww . j a v a 2s .c o m * @param contribution the current contribution * @param stepContributionSource a source of StepContributions */ protected void updateStepContribution(StepContribution contribution, StepContributionSource stepContributionSource) { for (StepContribution result : stepContributionSource.getStepContributions()) { contribution.incrementFilterCount(result.getFilterCount()); contribution.incrementWriteCount(result.getWriteCount()); for (int i = 0; i < result.getProcessSkipCount(); i++) { contribution.incrementProcessSkipCount(); } for (int i = 0; i < result.getWriteSkipCount(); i++) { contribution.incrementWriteSkipCount(); } contribution.setExitStatus(contribution.getExitStatus().and(result.getExitStatus())); } }
From source file:org.springframework.batch.core.jsr.step.item.JsrFaultTolerantChunkProcessor.java
/** * Adds retry and skip logic to the write phase of the chunk loop. * * @param contribution a {@link StepContribution} * @param chunk a {@link Chunk}/* w w w . j a va 2 s .c o m*/ * @throws Exception */ @Override protected void persist(final StepContribution contribution, final Chunk<O> chunk) throws Exception { RetryCallback<Object, Exception> retryCallback = new RetryCallback<Object, Exception>() { @Override @SuppressWarnings({ "unchecked", "rawtypes" }) public Object doWithRetry(RetryContext context) throws Exception { chunkMonitor.setChunkSize(chunk.size()); try { doPersist(contribution, chunk); } catch (Exception e) { if (shouldSkip(skipPolicy, e, contribution.getStepSkipCount())) { // Per section 9.2.7 of JSR-352, the SkipListener receives all the items within the chunk ((MulticasterBatchListener) getListener()).onSkipInWrite(chunk.getItems(), e); } else { getListener().onRetryWriteException((List<Object>) chunk.getItems(), e); if (rollbackClassifier.classify(e)) { throw e; } } /* * If the exception is marked as no-rollback, we need to * override that, otherwise there's no way to write the * rest of the chunk or to honour the skip listener * contract. */ throw new ForceRollbackForWriteSkipException( "Force rollback on skippable exception so that skipped item can be located.", e); } contribution.incrementWriteCount(chunk.size()); return null; } }; RecoveryCallback<Object> recoveryCallback = new RecoveryCallback<Object>() { @Override public O recover(RetryContext context) throws Exception { Throwable e = context.getLastThrowable(); if (shouldSkip(skipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); logger.debug("Skipping after failed write", e); return null; } else { if (rollbackClassifier.classify(e)) { // Default is to rollback unless the classifier // allows us to continue throw new RetryException("Non-skippable exception in recoverer while write", e); } return null; } } }; batchRetryTemplate.execute(retryCallback, recoveryCallback); }
From source file:org.springframework.batch.core.step.item.FaultTolerantChunkProcessor.java
private void checkSkipPolicy(Chunk<I>.ChunkIterator inputIterator, Chunk<O>.ChunkIterator outputIterator, Throwable e, StepContribution contribution, boolean recovery) throws Exception { logger.debug("Checking skip policy after failed write"); if (shouldSkip(itemWriteSkipPolicy, e, contribution.getStepSkipCount())) { contribution.incrementWriteSkipCount(); inputIterator.remove();//w w w . jav a 2s .c o m outputIterator.remove(e); logger.debug("Skipping after failed write", e); } else { if (recovery) { // Only if already recovering should we check skip policy throw new RetryException("Non-skippable exception in recoverer", e); } else { if (e instanceof Exception) { throw (Exception) e; } else if (e instanceof Error) { throw (Error) e; } else { throw new RetryException("Non-skippable throwable in recoverer", e); } } } }