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 */ 018package org.apache.hadoop.fs; 019 020import java.io.DataInput; 021import java.io.DataOutput; 022import java.io.IOException; 023 024import org.apache.hadoop.classification.InterfaceAudience; 025import org.apache.hadoop.classification.InterfaceStability; 026import org.apache.hadoop.io.Writable; 027import org.apache.hadoop.io.WritableFactories; 028import org.apache.hadoop.io.WritableFactory; 029import org.apache.hadoop.io.WritableUtils; 030import org.apache.hadoop.util.DataChecksum; 031 032/**************************************************** 033 * Provides server default configuration values to clients. 034 * 035 ****************************************************/ 036@InterfaceAudience.Public 037@InterfaceStability.Evolving 038public 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 private String keyProviderUri; 058 059 public FsServerDefaults() { 060 } 061 062 public FsServerDefaults(long blockSize, int bytesPerChecksum, 063 int writePacketSize, short replication, int fileBufferSize, 064 boolean encryptDataTransfer, long trashInterval, 065 DataChecksum.Type checksumType, 066 String keyProviderUri) { 067 this.blockSize = blockSize; 068 this.bytesPerChecksum = bytesPerChecksum; 069 this.writePacketSize = writePacketSize; 070 this.replication = replication; 071 this.fileBufferSize = fileBufferSize; 072 this.encryptDataTransfer = encryptDataTransfer; 073 this.trashInterval = trashInterval; 074 this.checksumType = checksumType; 075 this.keyProviderUri = keyProviderUri; 076 } 077 078 public long getBlockSize() { 079 return blockSize; 080 } 081 082 public int getBytesPerChecksum() { 083 return bytesPerChecksum; 084 } 085 086 public int getWritePacketSize() { 087 return writePacketSize; 088 } 089 090 public short getReplication() { 091 return replication; 092 } 093 094 public int getFileBufferSize() { 095 return fileBufferSize; 096 } 097 098 public boolean getEncryptDataTransfer() { 099 return encryptDataTransfer; 100 } 101 102 public long getTrashInterval() { 103 return trashInterval; 104 } 105 106 public DataChecksum.Type getChecksumType() { 107 return checksumType; 108 } 109 110 /* null means old style namenode. 111 * "" (empty string) means namenode is upgraded but EZ is not supported. 112 * some string means that value is the key provider. 113 */ 114 public String getKeyProviderUri() { 115 return keyProviderUri; 116 } 117 118 // ///////////////////////////////////////// 119 // Writable 120 // ///////////////////////////////////////// 121 @Override 122 @InterfaceAudience.Private 123 public void write(DataOutput out) throws IOException { 124 out.writeLong(blockSize); 125 out.writeInt(bytesPerChecksum); 126 out.writeInt(writePacketSize); 127 out.writeShort(replication); 128 out.writeInt(fileBufferSize); 129 WritableUtils.writeEnum(out, checksumType); 130 } 131 132 @Override 133 @InterfaceAudience.Private 134 public void readFields(DataInput in) throws IOException { 135 blockSize = in.readLong(); 136 bytesPerChecksum = in.readInt(); 137 writePacketSize = in.readInt(); 138 replication = in.readShort(); 139 fileBufferSize = in.readInt(); 140 checksumType = WritableUtils.readEnum(in, DataChecksum.Type.class); 141 } 142}