Skip to content

Commit

Permalink
Move to smallrye-common as much as possible
Browse files Browse the repository at this point in the history
  • Loading branch information
dmlloyd committed May 7, 2024
1 parent 2bed15a commit 5ebf5b0
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 28 deletions.
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,24 @@
<dependency>
<groupId>org.wildfly.common</groupId>
<artifactId>wildfly-common</artifactId>
<version>1.7.0.Final</version>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-annotation</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-constraint</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-cpu</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.common</groupId>
<artifactId>smallrye-common-function</artifactId>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jboss/threads/EnhancedQueueExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
import org.jboss.threads.management.ManageableThreadPoolExecutorService;
import org.jboss.threads.management.StandardThreadPoolMXBean;

import org.wildfly.common.Assert;
import org.wildfly.common.cpu.ProcessorInfo;
import io.smallrye.common.constraint.Assert;
import io.smallrye.common.cpu.ProcessorInfo;

/**
* A task-or-thread queue backed thread pool executor service. Tasks are added in a FIFO manner, and consumers in a LIFO manner.
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/org/jboss/threads/EnhancedViewExecutor.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package org.jboss.threads;

import org.jboss.logging.Logger;
import org.wildfly.common.Assert;
import org.wildfly.common.annotation.Nullable;
import org.wildfly.common.cpu.ProcessorInfo;
import org.wildfly.common.lock.Locks;
import io.smallrye.common.constraint.Assert;
import io.smallrye.common.constraint.Nullable;
import io.smallrye.common.cpu.ProcessorInfo;

import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -17,6 +16,7 @@
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

import static org.jboss.threads.JBossExecutors.unsafe;

Expand Down Expand Up @@ -100,7 +100,7 @@ final class EnhancedViewExecutor extends ViewExecutor {
this.executeLock = queueLimit == 0
? null
// Lock must be reentrant to handle same-thread executors or CallerRunsPolicy
: Locks.reentrantLock();
: new ReentrantLock();
this.setExceptionHandler(uncaughtExceptionHandler);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jboss/threads/JBossExecutors.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.security.AccessController;

import org.jboss.logging.Logger;
import org.wildfly.common.Assert;
import io.smallrye.common.constraint.Assert;
import sun.misc.Unsafe;

/**
Expand Down
56 changes: 40 additions & 16 deletions src/main/java/org/jboss/threads/JBossThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.LockSupport;

import org.wildfly.common.Assert;
import org.wildfly.common.cpu.ProcessorInfo;
import io.smallrye.common.constraint.Assert;
import io.smallrye.common.cpu.ProcessorInfo;
import org.wildfly.common.function.ExceptionBiConsumer;
import org.wildfly.common.function.ExceptionBiFunction;
import org.wildfly.common.function.ExceptionConsumer;
Expand All @@ -19,7 +19,6 @@
import org.wildfly.common.function.ExceptionObjLongConsumer;
import org.wildfly.common.function.ExceptionRunnable;
import org.wildfly.common.function.ExceptionSupplier;
import org.wildfly.common.function.Functions;

/**
* A JBoss thread. Supports logging and extra operations.
Expand Down Expand Up @@ -255,6 +254,7 @@ public static <T> T executeWithInterruptDeferred(final Callable<T> action) throw
* @param <T> the action's return type
* @return the value returned from the callable
*/
@Deprecated
public static <T> T executeWithInterruptDeferred(final PrivilegedAction<T> action) {
final JBossThread thread = currentThread();
if (registerDeferral(thread)) try {
Expand All @@ -277,6 +277,7 @@ public static <T> T executeWithInterruptDeferred(final PrivilegedAction<T> actio
* @return the value returned from the callable
* @throws Exception if the action throws an exception
*/
@Deprecated
public static <T> T executeWithInterruptDeferred(final PrivilegedExceptionAction<T> action) throws Exception {
final JBossThread thread = currentThread();
if (registerDeferral(thread)) try {
Expand All @@ -289,6 +290,7 @@ public static <T> T executeWithInterruptDeferred(final PrivilegedExceptionAction
}
}

@Deprecated
public static <T, U, R, E extends Exception> R applyInterruptDeferredEx(final ExceptionBiFunction<T, U, R, E> function, T param1, U param2) throws E {
final JBossThread thread = currentThread();
if (registerDeferral(thread)) try {
Expand All @@ -301,14 +303,17 @@ public static <T, U, R, E extends Exception> R applyInterruptDeferredEx(final Ex
}
}

@Deprecated
public static <T, R, E extends Exception> R applyInterruptDeferredEx(final ExceptionFunction<T, R, E> function, T param) throws E {
return applyInterruptDeferredEx(Functions.exceptionFunctionBiFunction(), function, param);
return applyInterruptDeferredEx(ExceptionFunction::apply, function, param);
}

@Deprecated
public static <T, E extends Exception> T getInterruptDeferredEx(final ExceptionSupplier<T, E> supplier) throws E {
return applyInterruptDeferredEx(Functions.exceptionFunctionBiFunction(), Functions.exceptionSupplierFunction(), supplier);
return applyInterruptDeferredEx(ExceptionSupplier::get, supplier);
}

@Deprecated
public static <T, E extends Exception> void acceptInterruptDeferredEx(final ExceptionObjLongConsumer<T, E> consumer, T param1, long param2) throws E {
final JBossThread thread = currentThread();
if (registerDeferral(thread)) try {
Expand All @@ -321,6 +326,7 @@ public static <T, E extends Exception> void acceptInterruptDeferredEx(final Exce
}
}

@Deprecated
public static <T, E extends Exception> void acceptInterruptDeferredEx(final ExceptionObjIntConsumer<T, E> consumer, T param1, int param2) throws E {
final JBossThread thread = currentThread();
if (registerDeferral(thread)) try {
Expand All @@ -333,6 +339,7 @@ public static <T, E extends Exception> void acceptInterruptDeferredEx(final Exce
}
}

@Deprecated
public static <T, U, E extends Exception> void acceptInterruptDeferredEx(final ExceptionBiConsumer<T, U, E> consumer, T param1, U param2) throws E {
final JBossThread thread = currentThread();
if (registerDeferral(thread)) try {
Expand All @@ -345,15 +352,17 @@ public static <T, U, E extends Exception> void acceptInterruptDeferredEx(final E
}
}

@Deprecated
public static <T, E extends Exception> void acceptInterruptDeferredEx(final ExceptionConsumer<T, E> consumer, T param) throws E {
acceptInterruptDeferredEx(Functions.exceptionConsumerBiConsumer(), consumer, param);
acceptInterruptDeferredEx(ExceptionConsumer::accept, consumer, param);
}

@Deprecated
public static <E extends Exception> void runInterruptDeferredEx(final ExceptionRunnable<E> runnable) throws E {
acceptInterruptDeferredEx(Functions.exceptionConsumerBiConsumer(), Functions.exceptionRunnableConsumer(), runnable);
acceptInterruptDeferredEx(ExceptionRunnable::run, runnable);
}


@Deprecated
public static <T, U, R, E extends Exception> R applyInterruptResumedEx(final ExceptionBiFunction<T, U, R, E> function, T param1, U param2) throws E {
final JBossThread thread = currentThread();
if (unregisterDeferral(thread)) try {
Expand All @@ -366,14 +375,17 @@ public static <T, U, R, E extends Exception> R applyInterruptResumedEx(final Exc
}
}

@Deprecated
public static <T, R, E extends Exception> R applyInterruptResumedEx(final ExceptionFunction<T, R, E> function, T param) throws E {
return applyInterruptResumedEx(Functions.exceptionFunctionBiFunction(), function, param);
return applyInterruptResumedEx(ExceptionFunction::apply, function, param);
}

@Deprecated
public static <T, E extends Exception> T getInterruptResumedEx(final ExceptionSupplier<T, E> supplier) throws E {
return applyInterruptResumedEx(Functions.exceptionFunctionBiFunction(), Functions.exceptionSupplierFunction(), supplier);
return applyInterruptResumedEx(ExceptionSupplier::get, supplier);
}

@Deprecated
public static <T, E extends Exception> void acceptInterruptResumedEx(final ExceptionObjLongConsumer<T, E> consumer, T param1, long param2) throws E {
final JBossThread thread = currentThread();
if (unregisterDeferral(thread)) try {
Expand All @@ -386,6 +398,7 @@ public static <T, E extends Exception> void acceptInterruptResumedEx(final Excep
}
}

@Deprecated
public static <T, E extends Exception> void acceptInterruptResumedEx(final ExceptionObjIntConsumer<T, E> consumer, T param1, int param2) throws E {
final JBossThread thread = currentThread();
if (unregisterDeferral(thread)) try {
Expand All @@ -398,6 +411,7 @@ public static <T, E extends Exception> void acceptInterruptResumedEx(final Excep
}
}

@Deprecated
public static <T, U, E extends Exception> void acceptInterruptResumedEx(final ExceptionBiConsumer<T, U, E> consumer, T param1, U param2) throws E {
final JBossThread thread = currentThread();
if (unregisterDeferral(thread)) try {
Expand All @@ -410,12 +424,14 @@ public static <T, U, E extends Exception> void acceptInterruptResumedEx(final Ex
}
}

@Deprecated
public static <T, E extends Exception> void acceptInterruptResumedEx(final ExceptionConsumer<T, E> consumer, T param) throws E {
acceptInterruptResumedEx(Functions.exceptionConsumerBiConsumer(), consumer, param);
acceptInterruptResumedEx(ExceptionConsumer::accept, consumer, param);
}

@Deprecated
public static <E extends Exception> void runInterruptResumedEx(final ExceptionRunnable<E> runnable) throws E {
acceptInterruptResumedEx(Functions.exceptionConsumerBiConsumer(), Functions.exceptionRunnableConsumer(), runnable);
acceptInterruptResumedEx(ExceptionRunnable::run, runnable);
}

private static boolean unregisterDeferral(final JBossThread thread) {
Expand Down Expand Up @@ -578,6 +594,7 @@ public static InterruptHandler getAndSetInterruptHandler(final InterruptHandler
}
}

@Deprecated
public static <T, U, R, E extends Exception> R applyWithInterruptHandler(InterruptHandler interruptHandler, ExceptionBiFunction<T, U, R, E> function, T param1, U param2) throws E {
final JBossThread thread = currentThread();
if (thread == null) {
Expand All @@ -593,14 +610,17 @@ public static <T, U, R, E extends Exception> R applyWithInterruptHandler(Interru
}
}

@Deprecated
public static <T, R, E extends Exception> R applyWithInterruptHandler(InterruptHandler interruptHandler, ExceptionFunction<T, R, E> function, T param1) throws E {
return applyWithInterruptHandler(interruptHandler, Functions.exceptionFunctionBiFunction(), function, param1);
return applyWithInterruptHandler(interruptHandler, ExceptionFunction::apply, function, param1);
}

@Deprecated
public static <R, E extends Exception> R getWithInterruptHandler(InterruptHandler interruptHandler, ExceptionSupplier<R, E> function) throws E {
return applyWithInterruptHandler(interruptHandler, Functions.exceptionFunctionBiFunction(), Functions.exceptionSupplierFunction(), function);
return applyWithInterruptHandler(interruptHandler, ExceptionSupplier::get, function);
}

@Deprecated
public static <T, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionObjLongConsumer<T, E> function, T param1, long param2) throws E {
final JBossThread thread = currentThread();
if (thread == null) {
Expand All @@ -618,6 +638,7 @@ public static <T, E extends Exception> void acceptWithInterruptHandler(Interrupt
}
}

@Deprecated
public static <T, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionObjIntConsumer<T, E> function, T param1, int param2) throws E {
final JBossThread thread = currentThread();
if (thread == null) {
Expand All @@ -635,6 +656,7 @@ public static <T, E extends Exception> void acceptWithInterruptHandler(Interrupt
}
}

@Deprecated
public static <T, U, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionBiConsumer<T, U, E> function, T param1, U param2) throws E {
final JBossThread thread = currentThread();
if (thread == null) {
Expand All @@ -652,12 +674,14 @@ public static <T, U, E extends Exception> void acceptWithInterruptHandler(Interr
}
}

@Deprecated
public static <T, E extends Exception> void acceptWithInterruptHandler(InterruptHandler interruptHandler, ExceptionConsumer<T, E> function, T param1) throws E {
acceptWithInterruptHandler(interruptHandler, Functions.exceptionConsumerBiConsumer(), function, param1);
acceptWithInterruptHandler(interruptHandler, ExceptionConsumer::accept, function, param1);
}

@Deprecated
public static <E extends Exception> void runWithInterruptHandler(InterruptHandler interruptHandler, ExceptionRunnable<E> function) throws E {
acceptWithInterruptHandler(interruptHandler, Functions.exceptionConsumerBiConsumer(), Functions.exceptionRunnableConsumer(), function);
acceptWithInterruptHandler(interruptHandler, ExceptionRunnable::run, function);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import org.jboss.threads.management.ManageableThreadPoolExecutorService;
import org.jboss.threads.management.StandardThreadPoolMXBean;
import org.wildfly.common.Assert;
import io.smallrye.common.constraint.Assert;

/**
* A version of {@link ThreadPoolExecutor} which implements {@link ManageableThreadPoolExecutorService} in order to allow
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/jboss/threads/ViewExecutor.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.jboss.threads;

import org.wildfly.common.Assert;
import io.smallrye.common.constraint.Assert;

import java.security.PrivilegedAction;
import java.util.concurrent.AbstractExecutorService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import java.util.concurrent.ExecutorService;

import org.wildfly.common.annotation.NotNull;
import io.smallrye.common.constraint.NotNull;

/**
* A thread pool for which an MBean can be obtained.
Expand Down

0 comments on commit 5ebf5b0

Please sign in to comment.