mirror of
https://github.com/bisq-network/bisq.git
synced 2025-02-22 22:45:21 +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;
|
||||
|
||||
import bisq.common.Timer;
|
||||
|
@ -21,12 +38,10 @@ public final class GrpcCallRateMeter {
|
|||
private final int allowedCallsPerTimeUnit;
|
||||
@Getter
|
||||
private final TimeUnit timeUnit;
|
||||
|
||||
@Getter
|
||||
private int callsCount = 0;
|
||||
|
||||
@Getter
|
||||
private boolean isRunning;
|
||||
private transient boolean isRunning;
|
||||
|
||||
@Nullable
|
||||
private Timer timer;
|
||||
|
@ -37,11 +52,16 @@ public final class GrpcCallRateMeter {
|
|||
}
|
||||
|
||||
public void start() {
|
||||
stop();
|
||||
timer = UserThread.runPeriodically(() -> callsCount = 0, 1, timeUnit);
|
||||
isRunning = true;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (timer != null)
|
||||
timer.stop();
|
||||
|
||||
timer = UserThread.runPeriodically(() -> callsCount = 0, 1, timeUnit);
|
||||
isRunning = true;
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
public void incrementCallsCount() {
|
||||
|
@ -54,7 +74,7 @@ public final class GrpcCallRateMeter {
|
|||
|
||||
public String getCallsCountProgress(String calledMethodName) {
|
||||
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,
|
||||
callsCount,
|
||||
callsCount == 1 ? "" : "s",
|
||||
|
@ -62,4 +82,14 @@ public final class GrpcCallRateMeter {
|
|||
allowedCallsPerTimeUnit,
|
||||
shortTimeUnitName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "GrpcCallRateMeter{" +
|
||||
"allowedCallsPerTimeUnit=" + allowedCallsPerTimeUnit +
|
||||
", timeUnit=" + timeUnit.name() +
|
||||
", callsCount=" + callsCount +
|
||||
", isRunning=" + isRunning +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue