Skip to content

Commit

Permalink
Separate API and internals and make tests modular (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed Jul 7, 2024
2 parents 607f837 + a194557 commit ddb12ce
Show file tree
Hide file tree
Showing 72 changed files with 811 additions and 394 deletions.
178 changes: 178 additions & 0 deletions api-changes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
[
{
"extension": "revapi.versions",
"configuration": {
"enabled": true,
"semantic0": true,
"strictSemver": true,
"versionIncreaseAllows": {
"major": {
"severity": "BREAKING"
},
"minor": {
"severity": "NON_BREAKING"
},
"patch": {
"severity": "EQUIVALENT"
}
}
}
},
{
"extension": "revapi.differences",
"configuration": {
"ignore": true,
"differences": [
{
"code": "java.class.noLongerInheritsFromClass",
"old": "class stormpot.Pool<T extends stormpot.Poolable>",
"new": "interface stormpot.Pool<T extends stormpot.Poolable>",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.class.kindChanged",
"old": "class stormpot.Pool<T extends stormpot.Poolable>",
"new": "interface stormpot.Pool<T extends stormpot.Poolable>",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.Pool<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::build()",
"new": "method stormpot.Pool<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::build()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::clone()",
"new": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::clone()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.Allocator<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::getAllocator()",
"new": "method stormpot.Allocator<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::getAllocator()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method int stormpot.PoolBuilder<T extends stormpot.Poolable>::getBackgroundExpirationCheckDelay()",
"new": "method int stormpot.PoolBuilder<T extends stormpot.Poolable>::getBackgroundExpirationCheckDelay()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.Expiration<? super T> stormpot.PoolBuilder<T extends stormpot.Poolable>::getExpiration()",
"new": "method stormpot.Expiration<? super T> stormpot.PoolBuilder<T extends stormpot.Poolable>::getExpiration()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.MetricsRecorder stormpot.PoolBuilder<T extends stormpot.Poolable>::getMetricsRecorder()",
"new": "method stormpot.MetricsRecorder stormpot.PoolBuilder<T extends stormpot.Poolable>::getMetricsRecorder()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.Reallocator<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::getReallocator()",
"new": "method stormpot.Reallocator<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::getReallocator()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method int stormpot.PoolBuilder<T extends stormpot.Poolable>::getSize()",
"new": "method int stormpot.PoolBuilder<T extends stormpot.Poolable>::getSize()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method java.util.concurrent.ThreadFactory stormpot.PoolBuilder<T extends stormpot.Poolable>::getThreadFactory()",
"new": "method java.util.concurrent.ThreadFactory stormpot.PoolBuilder<T extends stormpot.Poolable>::getThreadFactory()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method boolean stormpot.PoolBuilder<T extends stormpot.Poolable>::isBackgroundExpirationEnabled()",
"new": "method boolean stormpot.PoolBuilder<T extends stormpot.Poolable>::isBackgroundExpirationEnabled()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method boolean stormpot.PoolBuilder<T extends stormpot.Poolable>::isPreciseLeakDetectionEnabled()",
"new": "method boolean stormpot.PoolBuilder<T extends stormpot.Poolable>::isPreciseLeakDetectionEnabled()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method <X extends stormpot.Poolable> stormpot.PoolBuilder<X> stormpot.PoolBuilder<T extends stormpot.Poolable>::setAllocator(stormpot.Allocator<X>)",
"new": "method <X extends stormpot.Poolable> stormpot.PoolBuilder<X> stormpot.PoolBuilder<T extends stormpot.Poolable>::setAllocator(stormpot.Allocator<X>)",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setBackgroundExpirationCheckDelay(int)",
"new": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setBackgroundExpirationCheckDelay(int)",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setBackgroundExpirationEnabled(boolean)",
"new": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setBackgroundExpirationEnabled(boolean)",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setExpiration(stormpot.Expiration<? super T>)",
"new": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setExpiration(stormpot.Expiration<? super T>)",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setMetricsRecorder(stormpot.MetricsRecorder)",
"new": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setMetricsRecorder(stormpot.MetricsRecorder)",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setPreciseLeakDetectionEnabled(boolean)",
"new": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setPreciseLeakDetectionEnabled(boolean)",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setSize(int)",
"new": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setSize(int)",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.nowAbstract",
"old": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setThreadFactory(java.util.concurrent.ThreadFactory)",
"new": "method stormpot.PoolBuilder<T> stormpot.PoolBuilder<T extends stormpot.Poolable>::setThreadFactory(java.util.concurrent.ThreadFactory)",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.class.kindChanged",
"old": "class stormpot.PoolBuilder<T extends stormpot.Poolable>",
"new": "interface stormpot.PoolBuilder<T extends stormpot.Poolable>",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.class.nowAbstract",
"old": "class stormpot.PoolBuilder<T extends stormpot.Poolable>",
"new": "interface stormpot.PoolBuilder<T extends stormpot.Poolable>",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.class.kindChanged",
"old": "class stormpot.PoolTap<T extends stormpot.Poolable>",
"new": "interface stormpot.PoolTap<T extends stormpot.Poolable>",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
},
{
"code": "java.method.addedToInterface",
"new": "method long stormpot.SlotInfo<T extends stormpot.Poolable>::getCreatedNanoTime()",
"justification": "ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE"
}
]
}
}
]
22 changes: 7 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,6 @@
<trimStackTrace>false</trimStackTrace>
<argLine>
@{argLine}
--add-opens stormpot/stormpot=ALL-UNNAMED
--add-opens stormpot/blackbox=ALL-UNNAMED
--add-opens stormpot/extensions=ALL-UNNAMED
-Djunit.jupiter.execution.parallel.enabled=true
-Djunit.jupiter.execution.parallel.mode.classes.default=concurrent
-Djunit.jupiter.execution.timeout.default=30m
-Djdk.attach.allowAttachSelf
</argLine>
</configuration>
Expand All @@ -135,12 +129,6 @@
<trimStackTrace>false</trimStackTrace>
<argLine>
@{argLine}
--add-opens stormpot/stormpot=ALL-UNNAMED
--add-opens stormpot/blackbox=ALL-UNNAMED
--add-opens stormpot/extensions=ALL-UNNAMED
-Djunit.jupiter.execution.parallel.enabled=true
-Djunit.jupiter.execution.parallel.mode.classes.default=concurrent
-Djunit.jupiter.execution.timeout.default=30m
-Djdk.attach.allowAttachSelf
</argLine>
</configuration>
Expand Down Expand Up @@ -312,7 +300,11 @@
</dependency>
</dependencies>
<configuration>
<oldVersion>3.0.1</oldVersion>
<analysisConfigurationFiles>
<configurationFile>
<path>api-changes.json</path>
</configurationFile>
</analysisConfigurationFiles>
</configuration>
<executions>
<execution>
Expand Down Expand Up @@ -395,7 +387,7 @@
<dependency>
<groupId>org.hdrhistogram</groupId>
<artifactId>HdrHistogram</artifactId>
<version>2.2.1</version>
<version>2.2.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -420,7 +412,7 @@
<configuration>
<additionalOptions>
<additionalOption>--snippet-path</additionalOption>
<additionalOption>${build.testSourceDirectory}/examples/</additionalOption>
<additionalOption>${project.build.testSourceDirectory}/examples/</additionalOption>
</additionalOptions>
<detectJavaApiLink>true</detectJavaApiLink>
</configuration>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
*/
module stormpot {
requires transitive java.management;
requires static java.sql; // For testing only.
exports stormpot;
exports stormpot.internal to stormpot.test;
}
5 changes: 5 additions & 0 deletions src/main/java/stormpot/Expiration.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*/
package stormpot;

import stormpot.internal.EveryExpiration;
import stormpot.internal.OrExpiration;
import stormpot.internal.TimeExpiration;
import stormpot.internal.TimeSpreadExpiration;

import java.util.concurrent.TimeUnit;

/**
Expand Down
39 changes: 19 additions & 20 deletions src/main/java/stormpot/Pool.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package stormpot;

import static stormpot.AllocationProcess.direct;
import static stormpot.AllocationProcess.inline;
import static stormpot.AllocationProcess.threaded;
import stormpot.internal.PoolBuilderImpl;

import static stormpot.internal.AllocationProcess.direct;
import static stormpot.internal.AllocationProcess.inline;
import static stormpot.internal.AllocationProcess.threaded;

/**
* A Pool is a self-renewable set of objects from which one can claim exclusive
Expand Down Expand Up @@ -72,10 +74,7 @@
* by the configured allocator.
* @see stormpot.PoolTap
*/
public abstract class Pool<T extends Poolable> extends PoolTap<T> {
Pool() {
}

public interface Pool<T extends Poolable> extends PoolTap<T> {
/**
* Get a {@link PoolBuilder} based on the given {@link Allocator} or
* {@link Reallocator}, which can then in turn be used to
Expand All @@ -92,7 +91,7 @@ public abstract class Pool<T extends Poolable> extends PoolTap<T> {
* before the pool instance is {@linkplain PoolBuilder#build() built}.
* @see #fromThreaded(Allocator)
*/
public static <T extends Poolable> PoolBuilder<T> from(Allocator<T> allocator) {
static <T extends Poolable> PoolBuilder<T> from(Allocator<T> allocator) {
return fromThreaded(allocator);
}

Expand Down Expand Up @@ -120,8 +119,8 @@ public static <T extends Poolable> PoolBuilder<T> from(Allocator<T> allocator) {
* @return A {@link PoolBuilder} that admits additional configurations,
* before the pool instance is {@linkplain PoolBuilder#build() built}.
*/
public static <T extends Poolable> PoolBuilder<T> fromThreaded(Allocator<T> allocator) {
return new PoolBuilder<>(threaded(), allocator);
static <T extends Poolable> PoolBuilder<T> fromThreaded(Allocator<T> allocator) {
return new PoolBuilderImpl<>(threaded(), allocator);
}

/**
Expand All @@ -147,8 +146,8 @@ public static <T extends Poolable> PoolBuilder<T> fromThreaded(Allocator<T> allo
* @return A {@link PoolBuilder} that admits additional configurations,
* before the pool instance is {@linkplain PoolBuilder#build() built}.
*/
public static <T extends Poolable> PoolBuilder<T> fromInline(Allocator<T> allocator) {
return new PoolBuilder<>(inline(), allocator);
static <T extends Poolable> PoolBuilder<T> fromInline(Allocator<T> allocator) {
return new PoolBuilderImpl<>(inline(), allocator);
}

/**
Expand Down Expand Up @@ -185,7 +184,7 @@ public static <T extends Poolable> PoolBuilder<T> fromInline(Allocator<T> alloca
* @return A pool of the given objects.
*/
@SafeVarargs
public static <T> Pool<Pooled<T>> of(T... objects) {
static <T> Pool<Pooled<T>> of(T... objects) {
Allocator<Pooled<T>> allocator = new Allocator<>() {
private int index;
@Override
Expand All @@ -197,7 +196,7 @@ public Pooled<T> allocate(Slot slot) {
public void deallocate(Pooled<T> poolable) {
}
};
PoolBuilder<Pooled<T>> builder = new PoolBuilder<>(direct(), allocator);
PoolBuilder<Pooled<T>> builder = new PoolBuilderImpl<>(direct(), allocator);
builder.setSize(objects.length);
return builder.build();
}
Expand Down Expand Up @@ -232,7 +231,7 @@ public void deallocate(Pooled<T> poolable) {
* @return A {@link Completion} instance that represents the shutdown
* process.
*/
public abstract Completion shutdown();
Completion shutdown();

/**
* Set the target size for this pool. The pool will strive to keep this many
Expand All @@ -256,7 +255,7 @@ public void deallocate(Pooled<T> poolable) {
*
* @param size The new target size of the pool
*/
public abstract void setTargetSize(int size);
void setTargetSize(int size);

/**
* Get the currently configured target size of the pool. Note that this is
Expand All @@ -265,20 +264,20 @@ public void deallocate(Pooled<T> poolable) {
*
* @return The current target size of this pool.
*/
public abstract int getTargetSize();
int getTargetSize();

/**
* Get the {@link ManagedPool} instance that represents this pool.
* @return The {@link ManagedPool} instance for this pool.
*/
public abstract ManagedPool getManagedPool();
ManagedPool getManagedPool();

/**
* Get a thread-safe {@link PoolTap} implementation for this pool, which can
* be freely shared among multiple threads.
* @return A thread-safe {@link PoolTap}.
*/
public final PoolTap<T> getThreadSafeTap() {
default PoolTap<T> getThreadSafeTap() {
// We use the anonymous inner class to enforce encapsulation, which is
// probably the only reason anyone would wan to use this.
return new PoolTap<>() {
Expand Down Expand Up @@ -308,5 +307,5 @@ public T tryClaim() {
*
* @return A thread-local {@link PoolTap}.
*/
public abstract PoolTap<T> getThreadLocalTap();
PoolTap<T> getThreadLocalTap();
}
Loading

0 comments on commit ddb12ce

Please sign in to comment.