001    /*
002     * Copyright (c) 2007-2015 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.flow;
022    
023    import java.util.Map;
024    import java.util.Properties;
025    
026    import cascading.operation.AssertionLevel;
027    import cascading.operation.DebugLevel;
028    import cascading.property.Props;
029    import cascading.scheme.Scheme;
030    import cascading.tap.DecoratorTap;
031    
032    /**
033     * The class FlowConnectorProps is a fluent helper class for setting {@link FlowConnector} specific
034     * properties through the {@link FlowConnector} constructor.
035     *
036     * @see cascading.property.AppProps
037     * @see cascading.cascade.CascadeProps
038     * @see FlowProps
039     */
040    public class FlowConnectorProps extends Props
041      {
042      public static final String ASSERTION_LEVEL = "cascading.flowconnector.assertionlevel";
043      public static final String DEBUG_LEVEL = "cascading.flowconnector.debuglevel";
044      public static final String INTERMEDIATE_SCHEME_CLASS = "cascading.flowconnector.intermediateschemeclass";
045      public static final String TEMPORARY_TAP_DECORATOR_CLASS = "cascading.flowconnector.temporary_tap.decorator.classname";
046      public static final String CHECKPOINT_TAP_DECORATOR_CLASS = "cascading.flowconnector.checkpoint_tap.decorator.classname";
047    
048      AssertionLevel assertionLevel;
049      DebugLevel debugLevel;
050      String intermediateSchemeClassName;
051      String temporaryTapDecoratorClassName;
052      String checkpointTapDecoratorClassName;
053    
054      /**
055       * Method setAssertionLevel sets the target planner {@link cascading.operation.AssertionLevel}.
056       *
057       * @param properties     of type Map<Object, Object>
058       * @param assertionLevel of type AssertionLevel
059       */
060      public static void setAssertionLevel( Map<Object, Object> properties, AssertionLevel assertionLevel )
061        {
062        if( assertionLevel != null )
063          properties.put( ASSERTION_LEVEL, assertionLevel.toString() );
064        }
065    
066      /**
067       * Method setDebugLevel sets the target planner {@link cascading.operation.DebugLevel}.
068       *
069       * @param properties of type Map<Object, Object>
070       * @param debugLevel of type DebugLevel
071       */
072      public static void setDebugLevel( Map<Object, Object> properties, DebugLevel debugLevel )
073        {
074        if( debugLevel != null )
075          properties.put( DEBUG_LEVEL, debugLevel.toString() );
076        }
077    
078      /**
079       * Method setIntermediateSchemeClass is used for debugging.
080       *
081       * @param properties              of type Map<Object, Object>
082       * @param intermediateSchemeClass of type Class
083       */
084      public static void setIntermediateSchemeClass( Map<Object, Object> properties, Class<? extends Scheme> intermediateSchemeClass )
085        {
086        if( intermediateSchemeClass != null )
087          properties.put( INTERMEDIATE_SCHEME_CLASS, intermediateSchemeClass.getName() );
088        }
089    
090      /**
091       * Method setIntermediateSchemeClass is used for debugging.
092       *
093       * @param properties                  of type Map<Object, Object>
094       * @param intermediateSchemeClassName of type String
095       */
096      public static void setIntermediateSchemeClass( Map<Object, Object> properties, String intermediateSchemeClassName )
097        {
098        if( intermediateSchemeClassName != null )
099          properties.put( INTERMEDIATE_SCHEME_CLASS, intermediateSchemeClassName );
100        }
101    
102      /**
103       * Method temporaryTapDecoratorClassName is used for wrapping a intermediate temporary Tap.
104       *
105       * @param properties                     of type Map<Object, Object>
106       * @param temporaryTapDecoratorClassName of type String
107       */
108      public static void setTemporaryTapDecoratorClass( Map<Object, Object> properties, String temporaryTapDecoratorClassName )
109        {
110        if( temporaryTapDecoratorClassName != null )
111          properties.put( TEMPORARY_TAP_DECORATOR_CLASS, temporaryTapDecoratorClassName );
112        }
113    
114      /**
115       * Method checkpointTapDecoratorClassName is used for wrapping a checkpoint Tap.
116       *
117       * @param properties                      of type Map<Object, Object>
118       * @param checkpointTapDecoratorClassName of type String
119       */
120      public static void setCheckpointTapDecoratorClass( Map<Object, Object> properties, String checkpointTapDecoratorClassName )
121        {
122        if( checkpointTapDecoratorClassName != null )
123          properties.put( CHECKPOINT_TAP_DECORATOR_CLASS, checkpointTapDecoratorClassName );
124        }
125    
126      /**
127       * Creates a new FlowConnectorProps instance.
128       *
129       * @return FlowConnectorProps instance
130       */
131      public static FlowConnectorProps flowConnectorProps()
132        {
133        return new FlowConnectorProps();
134        }
135    
136      public FlowConnectorProps()
137        {
138        }
139    
140      public AssertionLevel getAssertionLevel()
141        {
142        return assertionLevel;
143        }
144    
145      /**
146       * Method setAssertionLevel sets the target planner {@link cascading.operation.AssertionLevel}.
147       *
148       * @param assertionLevel of type AssertionLevel
149       * @return this instance
150       */
151      public FlowConnectorProps setAssertionLevel( AssertionLevel assertionLevel )
152        {
153        this.assertionLevel = assertionLevel;
154    
155        return this;
156        }
157    
158      public DebugLevel getDebugLevel()
159        {
160        return debugLevel;
161        }
162    
163      /**
164       * Method setDebugLevel sets the target planner {@link cascading.operation.DebugLevel}.
165       *
166       * @param debugLevel of type DebugLevel
167       * @return this instance
168       */
169      public FlowConnectorProps setDebugLevel( DebugLevel debugLevel )
170        {
171        this.debugLevel = debugLevel;
172    
173        return this;
174        }
175    
176      public String getIntermediateSchemeClassName()
177        {
178        return intermediateSchemeClassName;
179        }
180    
181      /**
182       * Method setIntermediateSchemeClassName is used for debugging.
183       *
184       * @param intermediateSchemeClassName of type String
185       * @return this instance
186       */
187      public FlowConnectorProps setIntermediateSchemeClassName( String intermediateSchemeClassName )
188        {
189        this.intermediateSchemeClassName = intermediateSchemeClassName;
190    
191        return this;
192        }
193    
194      /**
195       * Method setIntermediateSchemeClassName is used for debugging.
196       *
197       * @param intermediateSchemeClass of type Class
198       * @return this instance
199       */
200      public FlowConnectorProps setIntermediateSchemeClassName( Class<Scheme> intermediateSchemeClass )
201        {
202        if( intermediateSchemeClass != null )
203          this.intermediateSchemeClassName = intermediateSchemeClass.getName();
204    
205        return this;
206        }
207    
208      public String getTemporaryTapDecoratorClassName()
209        {
210        return temporaryTapDecoratorClassName;
211        }
212    
213      /**
214       * Method setTemporaryTapDecoratorClassName sets the class of a {@link cascading.tap.DecoratorTap} to use to
215       * wrap an intermediate temporary Tap instance internal to the Flow.
216       *
217       * @param temporaryTapDecoratorClassName of type String
218       * @return this instance
219       */
220      public FlowConnectorProps setTemporaryTapDecoratorClassName( String temporaryTapDecoratorClassName )
221        {
222        this.temporaryTapDecoratorClassName = temporaryTapDecoratorClassName;
223    
224        return this;
225        }
226    
227      /**
228       * Method setTemporaryTapDecoratorClassName sets the class of a {@link cascading.tap.DecoratorTap} to use to
229       * wrap an intermediate temporary Tap instance internal to the Flow.
230       *
231       * @param temporaryTapDecoratorClass of type Class
232       * @return this instance
233       */
234      public FlowConnectorProps setTemporaryTapDecoratorClassName( Class<DecoratorTap> temporaryTapDecoratorClass )
235        {
236        if( temporaryTapDecoratorClass != null )
237          this.temporaryTapDecoratorClassName = temporaryTapDecoratorClass.getName();
238    
239        return this;
240        }
241    
242      public String getCheckpointTapDecoratorClassName()
243        {
244        return checkpointTapDecoratorClassName;
245        }
246    
247      /**
248       * Method setCheckpointTapDecoratorClassName sets the class of a {@link cascading.tap.DecoratorTap} to use to
249       * wrap an Checkpoint Tap instance within the Flow.
250       *
251       * @param checkpointTapDecoratorClassName of type String
252       * @return this instance
253       */
254      public FlowConnectorProps setCheckpointTapDecoratorClassName( String checkpointTapDecoratorClassName )
255        {
256        this.checkpointTapDecoratorClassName = checkpointTapDecoratorClassName;
257    
258        return this;
259        }
260    
261      /**
262       * Method setCheckpointTapDecoratorClassName sets the class of a {@link cascading.tap.DecoratorTap} to use to
263       * wrap an Checkpoint Tap instance within the Flow.
264       *
265       * @param checkpointTapDecoratorClass of type Class
266       * @return this instance
267       */
268      public FlowConnectorProps setCheckpointTapDecoratorClassName( Class<DecoratorTap> checkpointTapDecoratorClass )
269        {
270        if( checkpointTapDecoratorClass != null )
271          this.checkpointTapDecoratorClassName = checkpointTapDecoratorClass.getName();
272    
273        return this;
274        }
275    
276      @Override
277      protected void addPropertiesTo( Properties properties )
278        {
279        setAssertionLevel( properties, assertionLevel );
280        setDebugLevel( properties, debugLevel );
281        setIntermediateSchemeClass( properties, intermediateSchemeClassName );
282        setTemporaryTapDecoratorClass( properties, temporaryTapDecoratorClassName );
283        setCheckpointTapDecoratorClass( properties, checkpointTapDecoratorClassName );
284        }
285      }