001/* 002 * Copyright 2006-2018 the original author or authors. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 017package org.springframework.batch.integration.chunk; 018 019import java.io.Serializable; 020 021import org.springframework.batch.core.StepContribution; 022import org.springframework.lang.Nullable; 023 024/** 025 * Encapsulates a response to processing a chunk of items, summarising the result as a {@link StepContribution}. 026 * 027 * @author Dave Syer 028 * @author Mahmoud Ben Hassine 029 * 030 */ 031public class ChunkResponse implements Serializable { 032 033 private static final long serialVersionUID = 1L; 034 035 private final StepContribution stepContribution; 036 037 private final Long jobId; 038 039 private final boolean status; 040 041 private final String message; 042 043 private final boolean redelivered; 044 045 private final int sequence; 046 047 public ChunkResponse(int sequence, Long jobId, StepContribution stepContribution) { 048 this(true, sequence, jobId, stepContribution, null); 049 } 050 051 public ChunkResponse(boolean status, int sequence, Long jobId, StepContribution stepContribution) { 052 this(status, sequence, jobId, stepContribution, null); 053 } 054 055 public ChunkResponse(boolean status, int sequence, Long jobId, StepContribution stepContribution, @Nullable String message) { 056 this(status, sequence, jobId, stepContribution, message, false); 057 } 058 059 public ChunkResponse(ChunkResponse input, boolean redelivered) { 060 this(input.status, input.sequence, input.jobId, input.stepContribution, input.message, redelivered); 061 } 062 063 public ChunkResponse(boolean status, int sequence, Long jobId, StepContribution stepContribution, @Nullable String message, boolean redelivered) { 064 this.status = status; 065 this.sequence = sequence; 066 this.jobId = jobId; 067 this.stepContribution = stepContribution; 068 this.message = message; 069 this.redelivered = redelivered; 070 } 071 072 public StepContribution getStepContribution() { 073 return stepContribution; 074 } 075 076 public Long getJobId() { 077 return jobId; 078 } 079 080 public int getSequence() { 081 return sequence; 082 } 083 084 public boolean isSuccessful() { 085 return status; 086 } 087 088 public boolean isRedelivered() { 089 return redelivered; 090 } 091 092 public String getMessage() { 093 return message; 094 } 095 096 /** 097 * @see java.lang.Object#toString() 098 */ 099 @Override 100 public String toString() { 101 return getClass().getSimpleName() + ": jobId=" + jobId + ", sequence=" + sequence + ", stepContribution=" + stepContribution 102 + ", successful=" + status; 103 } 104 105}