use of org.apache.ignite.internal.util.typedef.P1 in project ignite by apache.
the class F0 method and.
/**
* Get a predicate (not peer-deployable) that evaluates to {@code true} if each of its component predicates
* evaluates to {@code true}. The components are evaluated in order they are supplied.
* Evaluation will be stopped as soon as first predicate evaluates to {@code false}.
* Passed in predicates are NOT copied. If no predicates are passed in the returned
* predicate will always evaluate to {@code false}.
*
* @param ps Passed in predicate. If none provided - always-{@code false} predicate is
* returned.
* @param <T> Type of the free variable, i.e. the element the predicate is called on.
* @return Predicate that evaluates to {@code true} if each of its component predicates
* evaluates to {@code true}.
*/
@SuppressWarnings({ "unchecked", "ConfusingArgumentToVarargsMethod", "ConstantConditions" })
public static <T> IgnitePredicate<T> and(@Nullable final IgnitePredicate<? super T> p, @Nullable final IgnitePredicate<? super T>... ps) {
if (p == null && F.isEmptyOrNulls(ps))
return F.alwaysTrue();
if (F.isAlwaysFalse(p) && F.isAlwaysFalse(ps))
return F.alwaysFalse();
if (F.isAlwaysTrue(p) && F.isAlwaysTrue(ps))
return F.alwaysTrue();
if (isAllNodePredicates(p) && isAllNodePredicates(ps)) {
assert ps != null;
Set<UUID> ids = new GridLeanSet<>();
for (IgnitePredicate<? super T> p0 : ps) {
Collection<UUID> list = ((GridNodePredicate) p0).nodeIds();
if (ids.isEmpty())
ids.addAll(list);
else
ids.retainAll(list);
}
Collection<UUID> list = ((GridNodePredicate) p).nodeIds();
if (ids.isEmpty())
ids.addAll(list);
else
ids.retainAll(list);
// T must be <T extends ClusterNode>.
return (IgnitePredicate<T>) new GridNodePredicate(ids);
} else {
return new P1<T>() {
@Override
public boolean apply(T t) {
assert ps != null;
if (p != null && !p.apply(t))
return false;
for (IgnitePredicate<? super T> p : ps) if (p != null && !p.apply(t))
return false;
return true;
}
};
}
}
use of org.apache.ignite.internal.util.typedef.P1 in project ignite by apache.
the class GridEventConsumeSelfTest method testNodeJoin.
/**
* @throws Exception If failed.
*/
public void testNodeJoin() throws Exception {
final Collection<UUID> nodeIds = new HashSet<>();
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(GRID_CNT + 1);
UUID consumeId = grid(0).events().remoteListen(notSerializableProxy(new P2<UUID, Event>() {
@Override
public boolean apply(UUID nodeId, Event evt) {
info("Event from " + nodeId + " [" + evt.shortDisplay() + ']');
assertEquals(EVT_JOB_STARTED, evt.type());
nodeIds.add(nodeId);
cnt.incrementAndGet();
latch.countDown();
return true;
}
}), notSerializableProxy(new P1<Event>() {
@Override
public boolean apply(Event evt) {
return evt.type() == EVT_JOB_STARTED;
}
}), EVT_JOB_STARTED, EVT_JOB_FINISHED);
try {
assertNotNull(consumeId);
include = true;
startGrid("anotherGrid");
grid(0).compute().broadcast(F.noop());
assert latch.await(2, SECONDS);
assertEquals(GRID_CNT + 1, nodeIds.size());
assertEquals(GRID_CNT + 1, cnt.get());
} finally {
stopGrid("anotherGrid");
grid(0).events().stopRemoteListen(consumeId);
}
}
Aggregations