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.tap;
022    
023    import java.io.IOException;
024    
025    import cascading.flow.FlowProcess;
026    import cascading.scheme.Scheme;
027    import cascading.tuple.Fields;
028    import cascading.tuple.TupleEntryIterator;
029    
030    /**
031     * Class SinkTap is an optional base class for sink only Taps.
032     * <p/>
033     * Some {@link cascading.tap.Tap} instances may only be sinks (as opposed
034     * to being a source). These types may subclass SinkTap for convenience or
035     * set {@link #isSource()} to {@code false} in a custom Tap sub-class.
036     */
037    public abstract class SinkTap<Config, Output> extends Tap<Config, Void, Output>
038      {
039      protected SinkTap()
040        {
041        }
042    
043      protected SinkTap( Scheme<Config, ?, Output, ?, ?> scheme )
044        {
045        super( (Scheme<Config, Void, Output, ?, ?>) scheme );
046        }
047    
048      protected SinkTap( Scheme<Config, ?, Output, ?, ?> scheme, SinkMode sinkMode )
049        {
050        super( (Scheme<Config, Void, Output, ?, ?>) scheme, sinkMode );
051        }
052    
053      @Override
054      public Fields getSourceFields()
055        {
056        throw new UnsupportedOperationException( "unable to source tuple streams via a SinkTap instance" );
057        }
058    
059      @Override
060      public boolean prepareResourceForRead( Config conf ) throws IOException
061        {
062        throw new UnsupportedOperationException( "unable to prepare resource for read via a SinkTap instance" );
063        }
064    
065      @Override
066      public boolean isSource()
067        {
068        return false;
069        }
070    
071      @Override
072      public void sourceConfInit( FlowProcess<Config> flowProcess, Config conf )
073        {
074        throw new UnsupportedOperationException( "unable to source tuple streams via a SinkTap instance" );
075        }
076    
077      @Override
078      public TupleEntryIterator openForRead( FlowProcess<Config> flowProcess, Void input ) throws IOException
079        {
080        throw new UnsupportedOperationException( "unable to open for read via a SinkTap instance" );
081        }
082      }