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.tap.partition;
023
024import java.util.Map;
025import java.util.Properties;
026
027import cascading.property.Props;
028
029/**
030 * Class PartitionTapProps is a fluent helper class to set properties which control the behaviour of the
031 * {@link BasePartitionTap}.
032 */
033public class PartitionTapProps extends Props
034  {
035  public static final String FAIL_ON_CLOSE = "cascading.tap.partition.failonclose";
036
037  private boolean failOnClose = false;
038
039  /**
040   * Method setFailOnClose(boolean b) controls if the PartitionTap is ignoring all Excpetions, when a TupleEntryCollector
041   * is closed or if it should rethrow the Exception.
042   *
043   * @param properties  a Map
044   * @param failOnClose boolean controlling the close behaviour
045   */
046  public static void setFailOnClose( Map<Object, Object> properties, boolean failOnClose )
047    {
048    properties.put( FAIL_ON_CLOSE, Boolean.toString( failOnClose ) );
049    }
050
051  /**
052   * Creates a new PartitionTapProps instance.
053   *
054   * @return PartitionTapProps instance
055   */
056  public static PartitionTapProps partitionTapProps()
057    {
058    return new PartitionTapProps();
059    }
060
061  /**
062   * Constructs a new PartitionTapProps instance.
063   */
064  public PartitionTapProps()
065    {
066    }
067
068  public boolean isFailOnClose()
069    {
070    return failOnClose;
071    }
072
073  /**
074   * Method setFailOnClose controls if the PartitionTap is ignoring all Exceptions, when a TupleEntryCollector
075   * is closed or if it should rethrow the Exception.
076   *
077   * @param failOnClose boolean controlling the close behaviour
078   */
079  public PartitionTapProps setFailOnClose( boolean failOnClose )
080    {
081    this.failOnClose = failOnClose;
082    return this;
083    }
084
085  @Override
086  protected void addPropertiesTo( Properties properties )
087    {
088    setFailOnClose( properties, failOnClose );
089    }
090  }