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.web.resources;
019    
020    import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_REPLICATION_DEFAULT;
021    import static org.apache.hadoop.hdfs.DFSConfigKeys.DFS_REPLICATION_KEY;
022    
023    import org.apache.hadoop.conf.Configuration;
024    
025    /** Replication parameter. */
026    public class ReplicationParam extends ShortParam {
027      /** Parameter name. */
028      public static final String NAME = "replication";
029      /** Default parameter value. */
030      public static final String DEFAULT = NULL;
031    
032      private static final Domain DOMAIN = new Domain(NAME);
033    
034      /**
035       * Constructor.
036       * @param value the parameter value.
037       */
038      public ReplicationParam(final Short value) {
039        super(DOMAIN, value, (short)1, null);
040      }
041    
042      /**
043       * Constructor.
044       * @param str a string representation of the parameter value.
045       */
046      public ReplicationParam(final String str) {
047        this(DOMAIN.parse(str));
048      }
049    
050      @Override
051      public String getName() {
052        return NAME;
053      }
054    
055      /** @return the value or, if it is null, return the default from conf. */
056      public short getValue(final Configuration conf) {
057        return getValue() != null? getValue()
058            : (short)conf.getInt(DFS_REPLICATION_KEY, DFS_REPLICATION_DEFAULT);
059      }
060    }