001    /**
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *     http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    package org.apache.hadoop.hdfs.server.datanode;
019    
020    import java.io.IOException;
021    
022    import org.apache.hadoop.hdfs.server.datanode.fsdataset.ReplicaOutputStreams;
023    import org.apache.hadoop.util.DataChecksum;
024    
025    /** 
026     * This defines the interface of a replica in Pipeline that's being written to
027     */
028    public interface ReplicaInPipelineInterface extends Replica {
029      /**
030       * Set the number of bytes received
031       * @param bytesReceived number of bytes received
032       */
033      void setNumBytes(long bytesReceived);
034      
035      /**
036       * Get the number of bytes acked
037       * @return the number of bytes acked
038       */
039      long getBytesAcked();
040      
041      /**
042       * Set the number bytes that have acked
043       * @param bytesAcked
044       */
045      void setBytesAcked(long bytesAcked);
046      
047      /**
048       * store the checksum for the last chunk along with the data length
049       * @param dataLength number of bytes on disk
050       * @param lastChecksum - checksum bytes for the last chunk
051       */
052      public void setLastChecksumAndDataLen(long dataLength, byte[] lastChecksum);
053      
054      /**
055       * gets the last chunk checksum and the length of the block corresponding
056       * to that checksum
057       */
058      public ChunkChecksum getLastChecksumAndDataLen();
059      
060      /**
061       * Create output streams for writing to this replica, 
062       * one for block file and one for CRC file
063       * 
064       * @param isCreate if it is for creation
065       * @param requestedChecksum the checksum the writer would prefer to use
066       * @return output streams for writing
067       * @throws IOException if any error occurs
068       */
069      public ReplicaOutputStreams createStreams(boolean isCreate,
070          DataChecksum requestedChecksum) throws IOException;
071    }