001/*
002 * Copyright 2006-2007 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;
020import java.util.Collection;
021
022import org.springframework.batch.core.StepContribution;
023
024/**
025 * Encapsulation of a chunk of items to be processed remotely as part of a step
026 * execution.
027 * 
028 * @author Dave Syer
029 * 
030 * @param <T> the type of the items to process
031 */
032public class ChunkRequest<T> implements Serializable {
033
034        private static final long serialVersionUID = 1L;
035
036        private final long jobId;
037
038        private final Collection<? extends T> items;
039
040        private final StepContribution stepContribution;
041
042        private final int sequence;
043
044        public ChunkRequest(int sequence, Collection<? extends T> items, long jobId, StepContribution stepContribution) {
045                this.sequence = sequence;
046                this.items = items;
047                this.jobId = jobId;
048                this.stepContribution = stepContribution;
049        }
050
051        public long getJobId() {
052                return jobId;
053        }
054
055        public Collection<? extends T> getItems() {
056                return items;
057        }
058
059        public int getSequence() {
060                return sequence;
061        }
062
063        /**
064         * @return the {@link StepContribution} for this chunk
065         */
066        public StepContribution getStepContribution() {
067                return stepContribution;
068        }
069
070        /**
071         * @see java.lang.Object#toString()
072         */
073        @Override
074        public String toString() {
075                return getClass().getSimpleName() + ": jobId=" + jobId + ", sequence=" + sequence + ", contribution="
076                                + stepContribution + ", item count=" + items.size();
077        }
078
079}