blob: a5115d6c358b414aed2e324a725ed08c9eb55426 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.model.admin;
import com.yahoo.binaryprefix.BinaryPrefix;
import com.yahoo.binaryprefix.BinaryScaledAmount;
import com.yahoo.cloud.config.filedistribution.FiledistributorConfig;
/**
* Options for controlling the behavior of the file distribution services.
* @author tonytv
*/
public class FileDistributionOptions implements FiledistributorConfig.Producer {
public static FileDistributionOptions defaultOptions() {
return new FileDistributionOptions();
}
private FileDistributionOptions() {}
private BinaryScaledAmount uploadbitrate = new BinaryScaledAmount();
private BinaryScaledAmount downloadbitrate = new BinaryScaledAmount();
//Called through reflection
public void downloadbitrate(BinaryScaledAmount amount) {
ensureNonNegative(amount);
downloadbitrate = amount;
}
//Called through reflection
public void uploadbitrate(BinaryScaledAmount amount) {
ensureNonNegative(amount);
uploadbitrate = amount;
}
private void ensureNonNegative(BinaryScaledAmount amount) {
if (amount.amount < 0)
throw new IllegalArgumentException("Expected non-negative number, got " + amount.amount);
}
private int byteRate(BinaryScaledAmount bitRate) {
BinaryScaledAmount byteRate = bitRate.divide(8);
return (int)byteRate.as(BinaryPrefix.unit);
}
@Override
public void getConfig(FiledistributorConfig.Builder builder) {
builder.maxuploadspeed((double)byteRate(uploadbitrate));
builder.maxdownloadspeed((double)byteRate(downloadbitrate));
}
}
|