BATCH-220: Committed the read part of chunking, without adding it to the StepExecutor. It should be noted that I used 'Chunker' instead of 'ChunkReader', since there's already precedence in the java world, and it isn't reading chunk so much as making a chunk out of items. I have also added skipCount to StepExecution, since it's reasonable that this type of data A) should be persisted and B) the domain object is the most logical place for this type of state.

This commit is contained in:
lucasward
2008-02-11 03:17:58 +00:00
parent af1729f251
commit 7a2cdadf8c
4 changed files with 188 additions and 0 deletions

View File

@@ -0,0 +1,73 @@
/*
* Copyright 2006-2008 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.core.domain;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.springframework.util.Assert;
/**
* A 'chunk' of items, that will be committed together. It is expected that a
* chunk may be serialized, especially if using a queue to dispatch chunks to
* various {@link ChunkProcessor}s.
*
* @author Ben Hale
* @author Lucas Ward
*/
public class Chunk implements Serializable {
private final Long id;
private final List items;
public Chunk(Long id, List items) {
validateSerializable(items);
this.items = items;
this.id = id;
}
/**
* Get the list of items for this chunk.
*
* @return items.
*/
public List getItems() {
return new ArrayList(items);
}
/**
* Get the chunk id.
*
* @return id of this chunk.
*/
public Long getId() {
return id;
}
/**
* In order for the whole chunk to be serializable, every item in the chunk
* must be serializable.
*/
private void validateSerializable(List items) {
for (Iterator i = items.iterator(); i.hasNext();) {
Assert.isInstanceOf(Serializable.class, i.next(), "All items in a chunk must be serialiable");
}
}
}

View File

@@ -0,0 +1,37 @@
/*
* Copyright 2006-2007 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.core.domain;
import org.springframework.batch.core.domain.StepExecution;
/**
* Policy for determining whether or not reading should continue.
*
* @author Lucas Ward
*/
public interface ReadFailurePolicy {
/**
* Returns true or false, indicating whether or not reading should
* continue for the current step execution with the given throwable.
*
* @param ex throwable encountered while reading
* @param stepExecution currently running execution
* @return true if reading should continue, false otherwise.
* @throws IllegalArgumentException if t or stepExecution is null
*/
boolean shouldContinue(Exception ex, StepExecution stepExecution);
}

View File

@@ -46,6 +46,10 @@ public class StepExecution extends Entity {
private int commitCount = 0;
private int rollbackCount = 0;
private int skipCount = 0;
private int retryCount = 0;
private Date startTime = new Date(System.currentTimeMillis());
@@ -368,5 +372,25 @@ public class StepExecution extends Entity {
public void setTerminateOnly() {
this.terminateOnly = true;
}
public void setSkipCount(int skipCount) {
this.skipCount = skipCount;
}
public int getSkipCount() {
return skipCount;
}
public void incrementSkipCount(){
skipCount++;
}
public void setRetryCount(int retryCount) {
this.retryCount = retryCount;
}
public int getRetryCount() {
return retryCount;
}
}