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