@Put
@At("/:port/limit")
public Reply<?> limit(@Named("port") int port, Request request) {
ProxyServer proxy = proxyManager.get(port);
StreamManager streamManager = proxy.getStreamManager();
String upstreamKbps = request.param("upstreamKbps");
if (upstreamKbps != null) {
try {
streamManager.setUpstreamKbps(Integer.parseInt(upstreamKbps));
streamManager.enable();
} catch (NumberFormatException e) { }
}
String downstreamKbps = request.param("downstreamKbps");
if (downstreamKbps != null) {
try {
streamManager.setDownstreamKbps(Integer.parseInt(downstreamKbps));
streamManager.enable();
} catch (NumberFormatException e) { }
}
String latency = request.param("latency");
if (latency != null) {
try {
streamManager.setLatency(Integer.parseInt(latency));
streamManager.enable();
} catch (NumberFormatException e) { }
}
String payloadPercentage = request.param("payloadPercentage");
if (payloadPercentage != null) {
try {
streamManager.setPayloadPercentage(Integer.parseInt(payloadPercentage));
} catch (NumberFormatException e) { }
}
String maxBitsPerSecond = request.param("maxBitsPerSecond");
if (maxBitsPerSecond != null) {
try {
streamManager.setMaxBitsPerSecondThreshold(Integer.parseInt(maxBitsPerSecond));
} catch (NumberFormatException e) { }
}
String enable = request.param("enable");
if (enable != null) {
if( Boolean.parseBoolean(enable) ) {
streamManager.enable();
} else {
streamManager.disable();
}
}
return Reply.saying().ok();
}