BATCH-2062: Added ChunkProcessor implementations to support JSR-352's chunking pattern
* Added the JsrChunkProvider implementation - a no-op ChunkProvider implementation to be used by the ChunkOrientedTasklet * Added the JsrChunkProcessor - A simple implementation of a ChunkProcessor that handles the JSR-352 chunking pattern (read and process loop with a single write per chunk). * Added the JsrFaultTolerantChunkProcessor - A ChunkProcessor that implements chunking the way JSR-352 requires as well as adding skip/retry functionality. * Added builders to support the above functionality.
This commit is contained in:
@@ -1,12 +1,36 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.jsr.repeat;
|
||||
|
||||
import javax.batch.api.chunk.CheckpointAlgorithm;
|
||||
import javax.batch.operations.BatchRuntimeException;
|
||||
|
||||
import org.springframework.batch.repeat.CompletionPolicy;
|
||||
import org.springframework.batch.repeat.RepeatContext;
|
||||
import org.springframework.batch.repeat.RepeatStatus;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* Wrapper for the {@link CheckpointAlgorithm} to be used via the rest
|
||||
* of the framework.
|
||||
*
|
||||
* @author Michael Minella
|
||||
* @see CheckpointAlgorithm
|
||||
* @see CompletionPolicy
|
||||
*/
|
||||
public class CheckpointAlgorithmAdapter implements CompletionPolicy {
|
||||
|
||||
private CheckpointAlgorithm policy;
|
||||
@@ -17,39 +41,50 @@ public class CheckpointAlgorithmAdapter implements CompletionPolicy {
|
||||
this.policy = policy;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext, org.springframework.batch.repeat.RepeatStatus)
|
||||
*/
|
||||
@Override
|
||||
public boolean isComplete(RepeatContext context, RepeatStatus result) {
|
||||
try {
|
||||
return policy.isReadyToCheckpoint();
|
||||
} catch (Exception e) {
|
||||
//TODO: do something here
|
||||
throw new BatchRuntimeException(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.CompletionPolicy#isComplete(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
@Override
|
||||
public boolean isComplete(RepeatContext context) {
|
||||
try {
|
||||
return policy.isReadyToCheckpoint();
|
||||
} catch (Exception e) {
|
||||
//TODO: do something here
|
||||
throw new BatchRuntimeException(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.batch.repeat.CompletionPolicy#start(org.springframework.batch.repeat.RepeatContext)
|
||||
*/
|
||||
@Override
|
||||
public RepeatContext start(RepeatContext parent) {
|
||||
try {
|
||||
policy.beginCheckpoint();
|
||||
} catch (Exception e) {
|
||||
//TODO: do something here
|
||||
throw new BatchRuntimeException(e);
|
||||
}
|
||||
|
||||
return null;
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* If {@link CheckpointAlgorithm#isReadyToCheckpoint()} is true
|
||||
* we will call {@link CheckpointAlgorithm#endCheckpoint()}
|
||||
*
|
||||
* @param context a {@link RepeatContext}
|
||||
*/
|
||||
@Override
|
||||
public void update(RepeatContext context) {
|
||||
try {
|
||||
@@ -57,7 +92,7 @@ public class CheckpointAlgorithmAdapter implements CompletionPolicy {
|
||||
policy.endCheckpoint();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
//TODO: do something here
|
||||
throw new BatchRuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user