001/*
002 * Copyright 2006-2013 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.core.partition.support;
018
019import java.util.HashMap;
020import java.util.Map;
021
022import org.springframework.batch.item.ExecutionContext;
023
024/**
025 * Simplest possible implementation of {@link Partitioner}. Just creates a set
026 * of empty {@link ExecutionContext} instances, and labels them as
027 * <code>{partition0, partition1, ..., partitionN}</code>, where <code>N</code> is the grid
028 * size.
029 *
030 * @author Dave Syer
031 * @since 2.0
032 */
033public class SimplePartitioner implements Partitioner {
034
035        private static final String PARTITION_KEY = "partition";
036
037        @Override
038        public Map<String, ExecutionContext> partition(int gridSize) {
039                Map<String, ExecutionContext> map = new HashMap<String, ExecutionContext>(gridSize);
040                for (int i = 0; i < gridSize; i++) {
041                        map.put(PARTITION_KEY + i, new ExecutionContext());
042                }
043                return map;
044        }
045
046}