View Javadoc
1   /*
2    * Copyright 2006-2007 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.batch.integration.chunk;
18  
19  import java.io.Serializable;
20  
21  import org.springframework.batch.core.StepContribution;
22  
23  /**
24   * Encapsulates a response to processing a chunk of items, summarising the result as a {@link StepContribution}.
25   * 
26   * @author Dave Syer
27   * 
28   */
29  public class ChunkResponse implements Serializable {
30  
31  	private final StepContribution stepContribution;
32  
33  	private final Long jobId;
34  
35  	private final boolean status;
36  
37  	private final String message;
38  	
39  	private final boolean redelivered;
40  
41  	private final int sequence;
42  
43  	public ChunkResponse(int sequence, Long jobId, StepContribution stepContribution) {
44  		this(true, sequence, jobId, stepContribution, null);
45  	}
46  
47  	public ChunkResponse(boolean status, int sequence, Long jobId, StepContribution stepContribution) {
48  		this(status, sequence, jobId, stepContribution, null);
49  	}
50  
51  	public ChunkResponse(boolean status, int sequence, Long jobId, StepContribution stepContribution, String message) {
52  		this(status, sequence, jobId, stepContribution, message, false);
53  	}
54  
55  	public ChunkResponse(ChunkResponse input, boolean redelivered) {
56  		this(input.status, input.sequence, input.jobId, input.stepContribution, input.message, redelivered);
57  	}
58  
59  	public ChunkResponse(boolean status, int sequence, Long jobId, StepContribution stepContribution, String message, boolean redelivered) {
60  		this.status = status;
61  		this.sequence = sequence;
62  		this.jobId = jobId;
63  		this.stepContribution = stepContribution;
64  		this.message = message;
65  		this.redelivered = redelivered;
66  	}
67  
68  	public StepContribution getStepContribution() {
69  		return stepContribution;
70  	}
71  
72  	public Long getJobId() {
73  		return jobId;
74  	}
75  	
76  	public int getSequence() {
77  		return sequence;
78  	}
79  
80  	public boolean isSuccessful() {
81  		return status;
82  	}
83  	
84  	public boolean isRedelivered() {
85  		return redelivered;
86  	}
87  
88  	public String getMessage() {
89  		return message;
90  	}
91  
92  	/**
93  	 * @see java.lang.Object#toString()
94  	 */
95  	@Override
96  	public String toString() {
97  		return getClass().getSimpleName() + ": jobId=" + jobId + ", sequence=" + sequence + ", stepContribution=" + stepContribution
98  				+ ", successful=" + status;
99  	}
100 
101 }