mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-23 23:06:39 +01:00
Add license comment, stop & toString methods, and make isRunning transient
This commit is contained in:
parent
89e2187878
commit
a5ed17e43f
1 changed files with 36 additions and 6 deletions
|
@ -1,3 +1,20 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Bisq.
|
||||||
|
*
|
||||||
|
* Bisq is free software: you can redistribute it and/or modify it
|
||||||
|
* under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or (at
|
||||||
|
* your option) any later version.
|
||||||
|
*
|
||||||
|
* Bisq is distributed in the hope that it will be useful, but WITHOUT
|
||||||
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public
|
||||||
|
* License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with Bisq. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
package bisq.daemon.grpc.interceptor;
|
package bisq.daemon.grpc.interceptor;
|
||||||
|
|
||||||
import bisq.common.Timer;
|
import bisq.common.Timer;
|
||||||
|
@ -21,12 +38,10 @@ public final class GrpcCallRateMeter {
|
||||||
private final int allowedCallsPerTimeUnit;
|
private final int allowedCallsPerTimeUnit;
|
||||||
@Getter
|
@Getter
|
||||||
private final TimeUnit timeUnit;
|
private final TimeUnit timeUnit;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private int callsCount = 0;
|
private int callsCount = 0;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private boolean isRunning;
|
private transient boolean isRunning;
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private Timer timer;
|
private Timer timer;
|
||||||
|
@ -37,11 +52,16 @@ public final class GrpcCallRateMeter {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void start() {
|
public void start() {
|
||||||
|
stop();
|
||||||
|
timer = UserThread.runPeriodically(() -> callsCount = 0, 1, timeUnit);
|
||||||
|
isRunning = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stop() {
|
||||||
if (timer != null)
|
if (timer != null)
|
||||||
timer.stop();
|
timer.stop();
|
||||||
|
|
||||||
timer = UserThread.runPeriodically(() -> callsCount = 0, 1, timeUnit);
|
isRunning = false;
|
||||||
isRunning = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void incrementCallsCount() {
|
public void incrementCallsCount() {
|
||||||
|
@ -54,7 +74,7 @@ public final class GrpcCallRateMeter {
|
||||||
|
|
||||||
public String getCallsCountProgress(String calledMethodName) {
|
public String getCallsCountProgress(String calledMethodName) {
|
||||||
String shortTimeUnitName = StringUtils.chop(timeUnit.name().toLowerCase());
|
String shortTimeUnitName = StringUtils.chop(timeUnit.name().toLowerCase());
|
||||||
return format("%s has been called %d time%s in the last %s; the rate limit is %d/%s.",
|
return format("%s has been called %d time%s in the last %s, rate limit is %d/%s",
|
||||||
calledMethodName,
|
calledMethodName,
|
||||||
callsCount,
|
callsCount,
|
||||||
callsCount == 1 ? "" : "s",
|
callsCount == 1 ? "" : "s",
|
||||||
|
@ -62,4 +82,14 @@ public final class GrpcCallRateMeter {
|
||||||
allowedCallsPerTimeUnit,
|
allowedCallsPerTimeUnit,
|
||||||
shortTimeUnitName);
|
shortTimeUnitName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "GrpcCallRateMeter{" +
|
||||||
|
"allowedCallsPerTimeUnit=" + allowedCallsPerTimeUnit +
|
||||||
|
", timeUnit=" + timeUnit.name() +
|
||||||
|
", callsCount=" + callsCount +
|
||||||
|
", isRunning=" + isRunning +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue