Construct a throttler from conf
@param conf configuration
@return a data transfer throttler
500001
public static final DataTransferThrottler getThrottler(Configuration conf, 
      boolean disableThrottler) {
    if (disableThrottler) {
      return null;
    }
    long transferBandwidth = 
      conf.getLong(HdfsConstants.DFS_IMAGE_TRANSFER_RATE_KEY,
          HdfsConstants.DFS_IMAGE_TRANSFER_RATE_DEFAULT);
    DataTransferThrottler throttler = null;
    if (transferBandwidth > 0) {
      throttler = new DataTransferThrottler(transferBandwidth);
    }
    return throttler;
  }
42729
def add_connection_throttle(self, loadbalancer, maxConnectionRate=None,
            maxConnections=None, minConnections=None, rateInterval=None):
        
        return loadbalancer.add_connection_throttle(
                maxConnectionRate=maxConnectionRate, maxConnections=maxConnections,
                minConnections=minConnections, rateInterval=rateInterval)
1356192
protected Connector createBaseListener(Configuration conf)
      throws IOException {
    Connector ret;
    if (conf.getBoolean("hadoop.http.bio", false)) {
      SocketConnector conn = new SocketConnector();
      conn.setAcceptQueueSize(4096);
      conn.setResolveNames(false);
      ret = conn;
    } else {
      SelectChannelConnector conn = new SelectChannelConnector();
      conn.setAcceptQueueSize(128);
      conn.setResolveNames(false);
      conn.setUseDirectBuffers(false);
      ret = conn;
    }
    ret.setLowResourceMaxIdleTime(10000);
    ret.setHeaderBufferSize(conf.getInt("hadoop.http.header.buffer.size", 4096));
    ret.setMaxIdleTime(conf.getInt("dfs.http.timeout", 200000));
    return ret;
  }
1237542
public static BackoffIdleStrategy createBackoffIdleStrategy(String config) {
        String[] args = config.split(",");
        if (args.length != ARG_COUNT) {
            throw new IllegalArgumentException(
                    format("Invalid backoff configuration '%s', 4 arguments expected", config));
        }
        long maxSpins = parseLong(args[ARG_MAX_SPINS]);
        long maxYields = parseLong(args[ARG_MAX_YIELDS]);
        long minParkPeriodNs = parseLong(args[ARG_MIN_PARK_PERIOD]);
        long maxParkNanos = parseLong(args[ARG_MAX_PARK_PERIOD]);
        return new BackoffIdleStrategy(maxSpins, maxYields, minParkPeriodNs, maxParkNanos);
    }
662624
private static Map<byte[], byte[]> createCfRenameMap(Configuration conf) {
    Map<byte[], byte[]> cfRenameMap = null;
    String allMappingsPropVal = conf.get(CF_RENAME_PROP);
    if(allMappingsPropVal != null) {
      // The conf value format should be sourceCf1:destCf1,sourceCf2:destCf2,...
      String[] allMappings = allMappingsPropVal.split(",");
      for (String mapping: allMappings) {
        if(cfRenameMap == null) {
            cfRenameMap = new TreeMap<byte[],byte[]>(Bytes.BYTES_COMPARATOR);
        }
        String [] srcAndDest = mapping.split(":");
        if(srcAndDest.length != 2) {
            continue;
        }
        cfRenameMap.put(srcAndDest[0].getBytes(), srcAndDest[1].getBytes());
      }
    }
    return cfRenameMap;
  }
410227
public SSLEngine buildClientSSLEngine(String host, int port) {
        SSLEngine engine = sslContext.createSSLEngine(host, port);
        engine.setUseClientMode(true);
        return addCommonConfigs(engine);
    }
79605
public static InetSocketAddress getAddress(Configuration conf) {
    String addr = conf.get(JournalConfigKeys.DFS_JOURNALNODE_HTTP_ADDRESS_KEY,
        JournalConfigKeys.DFS_JOURNALNODE_HTTP_ADDRESS_DEFAULT);
    return NetUtils.createSocketAddr(addr,
        JournalConfigKeys.DFS_JOURNALNODE_HTTP_PORT_DEFAULT);
  }
393152
private CodecFactory getCompressionCodec(Map<String, String> conf) {
		if (getBoolean(conf, CONF_COMPRESS, false)) {
			int deflateLevel = getInt(conf, CONF_DEFLATE_LEVEL, CodecFactory.DEFAULT_DEFLATE_LEVEL);
			int xzLevel = getInt(conf, CONF_XZ_LEVEL, CodecFactory.DEFAULT_XZ_LEVEL);

			String outputCodec = conf.get(CONF_COMPRESS_CODEC);

			if (DataFileConstants.DEFLATE_CODEC.equals(outputCodec)) {
				return CodecFactory.deflateCodec(deflateLevel);
			} else if (DataFileConstants.XZ_CODEC.equals(outputCodec)) {
				return CodecFactory.xzCodec(xzLevel);
			} else {
				return CodecFactory.fromString(outputCodec);
			}
		}
		return CodecFactory.nullCodec();
	}
1208353
public static RedisSingleServerConfig buildRedisConfig(String host, int port, String password) {
        RedisSingleServerConfig config = new RedisSingleServerConfig();
        config.setAddress(host + ":" + port);
        config.setPassword(password);
        return config;
    }
264214
function throttleable(duration, options) {
    return function innerDecorator(target, key, descriptor) {
        return {
            configurable: true,
            enumerable: descriptor.enumerable,
            get: function getter() {
                Object.defineProperty(this, key, {
                    configurable: true,
                    enumerable: descriptor.enumerable,
                    value: throttle(descriptor.value, duration, options)
                });
                return this[key];
            }
        };
    };
}
51950
function throttle(f, delay) {
  var timeoutId;
  var previous = 0;

  return function throttleExecute_() {
    var args = arguments;
    var now = +(new Date());
    var remaining = delay - (now - previous);

    if (remaining <= 0) {
      clearTimeout(timeoutId);
      timeoutId = null;
      previous = now;

      f.apply(null, args);
    } else if (!timeoutId) {
      timeoutId = setTimeout(function() {
        previous = +(new Date());
        timeoutId = null;

        f.apply(null, args);
      }, remaining);
    }
  };
}
951626
private void throttledTransfer(MockResponse throttlePolicy, InputStream in, OutputStream out,
            long limit) throws IOException {
        byte[] buffer = new byte[1024];
        int bytesPerPeriod = throttlePolicy.getThrottleBytesPerPeriod();
        long delayMs = throttlePolicy.getThrottleUnit().toMillis(throttlePolicy.getThrottlePeriod());

        while (true) {
            for (int b = 0; b < bytesPerPeriod; ) {
                int toRead = (int) Math.min(Math.min(buffer.length, limit), bytesPerPeriod - b);
                int read = in.read(buffer, 0, toRead);
                if (read == -1) return;

                out.write(buffer, 0, read);
                out.flush();
                b += read;
                limit -= read;

                if (limit == 0) return;
            }

            try {
                if (delayMs != 0) Thread.sleep(delayMs);
            } catch (InterruptedException e) {
                throw new AssertionError();
            }
        }
    }
827319
def cli(conf):
    
    config = init_config(conf)
    nas_id = config.get('DEFAULT', 'nas_id')
    nas_addr = config.get('DEFAULT', 'nas_addr')
    secret = config.get('DEFAULT', 'radius_secret')
    radius_addr = config.get('DEFAULT', 'radius_addr')
    radius_auth_port = config.getint('DEFAULT', 'radius_auth_port')
    radius_timeout = config.getint('DEFAULT', 'radius_timeout')
    client_config_dir = config.get('DEFAULT', 'client_config_dir')

    username = os.environ.get('username')

    req = {'User-Name':username}
    req['CHAP-Challenge'] = get_challenge()
    req['CHAP-Password-Plaintext'] = os.environ.get('password')
    req["NAS-IP-Address"]     = nas_addr
    req["NAS-Port-Id"]     = '0/0/0:0.0'
    req["NAS-Port"]           = 0
    req["Service-Type"]       = "Login-User"
    req["NAS-Identifier"]     = nas_id
    req["Called-Station-Id"]  = '00:00:00:00:00:00'
    req["Calling-Station-Id"] = '00:00:00:00:00:00'
    # req["Framed-IP-Address"]  = os.environ.get('ifconfig_pool_remote_ip')
    # log.msg("radius auth: %s" % repr(req))

    def shutdown(exitcode=0):
        reactor.addSystemEventTrigger('after', 'shutdown', os._exit,exitcode)
        reactor.stop()

    def onresp(r):
        if r.code == packet.AccessAccept:
            try:
                ccdattrs = []
                userip = get_radius_addr_attr(r,8)
                if userip:
                    ccdattrs.append('ifconfig-push {0} 255.255.255.0'.format(userip))
                with open(os.path.join(client_config_dir,username),'wb') as ccdfs:
                    ccdfs.write('\n'.join(ccdattrs))
            except:
                traceback.print_exc()
            shutdown(0)
        else:
            shutdown(1)
            
    def onerr(e):
        log.err(e)
        shutdown(1)

    d = client.send_auth(str(secret), 
        get_dictionary(), radius_addr, authport=radius_auth_port, debug=True,**req)
    d.addCallbacks(onresp,onerr)
    reactor.callLater(radius_timeout,shutdown,1)
    reactor.run()
364691
public static IHttpCredentialsPlugin GetDrpcHttpCredentialsPlugin(Map conf) {
        String klassName = (String) conf.get(Config.DRPC_HTTP_CREDS_PLUGIN);
        return AuthUtils.GetHttpCredentialsPlugin(conf, klassName);
    }
936963
static ManagedChannelServiceConfig fromServiceConfig(
      Map<String, ?> serviceConfig,
      boolean retryEnabled,
      int maxRetryAttemptsLimit,
      int maxHedgedAttemptsLimit,
      @Nullable Object loadBalancingConfig) {
    Throttle retryThrottling = null;
    if (retryEnabled) {
      retryThrottling = ServiceConfigUtil.getThrottlePolicy(serviceConfig);
    }
    Map<String, MethodInfo> serviceMethodMap = new HashMap<>();
    Map<String, MethodInfo> serviceMap = new HashMap<>();

    // Try and do as much validation here before we swap out the existing configuration.  In case
    // the input is invalid, we don't want to lose the existing configuration.
    List<Map<String, ?>> methodConfigs =
        ServiceConfigUtil.getMethodConfigFromServiceConfig(serviceConfig);

    if (methodConfigs == null) {
      // this is surprising, but possible.
      return new ManagedChannelServiceConfig(
          serviceMethodMap, serviceMap, retryThrottling, loadBalancingConfig);
    }

    for (Map<String, ?> methodConfig : methodConfigs) {
      MethodInfo info = new MethodInfo(
          methodConfig, retryEnabled, maxRetryAttemptsLimit, maxHedgedAttemptsLimit);

      List<Map<String, ?>> nameList =
          ServiceConfigUtil.getNameListFromMethodConfig(methodConfig);

      checkArgument(
          nameList != null && !nameList.isEmpty(), "no names in method config %s", methodConfig);
      for (Map<String, ?> name : nameList) {
        String serviceName = ServiceConfigUtil.getServiceFromName(name);
        checkArgument(!Strings.isNullOrEmpty(serviceName), "missing service name");
        String methodName = ServiceConfigUtil.getMethodFromName(name);
        if (Strings.isNullOrEmpty(methodName)) {
          // Service scoped config
          checkArgument(
              !serviceMap.containsKey(serviceName), "Duplicate service %s", serviceName);
          serviceMap.put(serviceName, info);
        } else {
          // Method scoped config
          String fullMethodName = MethodDescriptor.generateFullMethodName(serviceName, methodName);
          checkArgument(
              !serviceMethodMap.containsKey(fullMethodName),
              "Duplicate method name %s",
              fullMethodName);
          serviceMethodMap.put(fullMethodName, info);
        }
      }
    }

    return new ManagedChannelServiceConfig(
        serviceMethodMap, serviceMap, retryThrottling, loadBalancingConfig);
  }
714602
@SuppressWarnings("deprecation")
  private static JobConf createJobConfForCopyByChunk(Configuration conf) {
    JobConf jobconf = new JobConf(conf, DistCp.class);
    jobconf.setJobName(NAME);

    // turn off speculative execution, because DFS doesn't handle
    // multiple writers to the same file.
    jobconf.setReduceSpeculativeExecution(false);

    jobconf.setMapOutputKeyClass(Text.class);
    jobconf.setMapOutputValueClass(IntWritable.class);
    jobconf.setOutputKeyClass(Text.class);
    jobconf.setOutputValueClass(Text.class);

    jobconf.setInputFormat(CopyByChunkInputFormat.class);
    jobconf.setMapperClass(CopyFilesByChunkMapper.class);
    jobconf.setReducerClass(CopyFilesByChunkReducer.class);
    
    // Prevent the reducer from starting until all maps are done.
    jobconf.setInt("mapred.job.rushreduce.reduce.threshold", 0);
    jobconf.setFloat("mapred.reduce.slowstart.completed.maps", 1.0f);
    
    return jobconf;
  }
1309080
private CompletableFuture<Void> throttle() {
        val delay = new AtomicReference<ThrottlerCalculator.DelayResult>(this.throttlerCalculator.getThrottlingDelay());
        if (!delay.get().isMaximum()) {
            // We are not delaying the maximum amount. We only need to do this once.
            return throttleOnce(delay.get().getDurationMillis(), delay.get().isMaximum());
        } else {
            // The initial delay calculation indicated that we need to throttle to the maximum, which means there's
            // significant pressure. In order to protect downstream components, we need to run in a loop and delay as much
            // as needed until the pressure is relieved.
            return Futures.loop(
                    () -> !delay.get().isMaximum(),
                    () -> throttleOnce(delay.get().getDurationMillis(), delay.get().isMaximum())
                            .thenRun(() -> delay.set(this.throttlerCalculator.getThrottlingDelay())),
                    this.executor);
        }
    }