-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
This allows configurable expiry or refresh if either isn't necessary, without changing the rest of the system.
There was a problem hiding this 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"); |
There was a problem hiding this comment.
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.
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.
|
This allows configurable expiry or refresh if either isn't necessary, without changing the rest of the system.