本文整理匯總了Java中org.apache.ignite.lang.IgniteReducer類的典型用法代碼示例。如果您正苦於以下問題:Java IgniteReducer類的具體用法?Java IgniteReducer怎麽用?Java IgniteReducer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
IgniteReducer類屬於org.apache.ignite.lang包,在下文中一共展示了IgniteReducer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doCall
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
private void doCall(final Exchange exchange, final AsyncCallback callback, IgniteCompute compute) throws Exception {
Object job = exchange.getIn().getBody();
IgniteReducer<Object, Object> reducer = exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_REDUCER, IgniteReducer.class);
if (Collection.class.isAssignableFrom(job.getClass())) {
Collection<?> col = (Collection<?>) job;
TypeConverter tc = exchange.getContext().getTypeConverter();
Collection<IgniteCallable<?>> callables = new ArrayList<>(col.size());
for (Object o : col) {
callables.add(tc.mandatoryConvertTo(IgniteCallable.class, o));
}
if (reducer != null) {
compute.call((Collection) callables, reducer);
} else {
compute.call((Collection) callables);
}
} else if (IgniteCallable.class.isAssignableFrom(job.getClass())) {
compute.call((IgniteCallable<Object>) job);
} else {
throw new RuntimeCamelException(String.format(
"Ignite Compute endpoint with CALL executionType is only " + "supported for IgniteCallable payloads, or collections of them. The payload type was: %s.", job.getClass().getName()));
}
}
示例2: doApply
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private <T, R1, R2> void doApply(final Exchange exchange, final AsyncCallback callback, IgniteCompute compute) throws Exception {
IgniteClosure<T, R1> job = exchange.getIn().getBody(IgniteClosure.class);
T params = (T) exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_PARAMS);
if (job == null || params == null) {
throw new RuntimeCamelException(
String.format("Ignite Compute endpoint with APPLY executionType is only " + "supported for IgniteClosure payloads with parameters. The payload type was: %s.",
exchange.getIn().getBody().getClass().getName()));
}
IgniteReducer<R1, R2> reducer = exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_REDUCER, IgniteReducer.class);
if (Collection.class.isAssignableFrom(params.getClass())) {
Collection<T> colParams = (Collection<T>) params;
if (reducer == null) {
compute.apply(job, colParams);
} else {
compute.apply(job, colParams, reducer);
}
} else {
compute.apply(job, params);
}
}
示例3: boolReducer
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* @return Boolean reducer.
*/
public static IgniteReducer<Boolean, Boolean> boolReducer() {
return new IgniteReducer<Boolean, Boolean>() {
private final AtomicBoolean bool = new AtomicBoolean(true);
@Override public boolean collect(Boolean b) {
bool.compareAndSet(true, b);
// Stop collecting on first failure.
return bool.get();
}
@Override public Boolean reduce() {
return bool.get();
}
@Override public String toString() {
return "Bool reducer: " + bool;
}
};
}
示例4: mapsReducer
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* Gets reducer that aggregates maps into one.
*
* @param size Predicted size of the resulting map to avoid resizings.
* @param <K> Key type.
* @param <V> Value type.
* @return Reducer.
*/
public static <K, V> IgniteReducer<Map<K, V>, Map<K, V>> mapsReducer(final int size) {
return new IgniteReducer<Map<K, V>, Map<K, V>>() {
private final Map<K, V> ret = new ConcurrentHashMap8<>(size);
@Override public boolean collect(Map<K, V> map) {
if (map != null)
ret.putAll(map);
return true;
}
@Override public Map<K, V> reduce() {
return ret;
}
/** {@inheritDoc} */
@Override public String toString() {
return "Map reducer: " + ret;
}
};
}
示例5: objectsReducer
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* Gets reducer that aggregates items into collection.
*
* @param <T> Items type.
* @return Reducer.
*/
public static <T> IgniteReducer<T, Collection<T>> objectsReducer() {
return new IgniteReducer<T, Collection<T>>() {
private final Collection<T> ret = new ConcurrentLinkedQueue<>();
@Override public boolean collect(T item) {
if (item != null)
ret.add(item);
return true;
}
@Override public Collection<T> reduce() {
return ret;
}
};
}
示例6: GridCacheQueryInfo
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* @param loc {@code true} if local query.
* @param trans Transforming closure.
* @param rdc Reducer.
* @param qry Query base.
* @param locFut Query future in case of local query.
* @param sndId Sender node id.
* @param reqId Request id in case of distributed query.
* @param incMeta Include meta data or not.
* @param all Whether to load all pages.
* @param args Arguments.
*/
GridCacheQueryInfo(
boolean loc,
IgniteClosure<?, ?> trans,
IgniteReducer<Object, Object> rdc,
GridCacheQueryAdapter<?> qry,
GridCacheLocalQueryFuture<?, ?, ?> locFut,
UUID sndId,
long reqId,
boolean incMeta,
boolean all,
Object[] args
) {
this.loc = loc;
this.trans = trans;
this.rdc = rdc;
this.qry = qry;
this.locFut = locFut;
this.sndId = sndId;
this.reqId = reqId;
this.incMeta = incMeta;
this.all = all;
this.args = args;
}
示例7: finishTxs
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* Creates a future that will wait for all ongoing transactions that maybe affected by topology update
* to be finished. This set of transactions include
* <ul>
* <li/> All {@link TransactionConcurrency#PESSIMISTIC} transactions with topology version
* less or equal to {@code topVer}.
* <li/> {@link TransactionConcurrency#OPTIMISTIC} transactions in PREPARING state with topology
* version less or equal to {@code topVer} and having transaction key with entry that belongs to
* one of partitions in {@code parts}.
* </ul>
*
* @param topVer Topology version.
* @return Future that will be completed when all ongoing transactions are finished.
*/
public IgniteInternalFuture<Boolean> finishTxs(AffinityTopologyVersion topVer) {
GridCompoundFuture<IgniteInternalTx, Boolean> res =
new CacheObjectsReleaseFuture<>(
"Tx",
topVer,
new IgniteReducer<IgniteInternalTx, Boolean>() {
@Override public boolean collect(IgniteInternalTx e) {
return true;
}
@Override public Boolean reduce() {
return true;
}
});
for (IgniteInternalTx tx : txs()) {
if (needWaitTransaction(tx, topVer))
res.add(tx.finishFuture());
}
res.markInitialized();
return res;
}
示例8: forkjoinAsync
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* @param mode Distribution mode.
* @param jobs Closures to execute.
* @param rdc Reducer.
* @param nodes Grid nodes.
* @param execName Custom executor name.
* @param <R1> Type.
* @param <R2> Type.
* @return Reduced result.
*/
public <R1, R2> ComputeTaskInternalFuture<R2> forkjoinAsync(GridClosureCallMode mode,
Collection<? extends Callable<R1>> jobs,
IgniteReducer<R1, R2> rdc,
@Nullable Collection<ClusterNode> nodes,
@Nullable String execName)
{
assert mode != null;
assert rdc != null;
assert !F.isEmpty(jobs);
busyLock.readLock();
try {
if (F.isEmpty(nodes))
return ComputeTaskInternalFuture.finishedFuture(ctx, T3.class, U.emptyTopologyException());
ctx.task().setThreadContext(TC_SUBGRID, nodes);
return ctx.task().execute(new T3<>(mode, jobs, rdc), null, execName);
}
finally {
busyLock.readUnlock();
}
}
示例9: callAsync
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* @param job Job closure.
* @param args Job arguments.
* @param rdc Reducer.
* @param nodes Grid nodes.
* @param execName Custom executor name.
* @return Grid future for execution result.
*/
public <T, R1, R2> ComputeTaskInternalFuture<R2> callAsync(IgniteClosure<T, R1> job,
Collection<? extends T> args, IgniteReducer<R1, R2> rdc, @Nullable Collection<ClusterNode> nodes,
@Nullable String execName) {
busyLock.readLock();
try {
if (F.isEmpty(nodes))
return ComputeTaskInternalFuture.finishedFuture(ctx, T10.class, U.emptyTopologyException());
ctx.task().setThreadContext(TC_SUBGRID, nodes);
return ctx.task().execute(new T10<>(job, args, rdc), null, false, execName);
}
finally {
busyLock.readUnlock();
}
}
示例10: applyAsync0
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* Apply with reducer implementation.
*
* @param job Job
* @param args Arguments.
* @param rdc Reducer.
* @return Internal future.
*/
private <R1, R2, T> IgniteInternalFuture<R2> applyAsync0(IgniteClosure<T, R1> job, Collection<? extends T> args,
IgniteReducer<R1, R2> rdc) {
A.notNull(job, "job");
A.notNull(rdc, "rdc");
A.notNull(args, "args");
guard();
try {
return ctx.closure().callAsync(job, args, rdc, prj.nodes(), execName);
}
finally {
unguard();
}
}
示例11: testApply3
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* @throws Exception If failed.
*/
public void testApply3() throws Exception {
testMasterLeaveAwareCallback(2, new CX1<ClusterGroup, IgniteFuture<?>>() {
@Override public IgniteFuture<?> applyx(ClusterGroup grid) {
return compute(grid).applyAsync(new TestClosure(),
Arrays.asList("arg1", "arg2"),
new IgniteReducer<Void, Object>() {
@Override public boolean collect(@Nullable Void aVoid) {
return true;
}
@Override public Object reduce() {
return null;
}
});
}
});
}
示例12: testCall3
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* @throws Exception If failed.
*/
public void testCall3() throws Exception {
testMasterLeaveAwareCallback(2, new CX1<ClusterGroup, IgniteFuture<?>>() {
@Override public IgniteFuture<?> applyx(ClusterGroup prj) {
return compute(prj).callAsync(
Arrays.asList(new TestCallable(), new TestCallable()),
new IgniteReducer<Void, Object>() {
@Override public boolean collect(@Nullable Void aVoid) {
return true;
}
@Override public Object reduce() {
return null;
}
});
}
});
}
示例13: collectionsReducer
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* Gets reducer that aggregates collections.
*
* @param <T> Collection element type.
* @return Reducer.
*/
public static <T> IgniteReducer<Collection<T>, Collection<T>> collectionsReducer(final int size) {
return new IgniteReducer<Collection<T>, Collection<T>>() {
private List<T> ret;
@Override public synchronized boolean collect(Collection<T> c) {
if (c == null)
return true;
if (ret == null)
ret = new ArrayList<>(size);
ret.addAll(c);
return true;
}
@Override public synchronized Collection<T> reduce() {
return ret == null ? Collections.<T>emptyList() : ret;
}
/** {@inheritDoc} */
@Override public synchronized String toString() {
return "Collection reducer: " + ret;
}
};
}
示例14: GridCacheQueryBean
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* @param qry Query.
* @param rdc Optional reducer.
* @param trans Optional transformer.
* @param args Optional arguments.
*/
public GridCacheQueryBean(GridCacheQueryAdapter<?> qry, @Nullable IgniteReducer<Object, Object> rdc,
@Nullable IgniteClosure<?, ?> trans, @Nullable Object[] args) {
assert qry != null;
this.qry = qry;
this.rdc = rdc;
this.trans = trans;
this.args = args;
}
示例15: beforeLocalExecution
import org.apache.ignite.lang.IgniteReducer; //導入依賴的package包/類
/**
* @param ctx Context.
* @throws IgniteCheckedException In case of error.
*/
void beforeLocalExecution(GridCacheContext ctx) throws IgniteCheckedException {
Marshaller marsh = ctx.marshaller();
rdc = rdc != null ? U.<IgniteReducer<Object, Object>>unmarshal(marsh, U.marshal(marsh, rdc),
U.resolveClassLoader(ctx.gridConfig())) : null;
trans = trans != null ? U.<IgniteClosure<Object, Object>>unmarshal(marsh, U.marshal(marsh, trans),
U.resolveClassLoader(ctx.gridConfig())) : null;
}