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.fs;
019    
020    import java.io.DataInput;
021    import java.io.DataOutput;
022    import java.io.IOException;
023    
024    import org.apache.hadoop.classification.InterfaceAudience;
025    import org.apache.hadoop.classification.InterfaceStability;
026    import org.apache.hadoop.io.Writable;
027    import org.apache.hadoop.io.WritableFactories;
028    import org.apache.hadoop.io.WritableFactory;
029    import org.apache.hadoop.io.WritableUtils;
030    import org.apache.hadoop.util.DataChecksum;
031    
032    /****************************************************
033     * Provides server default configuration values to clients.
034     * 
035     ****************************************************/
036    @InterfaceAudience.Public
037    @InterfaceStability.Evolving
038    public class FsServerDefaults implements Writable {
039    
040      static { // register a ctor
041        WritableFactories.setFactory(FsServerDefaults.class, new WritableFactory() {
042          @Override
043          public Writable newInstance() {
044            return new FsServerDefaults();
045          }
046        });
047      }
048    
049      private long blockSize;
050      private int bytesPerChecksum;
051      private int writePacketSize;
052      private short replication;
053      private int fileBufferSize;
054      private boolean encryptDataTransfer;
055      private long trashInterval;
056      private DataChecksum.Type checksumType;
057    
058      public FsServerDefaults() {
059      }
060    
061      public FsServerDefaults(long blockSize, int bytesPerChecksum,
062          int writePacketSize, short replication, int fileBufferSize,
063          boolean encryptDataTransfer, long trashInterval,
064          DataChecksum.Type checksumType) {
065        this.blockSize = blockSize;
066        this.bytesPerChecksum = bytesPerChecksum;
067        this.writePacketSize = writePacketSize;
068        this.replication = replication;
069        this.fileBufferSize = fileBufferSize;
070        this.encryptDataTransfer = encryptDataTransfer;
071        this.trashInterval = trashInterval;
072        this.checksumType = checksumType;
073      }
074    
075      public long getBlockSize() {
076        return blockSize;
077      }
078    
079      public int getBytesPerChecksum() {
080        return bytesPerChecksum;
081      }
082    
083      public int getWritePacketSize() {
084        return writePacketSize;
085      }
086    
087      public short getReplication() {
088        return replication;
089      }
090    
091      public int getFileBufferSize() {
092        return fileBufferSize;
093      }
094      
095      public boolean getEncryptDataTransfer() {
096        return encryptDataTransfer;
097      }
098    
099      public long getTrashInterval() {
100        return trashInterval;
101      }
102    
103      public DataChecksum.Type getChecksumType() {
104        return checksumType;
105      }
106    
107      // /////////////////////////////////////////
108      // Writable
109      // /////////////////////////////////////////
110      @Override
111      @InterfaceAudience.Private
112      public void write(DataOutput out) throws IOException {
113        out.writeLong(blockSize);
114        out.writeInt(bytesPerChecksum);
115        out.writeInt(writePacketSize);
116        out.writeShort(replication);
117        out.writeInt(fileBufferSize);
118        WritableUtils.writeEnum(out, checksumType);
119      }
120    
121      @Override
122      @InterfaceAudience.Private
123      public void readFields(DataInput in) throws IOException {
124        blockSize = in.readLong();
125        bytesPerChecksum = in.readInt();
126        writePacketSize = in.readInt();
127        replication = in.readShort();
128        fileBufferSize = in.readInt();
129        checksumType = WritableUtils.readEnum(in, DataChecksum.Type.class);
130      }
131    }