Skip to content

Commit e5040f6

Browse files
committed
+ internal rename
1 parent 67142fd commit e5040f6

File tree

5 files changed

+26
-25
lines changed

5 files changed

+26
-25
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
<groupId>io.github.q3769</groupId>
3232
<artifactId>conottle</artifactId>
33-
<version>11.0.1</version>
33+
<version>11.0.2</version>
3434
<packaging>jar</packaging>
3535
<name>conottle</name>
3636
<description>A Java concurrent API to throttle the maximum concurrency to process tasks for any given client while

src/main/java/conottle/Conottle.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ public final class Conottle implements ClientTaskExecutor, AutoCloseable {
4848
Math.max(16, Runtime.getRuntime().availableProcessors());
4949
private static final Logger logger = Logger.instance();
5050
private final ExecutorService adminExecutorService = Executors.newSingleThreadExecutor();
51-
private final ConcurrentMap<Object, TaskThrottlingExecutorService> activeThrottlingExecutors;
52-
private final ObjectPool<TaskThrottlingExecutorService> throttlingExecutorPool;
51+
private final ConcurrentMap<Object, PendingWorkAwareExecutor> activeThrottlingExecutors;
52+
private final ObjectPool<PendingWorkAwareExecutor> throttlingExecutorPool;
5353

5454
private Conottle(@NonNull Builder builder) {
5555
this.activeThrottlingExecutors = new ConcurrentHashMap<>(builder.maxTotalClientsInParallel);
@@ -60,8 +60,8 @@ private Conottle(@NonNull Builder builder) {
6060
}
6161

6262
@NonNull
63-
private static GenericObjectPoolConfig<TaskThrottlingExecutorService> getThrottlingExecutorPoolConfig(int poolSizeMaxTotal) {
64-
GenericObjectPoolConfig<TaskThrottlingExecutorService> throttlingExecutorPoolConfig =
63+
private static GenericObjectPoolConfig<PendingWorkAwareExecutor> getThrottlingExecutorPoolConfig(int poolSizeMaxTotal) {
64+
GenericObjectPoolConfig<PendingWorkAwareExecutor> throttlingExecutorPoolConfig =
6565
new GenericObjectPoolConfig<>();
6666
throttlingExecutorPoolConfig.setMaxTotal(poolSizeMaxTotal);
6767
return throttlingExecutorPoolConfig;
@@ -78,7 +78,7 @@ public CompletableFuture<Void> execute(@NonNull Runnable command, @NonNull Objec
7878
public <V> CompletableFuture<V> submit(@NonNull Callable<V> task, @NonNull Object clientId) {
7979
CompletableFutureHolder<V> taskCompletableFutureHolder = new CompletableFutureHolder<>();
8080
activeThrottlingExecutors.compute(clientId, (k, presentExecutor) -> {
81-
TaskThrottlingExecutorService executor = (presentExecutor == null) ? borrowFromPool() : presentExecutor;
81+
PendingWorkAwareExecutor executor = (presentExecutor == null) ? borrowFromPool() : presentExecutor;
8282
taskCompletableFutureHolder.setCompletableFuture(executor.submit(task));
8383
return executor;
8484
});
@@ -104,15 +104,15 @@ int countActiveExecutors() {
104104
return activeThrottlingExecutors.size();
105105
}
106106

107-
private TaskThrottlingExecutorService borrowFromPool() {
107+
private PendingWorkAwareExecutor borrowFromPool() {
108108
try {
109109
return throttlingExecutorPool.borrowObject();
110110
} catch (Exception e) {
111111
throw new IllegalStateException("Failed to borrow executor from pool " + throttlingExecutorPool, e);
112112
}
113113
}
114114

115-
private void returnToPool(TaskThrottlingExecutorService throttlingExecutor) {
115+
private void returnToPool(PendingWorkAwareExecutor throttlingExecutor) {
116116
adminExecutorService.submit(() -> {
117117
try {
118118
throttlingExecutorPool.returnObject(throttlingExecutor);

src/main/java/conottle/TaskCountingExecutorService.java renamed to src/main/java/conottle/PendingTaskCountingThrottleExecutor.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
*/
4141
@NotThreadSafe
4242
@ToString
43-
final class TaskCountingExecutorService implements TaskThrottlingExecutorService {
43+
final class PendingTaskCountingThrottleExecutor implements PendingWorkAwareExecutor {
4444
/**
4545
* Thread pool that throttles the max concurrency of this executor
4646
*/
@@ -51,16 +51,17 @@ final class TaskCountingExecutorService implements TaskThrottlingExecutorService
5151
* @param taskThreadPoolCapacity
5252
* the capacity of backing thread pool facilitating the async executions of this executor.
5353
*/
54-
TaskCountingExecutorService(int taskThreadPoolCapacity) {
54+
PendingTaskCountingThrottleExecutor(int taskThreadPoolCapacity) {
5555
this.taskThreadPool = Executors.newFixedThreadPool(taskThreadPoolCapacity);
5656
}
5757

5858
/**
59-
* To be called on completion of each submitted task
59+
* To be called on completion of each submitted task. The pending task count after decrementing the current value by
60+
* one, accounting for the completion of one task. Within the synchronized context, a zero pending task count
61+
* unambiguously indicates no more in-flight task pending execution on this executor.
6062
*
61-
* @return the pending task count after decrementing the current value by one, accounting for the completion of one
62-
* task. Within the synchronized context, a return value of zero unambiguously indicates no more in-flight
63-
* task pending execution on this executor.
63+
* @return true if there is no more pending tasks after the count is decremented to account for the previously
64+
* completed task
6465
*/
6566
@Override
6667
public boolean noPendingWorkAfterTaskComplete() {

src/main/java/conottle/TaskThrottlingExecutorService.java renamed to src/main/java/conottle/PendingWorkAwareExecutor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
import java.util.concurrent.CompletableFuture;
3131

3232
/**
33-
* Throttles total number of tasks being concurrently executed
33+
* Async task executor. Implementations can provide throttling.
3434
*/
35-
interface TaskThrottlingExecutorService {
35+
interface PendingWorkAwareExecutor {
3636
/**
37-
* Intended to be called after a task is completed by this service.
37+
* Intended to be called after each task is completed by this service.
3838
*
3939
* @return true if this executor has no more pending tasks after the task whose completion triggered this method
4040
* invocation

src/main/java/conottle/PooledExecutorFactory.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,36 @@
3131
import org.apache.commons.pool2.impl.DefaultPooledObject;
3232

3333
/**
34-
* Creates pooled {@link TaskCountingExecutorService} instances that provide throttled async client task executions.
35-
* Each {@code TaskCountingExecutorService} instance throttles its client task concurrency at the max capacity of the
34+
* Creates pooled {@link PendingTaskCountingThrottleExecutor} instances that provide throttled async client task executions.
35+
* Each {@code PendingTaskCountingThrottleExecutor} instance throttles its client task concurrency at the max capacity of the
3636
* executor's backing thread pool.
3737
*/
38-
final class PooledExecutorFactory extends BasePooledObjectFactory<TaskThrottlingExecutorService> {
38+
final class PooledExecutorFactory extends BasePooledObjectFactory<PendingWorkAwareExecutor> {
3939

4040
private final int maxExecutorConcurrency;
4141

4242
/**
4343
* @param maxExecutorConcurrency
44-
* max concurrent threads of the {@link TaskCountingExecutorService} instance produced by this factory
44+
* max concurrent threads of the {@link PendingTaskCountingThrottleExecutor} instance produced by this factory
4545
*/
4646
PooledExecutorFactory(int maxExecutorConcurrency) {
4747
this.maxExecutorConcurrency = maxExecutorConcurrency;
4848
}
4949

5050
@Override
5151
@NonNull
52-
public TaskThrottlingExecutorService create() {
53-
return new TaskCountingExecutorService(maxExecutorConcurrency);
52+
public PendingWorkAwareExecutor create() {
53+
return new PendingTaskCountingThrottleExecutor(maxExecutorConcurrency);
5454
}
5555

5656
@Override
5757
@NonNull
58-
public PooledObject<TaskThrottlingExecutorService> wrap(TaskThrottlingExecutorService throttlingExecutor) {
58+
public PooledObject<PendingWorkAwareExecutor> wrap(PendingWorkAwareExecutor throttlingExecutor) {
5959
return new DefaultPooledObject<>(throttlingExecutor);
6060
}
6161

6262
@Override
63-
public void destroyObject(PooledObject<TaskThrottlingExecutorService> pooledThrottlingExecutor,
63+
public void destroyObject(PooledObject<PendingWorkAwareExecutor> pooledThrottlingExecutor,
6464
DestroyMode destroyMode) throws Exception {
6565
try {
6666
super.destroyObject(pooledThrottlingExecutor, destroyMode);

0 commit comments

Comments
 (0)