    001/*
    002 * Copyright (c) 2007-2017 Xplenty, 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
    021package cascading.cascade;
    022
    023import java.util.Map;
    024import java.util.Properties;
    025
    026import 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 */
    032public 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  /**
    055   * Creates a new CascadeProps instance.
    056   *
    057   * @return CascadeProps instance
    058   */
    059  public static CascadeProps cascadeProps()
    060    {
    061    return new CascadeProps();
    062    }
    063
    064  public CascadeProps()
    065    {
    066    }
    067
    068  public int getMaxConcurrentFlows()
    069    {
    070    return maxConcurrentFlows;
    071    }
    072
    073  /**
    074   * Method setMaxConcurrentFlows sets the maximum number of Flows that a Cascade can run concurrently.
    075   * <p/>
    076   * A value of one (1) will run one Flow at a time. A value of zero (0), the default, disables the restriction.
    077   * <p/>
    078   * By default a Cascade will attempt to run all give Flow instances at the same time, if eligible. But there are
    079   * occasions where limiting the number for flows helps manages resources.
    080   *
    081   * @param maxConcurrentFlows of type int
    082   */
    083  public CascadeProps setMaxConcurrentFlows( int maxConcurrentFlows )
    084    {
    085    this.maxConcurrentFlows = maxConcurrentFlows;
    086
    087    return this;
    088    }
    089
    090  @Override
    091  protected void addPropertiesTo( Properties properties )
    092    {
    093    setMaxConcurrentFlows( properties, maxConcurrentFlows );
    094    }
    095  }