pro.jk.ejoker.common.system.wrapper.CountDownLatchWrapper Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ejoker-common Show documentation
Show all versions of ejoker-common Show documentation
EJoker is a CQRS + EventSourcing framwork
package pro.jk.ejoker.common.system.wrapper;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import pro.jk.ejoker.common.system.functional.IFunction1;
import pro.jk.ejoker.common.system.functional.IVoidFunction1;
import pro.jk.ejoker.common.system.wrapper.WrapperAssembler.CountDownLatchProviderContext;
import pro.jk.ejoker.common.system.wrapper.WrapperAssembler._IVF_await1;
import pro.jk.ejoker.common.system.wrapper.WrapperAssembler._IVF_await2;
public class CountDownLatchWrapper {
public final static Object newCountDownLatch() {
return newCountDownLatch(1);
}
public final static Object newCountDownLatch(int count) {
return provider.trigger(count);
}
public final static void await(Object handle) throws InterruptedException {
awaiter.trigger(handle);
}
public final static boolean await(Object handle, long timeout, TimeUnit unit) throws InterruptedException {
return awaiterLimit.trigger(handle, timeout, unit);
}
/**
* Just clean the interrupt flag and do nothing while interrupt() invoke.
* @param handle
*/
@SuppressWarnings("deprecation")
public final static void awaitInterruptable(Object handle){
try {
awaiter.trigger(handle);
} catch (InterruptedException e) {
MittenWrapper.interrupted();
}
}
/**
* Just clean the interrupt flag and do nothing while interrupt() invoke.
* @param handle
* @param timeout
* @param unit
* @return await enough or not
*/
@SuppressWarnings("deprecation")
public final static boolean awaitInterruptable(Object handle, long timeout, TimeUnit unit){
try {
return awaiterLimit.trigger(handle, timeout, unit);
} catch (InterruptedException e) {
return MittenWrapper.interrupted();
}
}
public final static void countDown(Object handle) {
countDownTrigger.trigger(handle);
}
public final long getCount(Object handle) {
return countGetter.trigger(handle);
}
private static AtomicBoolean hasRedefined = new AtomicBoolean(false);
private static IFunction1