diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/circuitbreak/AbstractCircuitBreaker.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/circuitbreak/AbstractCircuitBreaker.java index 8a012769..5a19d7b7 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/circuitbreak/AbstractCircuitBreaker.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/circuitbreak/AbstractCircuitBreaker.java @@ -20,7 +20,6 @@ import com.jd.live.agent.governance.policy.service.circuitbreak.CircuitBreakPolicy; import lombok.Getter; -import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; /** @@ -33,13 +32,8 @@ public abstract class AbstractCircuitBreaker extends AbstractLicensee windowRef = new AtomicReference<>(); - protected final AtomicBoolean started = new AtomicBoolean(true); - public AbstractCircuitBreaker(CircuitBreakPolicy policy, URI uri) { this.policy = policy; this.uri = uri; @@ -112,21 +106,6 @@ public void onSuccess(long durationInMs) { } } - @Override - public void close() { - // When the circuit breaker is not accessed for a long time, it will be automatically garbage collected. - if (started.compareAndSet(true, false)) { - doClose(); - } - } - - /** - * Closes the circuit breaker. - */ - protected void doClose() { - - } - /** * Performs the actual acquisition logic. * Subclasses must implement this method to define the specific acquisition behavior. diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/concurrencylimit/AbstractConcurrencyLimiter.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/concurrencylimit/AbstractConcurrencyLimiter.java index 56b462dc..fdc3c4c4 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/concurrencylimit/AbstractConcurrencyLimiter.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/concurrencylimit/AbstractConcurrencyLimiter.java @@ -2,9 +2,6 @@ import com.jd.live.agent.governance.invoke.permission.AbstractLicensee; import com.jd.live.agent.governance.policy.service.limit.ConcurrencyLimitPolicy; -import lombok.Getter; - -import java.util.concurrent.atomic.AtomicBoolean; /** * AbstractConcurrencyLimiter @@ -13,11 +10,6 @@ */ public abstract class AbstractConcurrencyLimiter extends AbstractLicensee implements ConcurrencyLimiter { - @Getter - protected long lastAccessTime; - - protected final AtomicBoolean started = new AtomicBoolean(true); - public AbstractConcurrencyLimiter(ConcurrencyLimitPolicy policy) { this.policy = policy; } @@ -31,13 +23,6 @@ public boolean acquire() { return doAcquire(); } - @Override - public void close() { - if (started.compareAndSet(true, false)) { - doClose(); - } - } - /** * Performs the actual acquisition logic. * Subclasses must implement this method to define the specific acquisition behavior. @@ -45,11 +30,4 @@ public void close() { * @return true if the acquisition is successful, false otherwise. */ protected abstract boolean doAcquire(); - - /** - * Closes the limiter. - */ - protected void doClose() { - - } } diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/permission/AbstractLicensee.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/permission/AbstractLicensee.java index 822a2e4f..dd1c462e 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/permission/AbstractLicensee.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/permission/AbstractLicensee.java @@ -18,19 +18,26 @@ import com.jd.live.agent.governance.policy.PolicyVersion; import lombok.Getter; +import java.util.concurrent.atomic.AtomicBoolean; + /** * An abstract class representing a licensee with a policy version. * * @param

the type of policy version */ -@Getter public abstract class AbstractLicensee

implements Licensee

{ /** * The policy associated with the licensee. */ + @Getter protected P policy; + @Getter + protected volatile long lastAccessTime; + + protected final AtomicBoolean started = new AtomicBoolean(true); + @Override public void exchange(P policy) { P old = this.policy; @@ -40,6 +47,20 @@ public void exchange(P policy) { } } + @Override + public void close() { + if (started.compareAndSet(true, false)) { + doClose(); + } + } + + /** + * Closes the limiter. + */ + protected void doClose() { + + } + /** * Performs the exchange of the policy from the older version to the newer version. * This method can be overridden by subclasses to add additional logic during the policy exchange. diff --git a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/ratelimit/AbstractRateLimiter.java b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/ratelimit/AbstractRateLimiter.java index e4fa4869..a013ee08 100644 --- a/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/ratelimit/AbstractRateLimiter.java +++ b/joylive-core/joylive-governance-api/src/main/java/com/jd/live/agent/governance/invoke/ratelimit/AbstractRateLimiter.java @@ -19,10 +19,8 @@ import com.jd.live.agent.core.util.option.Option; import com.jd.live.agent.governance.invoke.permission.AbstractLicensee; import com.jd.live.agent.governance.policy.service.limit.RateLimitPolicy; -import lombok.Getter; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; /** * AbstractRateLimiter is an abstract implementation of the RateLimiter interface, @@ -51,11 +49,6 @@ public abstract class AbstractRateLimiter extends AbstractLicensee