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 public Writable newInstance() {
043 return new FsServerDefaults();
044 }
045 });
046 }
047
048 private long blockSize;
049 private int bytesPerChecksum;
050 private int writePacketSize;
051 private short replication;
052 private int fileBufferSize;
053 private DataChecksum.Type checksumType;
054
055 public FsServerDefaults() {
056 }
057
058 public FsServerDefaults(long blockSize, int bytesPerChecksum,
059 int writePacketSize, short replication, int fileBufferSize,
060 DataChecksum.Type checksumType) {
061 this.blockSize = blockSize;
062 this.bytesPerChecksum = bytesPerChecksum;
063 this.writePacketSize = writePacketSize;
064 this.replication = replication;
065 this.fileBufferSize = fileBufferSize;
066 this.checksumType = checksumType;
067 }
068
069 public long getBlockSize() {
070 return blockSize;
071 }
072
073 public int getBytesPerChecksum() {
074 return bytesPerChecksum;
075 }
076
077 public int getWritePacketSize() {
078 return writePacketSize;
079 }
080
081 public short getReplication() {
082 return replication;
083 }
084
085 public int getFileBufferSize() {
086 return fileBufferSize;
087 }
088
089 public DataChecksum.Type getChecksumType() {
090 return checksumType;
091 }
092
093 // /////////////////////////////////////////
094 // Writable
095 // /////////////////////////////////////////
096 @InterfaceAudience.Private
097 public void write(DataOutput out) throws IOException {
098 out.writeLong(blockSize);
099 out.writeInt(bytesPerChecksum);
100 out.writeInt(writePacketSize);
101 out.writeShort(replication);
102 out.writeInt(fileBufferSize);
103 WritableUtils.writeEnum(out, checksumType);
104 }
105
106 @InterfaceAudience.Private
107 public void readFields(DataInput in) throws IOException {
108 blockSize = in.readLong();
109 bytesPerChecksum = in.readInt();
110 writePacketSize = in.readInt();
111 replication = in.readShort();
112 fileBufferSize = in.readInt();
113 checksumType = WritableUtils.readEnum(in, DataChecksum.Type.class);
114 }
115 }