001    /**
002     * Copyright 2004-2012 The Kuali Foundation
003     *
004     * Licensed under the Educational Community 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     * http://www.opensource.org/licenses/ecl2.php
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    package org.kuali.common.threads;
017    
018    import java.util.List;
019    
020    import org.kuali.common.threads.listener.NoOpListener;
021    import org.kuali.common.threads.listener.ProgressListener;
022    
023    /**
024     * Provides context for a ThreadHandler
025     *
026     * @param <T>
027     */
028    public class ThreadHandlerContext<T> {
029        public static final int DEFAULT_MAX_THREADS = 1;
030    
031        // Min threads to use
032        int min;
033    
034        // Max threads to use
035        int max = DEFAULT_MAX_THREADS;
036    
037        // If supplied, divide # of elements in the list by this number to come up with a thread count
038        // Thread count will always be constrained by max regardless. This gives clients a way to
039        // scale threads up relative to the number of items in the list
040        int divisor;
041    
042        // The list of elements to iterate over
043        List<T> list;
044    
045        // The handler for dealing with an item from the list
046        ElementHandler<T> handler;
047    
048        // By default don't do anything when informed about progress being made
049        ProgressListener<T> listener = new NoOpListener<T>();
050    
051        public int getMin() {
052            return min;
053        }
054    
055        public void setMin(int min) {
056            this.min = min;
057        }
058    
059        public int getMax() {
060            return max;
061        }
062    
063        public void setMax(int max) {
064            this.max = max;
065        }
066    
067        public List<T> getList() {
068            return list;
069        }
070    
071        public void setList(List<T> list) {
072            this.list = list;
073        }
074    
075        public ElementHandler<T> getHandler() {
076            return handler;
077        }
078    
079        public void setHandler(ElementHandler<T> handler) {
080            this.handler = handler;
081        }
082    
083        public ProgressListener<T> getListener() {
084            return listener;
085        }
086    
087        public void setListener(ProgressListener<T> listener) {
088            this.listener = listener;
089        }
090    
091        public int getDivisor() {
092            return divisor;
093        }
094    
095        public void setDivisor(int divisor) {
096            this.divisor = divisor;
097        }
098    
099    }