001    /*
002     * Copyright (c) 2007-2014 Concurrent, Inc. All Rights Reserved.
003     *
004     * Project and contact information: http://www.cascading.org/
005     *
006     * This file is part of the Cascading project.
007     *
008     * Licensed under the Apache License, Version 2.0 (the "License");
009     * you may not use this file except in compliance with the License.
010     * You may obtain a copy of the License at
011     *
012     *     http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing, software
015     * distributed under the License is distributed on an "AS IS" BASIS,
016     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017     * See the License for the specific language governing permissions and
018     * limitations under the License.
019     */
020    
021    package cascading.cascade;
022    
023    import java.util.Map;
024    import java.util.Properties;
025    
026    import cascading.property.Props;
027    
028    /**
029     * Class CascadeProps is a fluent helper class for setting various {@link Cascade} level properties passed
030     * through a {@link CascadeConnector}.
031     */
032    public class CascadeProps extends Props
033      {
034      public static final String MAX_CONCURRENT_FLOWS = "cascading.cascade.maxconcurrentflows";
035    
036      int maxConcurrentFlows = 0;
037    
038      /**
039       * Method setMaxConcurrentFlows sets the maximum number of Flows that a Cascade can run concurrently.
040       * <p/>
041       * A value of one (1) will run one Flow at a time. A value of zero (0), the default, disables the restriction.
042       * <p/>
043       * By default a Cascade will attempt to run all give Flow instances at the same time. But there are occasions
044       * where limiting the number for flows helps manages resources.
045       *
046       * @param properties         of type Map<Object, Object>
047       * @param numConcurrentFlows of type int
048       */
049      public static void setMaxConcurrentFlows( Map<Object, Object> properties, int numConcurrentFlows )
050        {
051        properties.put( MAX_CONCURRENT_FLOWS, Integer.toString( numConcurrentFlows ) );
052        }
053    
054      public static CascadeProps cascadeProps()
055        {
056        return new CascadeProps();
057        }
058    
059      public CascadeProps()
060        {
061        }
062    
063      public int getMaxConcurrentFlows()
064        {
065        return maxConcurrentFlows;
066        }
067    
068      public CascadeProps setMaxConcurrentFlows( int maxConcurrentFlows )
069        {
070        this.maxConcurrentFlows = maxConcurrentFlows;
071    
072        return this;
073        }
074    
075      @Override
076      protected void addPropertiesTo( Properties properties )
077        {
078        setMaxConcurrentFlows( properties, maxConcurrentFlows );
079        }
080      }