// Path: src/main/java/org/apache/storm/hdfs/bolt/format/FileNameFormat.java
// public interface FileNameFormat extends Serializable {
// 
//     void prepare(Map conf, TopologyContext topologyContext);
// 
//     /**
//      * Returns the filename the HdfsBolt will create.
//      * @param rotation the current file rotation number (incremented on every rotation)
//      * @param timeStamp current time in milliseconds when the rotation occurs
//      * @return
//      */
//     String getName(long rotation, long timeStamp);
// 
//     String getPath();
// }
// 
// Path: src/main/java/org/apache/storm/hdfs/bolt/format/SequenceFormat.java
// public interface SequenceFormat extends Serializable {
//     /**
//      * Key class used by implementation (e.g. IntWritable.class, etc.)
//      *
//      * @return
//      */
//     Class keyClass();
// 
//     /**
//      * Value class used by implementation (e.g. Text.class, etc.)
//      * @return
//      */
//     Class valueClass();
// 
//     /**
//      * Given a tuple, return the key that should be written to the sequence file.
//      *
//      * @param tuple
//      * @return
//      */
//     Writable key(Tuple tuple);
// 
//     /**
//      * Given a tuple, return the value that should be written to the sequence file.
//      * @param tuple
//      * @return
//      */
//     Writable value(Tuple tuple);
// }
// 
// Path: src/main/java/org/apache/storm/hdfs/bolt/rotation/FileRotationPolicy.java
// public interface FileRotationPolicy extends Serializable {
//     /**
//      * Called for every tuple the HdfsBolt executes.
//      *
//      * @param tuple The tuple executed.
//      * @param offset current offset of file being written
//      * @return true if a file rotation should be performed
//      */
//     boolean mark(Tuple tuple, long offset);
// 
// 
//     /**
//      * Called after the HdfsBolt rotates a file.
//      *
//      */
//     void reset();
// }
// 
// Path: src/main/java/org/apache/storm/hdfs/bolt/sync/SyncPolicy.java
// public interface SyncPolicy extends Serializable {
//     /**
//      * Called for every tuple the HdfsBolt executes.
//      *
//      * @param tuple The tuple executed.
//      * @param offset current offset for the file being written
//      * @return true if a sync should be performed
//      */
//     boolean mark(Tuple tuple, long offset);
// 
// 
//     /**
//      * Called after the HdfsBolt performs a sync.
//      *
//      */
//     void reset();
// 
// }
// 
// Path: src/main/java/org/apache/storm/hdfs/common/rotation/RotationAction.java
// public interface RotationAction extends Serializable {
//     void execute(FileSystem fileSystem, Path filePath) throws IOException;
// }


import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.tuple.Tuple;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.compress.CompressionCodecFactory;
import org.apache.storm.hdfs.bolt.format.FileNameFormat;
import org.apache.storm.hdfs.bolt.format.SequenceFormat;
import org.apache.storm.hdfs.bolt.rotation.FileRotationPolicy;
import org.apache.storm.hdfs.bolt.sync.SyncPolicy;
import org.apache.storm.hdfs.common.rotation.RotationAction;
import org.slf4j.Logger;
/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.storm.hdfs.bolt;



public class SequenceFileBolt extends AbstractHdfsBolt {
    private static final Logger LOG = LoggerFactory.getLogger(SequenceFileBolt.class);

    private SequenceFormat format;
    private SequenceFile.CompressionType compressionType = SequenceFile.CompressionType.RECORD;
    private transient SequenceFile.Writer writer;

    private String compressionCodec = "default";
    private transient CompressionCodecFactory codecFactory;

    public SequenceFileBolt() {
    }

    public SequenceFileBolt withCompressionCodec(String codec){
        this.compressionCodec = codec;
        return this;
    }

    public SequenceFileBolt withFsUrl(String fsUrl) {
        this.fsUrl = fsUrl;
        return this;
    }

    public SequenceFileBolt withConfigKey(String configKey){
        this.configKey = configKey;
        return this;
    }

// Path: src/main/java/org/apache/storm/hdfs/bolt/format/FileNameFormat.java
// public interface FileNameFormat extends Serializable {
// 
//     void prepare(Map conf, TopologyContext topologyContext);
// 
//     /**
//      * Returns the filename the HdfsBolt will create.
//      * @param rotation the current file rotation number (incremented on every rotation)
//      * @param timeStamp current time in milliseconds when the rotation occurs
//      * @return
//      */
//     String getName(long rotation, long timeStamp);
// 
//     String getPath();
// }
// 
// Path: src/main/java/org/apache/storm/hdfs/bolt/format/SequenceFormat.java
// public interface SequenceFormat extends Serializable {
//     /**
//      * Key class used by implementation (e.g. IntWritable.class, etc.)
//      *
//      * @return
//      */
//     Class keyClass();
// 
//     /**
//      * Value class used by implementation (e.g. Text.class, etc.)
//      * @return
//      */
//     Class valueClass();
// 
//     /**
//      * Given a tuple, return the key that should be written to the sequence file.
//      *
//      * @param tuple
//      * @return
//      */
//     Writable key(Tuple tuple);
// 
//     /**
//      * Given a tuple, return the value that should be written to the sequence file.
//      * @param tuple
//      * @return
//      */
//     Writable value(Tuple tuple);
// }
// 
// Path: src/main/java/org/apache/storm/hdfs/bolt/rotation/FileRotationPolicy.java
// public interface FileRotationPolicy extends Serializable {
//     /**
//      * Called for every tuple the HdfsBolt executes.
//      *
//      * @param tuple The tuple executed.
//      * @param offset current offset of file being written
//      * @return true if a file rotation should be performed
//      */
//     boolean mark(Tuple tuple, long offset);
// 
// 
//     /**
//      * Called after the HdfsBolt rotates a file.
//      *
//      */
//     void reset();
// }
// 
// Path: src/main/java/org/apache/storm/hdfs/bolt/sync/SyncPolicy.java
// public interface SyncPolicy extends Serializable {
//     /**
//      * Called for every tuple the HdfsBolt executes.
//      *
//      * @param tuple The tuple executed.
//      * @param offset current offset for the file being written
//      * @return true if a sync should be performed
//      */
//     boolean mark(Tuple tuple, long offset);
// 
// 
//     /**
//      * Called after the HdfsBolt performs a sync.
//      *
//      */
//     void reset();
// 
// }
// 
// Path: src/main/java/org/apache/storm/hdfs/common/rotation/RotationAction.java
// public interface RotationAction extends Serializable {
//     void execute(FileSystem fileSystem, Path filePath) throws IOException;
// }


// Path: src/main/java/org/apache/storm/hdfs/bolt/SequenceFileBolt.java
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.net.URI;
import java.util.Map;
import backtype.storm.task.OutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.tuple.Tuple;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.SequenceFile;
import org.apache.hadoop.io.compress.CompressionCodecFactory;
import org.apache.storm.hdfs.bolt.format.FileNameFormat;
import org.apache.storm.hdfs.bolt.format.SequenceFormat;
import org.apache.storm.hdfs.bolt.rotation.FileRotationPolicy;
import org.apache.storm.hdfs.bolt.sync.SyncPolicy;
import org.apache.storm.hdfs.common.rotation.RotationAction;
import org.slf4j.Logger;

/**
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.storm.hdfs.bolt;



public class SequenceFileBolt extends AbstractHdfsBolt {
    private static final Logger LOG = LoggerFactory.getLogger(SequenceFileBolt.class);

    private SequenceFormat format;
    private SequenceFile.CompressionType compressionType = SequenceFile.CompressionType.RECORD;
    private transient SequenceFile.Writer writer;

    private String compressionCodec = "default";
    private transient CompressionCodecFactory codecFactory;

    public SequenceFileBolt() {
    }

    public SequenceFileBolt withCompressionCodec(String codec){
        this.compressionCodec = codec;
        return this;
    }

    public SequenceFileBolt withFsUrl(String fsUrl) {
        this.fsUrl = fsUrl;
        return this;
    }

    public SequenceFileBolt withConfigKey(String configKey){
        this.configKey = configKey;
        return this;
    }

    public SequenceFileBolt withFileNameFormat(FileNameFormat fileNameFormat) {