1
0
mirror of https://github.com/google/nomulus synced 2026-07-19 22:42:23 +00:00

Remove more usage of AutoValue (#2432)

This PR also removes `SerializedForm` used to serialize
`PendingDeposit`, as it is now a simple record.
This commit is contained in:
Lai Jiang
2024-05-07 20:50:01 -04:00
committed by GitHub
parent ca072b4861
commit 73d3b76a89
13 changed files with 144 additions and 230 deletions
@@ -59,7 +59,7 @@ public abstract class QuotaHandler extends ChannelInboundHandlerAdapter {
if (quotaResponse == null) {
String userId = getUserId(ctx);
checkNotNull(userId, "Cannot obtain User ID");
quotaResponse = quotaManager.acquireQuota(QuotaRequest.create(userId));
quotaResponse = quotaManager.acquireQuota(new QuotaRequest(userId));
if (!quotaResponse.success()) {
String protocolName = ctx.channel().attr(PROTOCOL_KEY).get().name();
metrics.registerQuotaRejection(protocolName, isUserIdPii() ? "none" : userId);
@@ -14,7 +14,6 @@
package google.registry.proxy.quota;
import com.google.auto.value.AutoValue;
import google.registry.proxy.quota.TokenStore.TimestampedInteger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@@ -40,42 +39,16 @@ import org.joda.time.DateTime;
public class QuotaManager {
/** Value class representing a quota request. */
@AutoValue
public abstract static class QuotaRequest {
public static QuotaRequest create(String userId) {
return new AutoValue_QuotaManager_QuotaRequest(userId);
}
abstract String userId();
}
public record QuotaRequest(String userId) {}
/** Value class representing a quota response. */
@AutoValue
public abstract static class QuotaResponse {
public static QuotaResponse create(
boolean success, String userId, DateTime grantedTokenRefillTime) {
return new AutoValue_QuotaManager_QuotaResponse(success, userId, grantedTokenRefillTime);
}
public abstract boolean success();
abstract String userId();
abstract DateTime grantedTokenRefillTime();
}
public record QuotaResponse(boolean success, String userId, DateTime grantedTokenRefillTime) {}
/** Value class representing a quota rebate. */
@AutoValue
public abstract static class QuotaRebate {
public record QuotaRebate(String userId, DateTime grantedTokenRefillTime) {
public static QuotaRebate create(QuotaResponse response) {
return new AutoValue_QuotaManager_QuotaRebate(
response.userId(), response.grantedTokenRefillTime());
return new QuotaRebate(response.userId(), response.grantedTokenRefillTime());
}
abstract String userId();
abstract DateTime grantedTokenRefillTime();
}
private final TokenStore tokenStore;
@@ -91,7 +64,7 @@ public class QuotaManager {
/** Attempts to acquire requested quota, synchronously. */
public QuotaResponse acquireQuota(QuotaRequest request) {
TimestampedInteger tokens = tokenStore.take(request.userId());
return QuotaResponse.create(tokens.value() != 0, request.userId(), tokens.timestamp());
return new QuotaResponse(tokens.value() != 0, request.userId(), tokens.timestamp());
}
/** Returns granted quota to the token store, asynchronously. */