本文整理汇总了Java中xiaofei.library.concurrentutils.util.Condition类的典型用法代码示例。如果您正苦于以下问题:Java Condition类的具体用法?Java Condition怎么用?Java Condition使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Condition类属于xiaofei.library.concurrentutils.util包,在下文中一共展示了Condition类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public T get(int index, Condition<? super T> condition) {
T result = null;
locks.get(index).lock();
try {
while (!condition.satisfy(result = list.get(index))) {
conditions.get(index).await();
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
locks.get(index).unlock();
}
return result;
}
示例2: wait
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public void wait(int index, Condition<? super T> condition) {
locks.get(index).lock();
try {
while (!condition.satisfy(list.get(index))) {
conditions.get(index).await();
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
locks.get(index).unlock();
}
}
示例3: actionNonBlocking
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public void actionNonBlocking(final Action<? super T> action, final Condition<? super T> condition) {
if (condition == null) {
throw new IllegalArgumentException("Condition cannot be null.");
}
lock.lock();
if (condition.satisfy(object)) {
action.call(object);
} else {
if (!waitingActions.containsKey(condition)) {
waitingActions.put(condition, new ConcurrentLinkedQueue<Action<? super T>>());
EXECUTOR.execute(new Runnable() {
@Override
public void run() {
ConcurrentLinkedQueue<Action<? super T>> q = waitingActions.get(condition);
try {
lock.lock();
while (!condition.satisfy(object)) {
ObjectCanary.this.condition.await();
}
Action<? super T> tmpAction;
while ((tmpAction = q.poll()) != null) {
tmpAction.call(object);
}
waitingActions.remove(condition);
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
lock.unlock();
}
}
});
}
waitingActions.get(condition).offer(action);
}
lock.unlock();
}
示例4: performFunctionUnderCondition
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
private <R> R performFunctionUnderCondition( Function<? super T, ? extends R> function, Condition<? super T> condition, boolean signal) {
R result = null;
try {
lock.lock();
while (condition != null && !condition.satisfy(object)) {
if (Config.DEBUG) {
System.out.println(Thread.currentThread().getName() + " before await");
}
this.condition.await();
if (Config.DEBUG) {
System.out.println(Thread.currentThread().getName() + " after await");
}
}
if (function != null) {
result = function.call(object);
}
if (signal) {
if (Config.DEBUG) {
System.out.println(Thread.currentThread().getName() + " signal");
}
//will signal all, but only one can go on.
this.condition.signalAll();
}
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
lock.unlock();
}
return result;
}
示例5: waitForInput
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public void waitForInput() {
int waitingIndex = mWaiting - 1;
mPlayer.getInputs().wait(waitingIndex, new Condition<PlayerInputs>() {
@Override
public boolean satisfy(PlayerInputs o) {
return o.getFinishedNumber().get() == o.getFunctionNumber();
}
});
}
示例6: inputSet
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public boolean inputSet() {
return mPlayer.getInputs().satisfy(mWaiting - 1, new Condition<PlayerInputs>() {
@Override
public boolean satisfy(PlayerInputs o) {
return o.getFinishedNumber().get() == o.getFunctionNumber();
}
});
}
示例7: waitForFinishing
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public final CopyOnWriteArrayList<Object> waitForFinishing() {
int index = mInputs.size() - 1;
return mInputs.get(index, new Condition<PlayerInputs>() {
@Override
public boolean satisfy(PlayerInputs o) {
return o.getFinishedNumber().get() == o.getFunctionNumber();
}
}).getInputs();
}
示例8: AugmentedListCanary
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public AugmentedListCanary() {
list = new CopyOnWriteArrayList<T>();
locks = new CopyOnWriteArrayList<Lock>();
conditions = new CopyOnWriteArrayList<java.util.concurrent.locks.Condition>();
}
示例9: satisfy
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public boolean satisfy(int index, Condition<? super T> condition) {
locks.get(index).lock();
boolean result = condition.satisfy(list.get(index));
locks.get(index).unlock();
return result;
}
示例10: ObjectCanary
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public <R extends T> ObjectCanary(R object) {
this.object = object;
lock = new ReentrantLock();
condition = lock.newCondition();
waitingActions = new ConcurrentHashMap<Condition<? super T>, ConcurrentLinkedQueue<Action<? super T>>>();
}
示例11: calculate
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public <R> R calculate(Function<? super T, ? extends R> function, Condition<? super T> condition) {
return performFunctionUnderCondition(function, condition, false);
}
示例12: wait
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public void wait(Condition<? super T> condition) {
performFunctionUnderCondition(null, condition, false);
}
示例13: satisfy
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public boolean satisfy(Condition<? super T> condition) {
lock.lock();
boolean result = condition.satisfy(object);
lock.unlock();
return result;
}
示例14: get
import xiaofei.library.concurrentutils.util.Condition; //导入依赖的package包/类
public T get(Condition<? super T> condition) {
return performFunctionUnderCondition(identicalFunction, condition, false);
}