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.protocol;
019    
020    /*
021     * A system administrator can tune the balancer bandwidth parameter
022     * (dfs.balance.bandwidthPerSec) dynamically by calling
023     * "dfsadmin -setBalanacerBandwidth newbandwidth".
024     * This class is to define the command which sends the new bandwidth value to
025     * each datanode.
026     */
027    
028    /**
029     * Balancer bandwidth command instructs each datanode to change its value for
030     * the max amount of network bandwidth it may use during the block balancing
031     * operation.
032     * 
033     * The Balancer Bandwidth Command contains the new bandwidth value as its
034     * payload. The bandwidth value is in bytes per second.
035     */
036    public class BalancerBandwidthCommand extends DatanodeCommand {
037      private final static long BBC_DEFAULTBANDWIDTH = 0L;
038    
039      private final long bandwidth;
040    
041      /**
042       * Balancer Bandwidth Command constructor. Sets bandwidth to 0.
043       */
044      BalancerBandwidthCommand() {
045        this(BBC_DEFAULTBANDWIDTH);
046      }
047    
048      /**
049       * Balancer Bandwidth Command constructor.
050       *
051       * @param bandwidth Blanacer bandwidth in bytes per second.
052       */
053      public BalancerBandwidthCommand(long bandwidth) {
054        super(DatanodeProtocol.DNA_BALANCERBANDWIDTHUPDATE);
055        this.bandwidth = bandwidth;
056      }
057    
058      /**
059       * Get current value of the max balancer bandwidth in bytes per second.
060       *
061       * @return bandwidth Blanacer bandwidth in bytes per second for this datanode.
062       */
063      public long getBalancerBandwidthValue() {
064        return this.bandwidth;
065      }
066    }