8000 Factor out different DelayManager implementations by andrewaylett · Pull Request #115 · andrewaylett/arc · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Factor out different DelayManager implementations #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2025

Conversation

andrewaylett
Copy link
Owner

This allows configurable expiry or refresh if either isn't necessary, without changing the rest of the system.

This allows configurable expiry or refresh if either isn't necessary,
without changing the rest of the system.
@Copilot Copilot AI review requested due to automatic review settings May 31, 2025 22:07
Copy link
@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors delay management by extracting different DelayManager implementations to allow configurable expiry and refresh behavior without affecting the rest of the system.

  • Introduces new DelayManager implementations (NoOpDelayManager, ExpiringDelayManager, ExpireAndRefreshDelayManager).
  • Replaces the previous concrete DelayedElement and DelayManager with new abstract structures.
  • Updates ArcBuilder and Arc to integrate the new delay management design.

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/src/main/java/eu/aylett/arc/internal/TimeDelayedElement.java New implementation using DelayManager.GetDelay, with proper delay calculation.
lib/src/main/java/eu/aylett/arc/internal/NoOpDelayedElement.java Lightweight implementation returning a no-op delay element.
lib/src/main/java/eu/aylett/arc/internal/NoOpDelayManager.java Implements a no-op manager with an empty poll implementation.
lib/src/main/java/eu/aylett/arc/internal/ExpiringDelayManager.java Adds delay elements with expiry handling using a DelayQueue.
lib/src/main/java/eu/aylett/arc/internal/ExpireAndRefreshDelayManager.java Handles both expiry and refresh using two separate DelayQueues.
lib/src/main/java/eu/aylett/arc/internal/DelayedElement.java Refactors DelayedElement to an abstract class, removing previous method implementations.
lib/src/main/java/eu/aylett/arc/internal/DelayManager.java Changes DelayManager to an abstract class, with concrete implementations in subclasses.
lib/src/main/java/eu/aylett/arc/ArcBuilder.java Updates to use DelayManager objects and validates expiry/refresh constraints.
lib/src/main/java/eu/aylett/arc/Arc.java Adjusts constructor to receive a DelayManager, removing explicit duration validations.
Comments suppressed due to low confidence (1)

lib/src/main/java/eu/aylett/arc/internal/DelayedElement.java:19

  • Consider adding class-level documentation for DelayedElement to clearly define the contract expected from its subclasses, now that its previous method implementations have been removed.
public abstract class DelayedElement { }

@@ -68,6 +76,18 @@ public ArcBuilder withClock(InstantSource clock) {
int capacity) {
checkNotNull(loader, "Loader function must be provided");
checkArgument(capacity > 0, "Capacity must be greater than zero");
return new Arc<>(capacity, loader, pool, expiry, refresh, clock);

Verify.verify(expiry != null || refresh == null, "Cannot refresh without expiry");
Copy link
Preview
Copilot AI May 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The condition verifying expiry and refresh is somewhat unclear; consider rewriting it to explicitly check that if a refresh duration is provided, then expiry must be non-null, for example by using a clear if statement with an explicit error message.

Suggested change
Verify.verify(expiry != null || refresh == null, "Cannot refresh without expiry");
if (refresh != null && expiry == null) {
throw new IllegalArgumentException("Cannot set a refresh duration without first setting an expiry duration.");
}

Copilot uses AI. Check for mistakes.

Copy link
  • Surviving mutants in this change: 35
  • Killed mutants in this change: 24
class surviving killed
🧟eu.aylett.arc.internal.TimeDelayedElement 15 9
🧟eu.aylett.arc.ArcBuilder 8 5
🧟eu.aylett.arc.internal.ExpiringDelayManager 6 0
🧟eu.aylett.arc.internal.ExpireAndRefreshDelayManager 5 9
🧟eu.aylett.arc.internal.NoOpDelayManager 1 0
💯eu.aylett.arc.Arc 0 1

See https://pitest.org

@andrewaylett andrewaylett merged commit 19bb81a into main May 31, 2025
6 checks passed
@andrewaylett andrewaylett deleted the push-mnvlzuptmunm branch May 31, 2025 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0