Search in sources :

Example 36 with IgniteCompute

use of org.apache.ignite.IgniteCompute in project ignite by apache.

the class GridClosureProcessorSelfTest method runAsync.

/**
 * @param idx Node index.
 * @param jobs Runnable jobs.
 * @param p Optional node predicate.
 * @return Future object.
 */
private IgniteFuture<?> runAsync(int idx, Collection<ClosureTestRunnable> jobs, @Nullable IgnitePredicate<ClusterNode> p) {
    assert idx >= 0 && idx < NODES_CNT;
    assert !F.isEmpty(jobs);
    execCntr.set(0);
    IgniteCompute comp = p != null ? compute(grid(idx).cluster().forPredicate(p)) : grid(idx).compute();
    return comp.runAsync(jobs);
}
Also used : IgniteCompute(org.apache.ignite.IgniteCompute)

Example 37 with IgniteCompute

use of org.apache.ignite.IgniteCompute in project ignite by apache.

the class GridClosureProcessorSelfTest method runAsync.

/**
 * @param idx Node index.
 * @param job Runnable job.
 * @param p Optional node predicate.
 * @return Future object.
 */
private IgniteFuture<?> runAsync(int idx, IgniteRunnable job, @Nullable IgnitePredicate<ClusterNode> p) {
    assert idx >= 0 && idx < NODES_CNT;
    assert job != null;
    execCntr.set(0);
    IgniteCompute comp = p != null ? compute(grid(idx).cluster().forPredicate(p)) : grid(idx).compute();
    return comp.runAsync(job);
}
Also used : IgniteCompute(org.apache.ignite.IgniteCompute)

Example 38 with IgniteCompute

use of org.apache.ignite.IgniteCompute in project ignite by apache.

the class IgniteComputeCustomExecutorSelfTest method testAllComputeApiByCustomExecutor.

/**
 * @throws Exception If fails.
 */
public void testAllComputeApiByCustomExecutor() throws Exception {
    IgniteCompute comp = grid(0).compute().withExecutor(EXEC_NAME0);
    comp.affinityRun(CACHE_NAME, primaryKey(grid(1).cache(CACHE_NAME)), new IgniteRunnable() {

        @Override
        public void run() {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
        }
    });
    comp.affinityCall(CACHE_NAME, 0, new IgniteCallable<Object>() {

        @Override
        public Object call() throws Exception {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    });
    comp.broadcast(new IgniteRunnable() {

        @Override
        public void run() {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
        }
    });
    comp.broadcast(new IgniteCallable<Object>() {

        @Override
        public Object call() throws Exception {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    });
    comp.broadcast(new IgniteClosure<Object, Object>() {

        @Override
        public Object apply(Object o) {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    }, 0);
    comp.apply(new IgniteClosure<Object, Object>() {

        @Override
        public Object apply(Object o) {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    }, 0);
    comp.apply(new IgniteClosure<Integer, Object>() {

        @Override
        public Object apply(Integer o) {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    }, Collections.singletonList(0));
    comp.apply(new IgniteClosure<Integer, Object>() {

        @Override
        public Object apply(Integer o) {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    }, Collections.singletonList(0), new IgniteReducer<Object, Object>() {

        @Override
        public boolean collect(@Nullable Object o) {
            return true;
        }

        @Override
        public Object reduce() {
            return null;
        }
    });
    List<IgniteCallable<Object>> calls = new ArrayList<>();
    for (int i = 0; i < GRID_CNT * 2; ++i) {
        calls.add(new IgniteCallable<Object>() {

            @Override
            public Object call() throws Exception {
                assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
                return null;
            }
        });
    }
    comp.call(calls.get(0));
    comp.call(calls);
    comp.call(calls, new IgniteReducer<Object, Object>() {

        @Override
        public boolean collect(@Nullable Object o) {
            return true;
        }

        @Override
        public Object reduce() {
            return null;
        }
    });
    List<IgniteRunnable> runs = new ArrayList<>();
    for (int i = 0; i < GRID_CNT * 2; ++i) {
        runs.add(new IgniteRunnable() {

            @Override
            public void run() {
                assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            }
        });
    }
    comp.run(runs.get(0));
    comp.run(runs);
    comp.execute(TestTask.class, null);
}
Also used : ArrayList(java.util.ArrayList) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteException(org.apache.ignite.IgniteException) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 39 with IgniteCompute

use of org.apache.ignite.IgniteCompute in project ignite by apache.

the class IgniteCacheRandomOperationBenchmark method doScanQuery.

/**
 * @param cache Ignite cache.
 * @throws Exception If failed.
 */
private void doScanQuery(IgniteCache<Object, Object> cache) throws Exception {
    if (!affCaches.contains(cache))
        return;
    Map<UUID, List<Integer>> partitionsMap = personCachePartitions(cache.getName());
    ScanQueryBroadcastClosure c = new ScanQueryBroadcastClosure(cache.getName(), partitionsMap);
    ClusterGroup clusterGrp = ignite().cluster().forNodeIds(partitionsMap.keySet());
    IgniteCompute compute = ignite().compute(clusterGrp);
    compute.broadcast(c);
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) List(java.util.List) ArrayList(java.util.ArrayList) UUID(java.util.UUID) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 40 with IgniteCompute

use of org.apache.ignite.IgniteCompute in project ignite by apache.

the class GridMarshallerAbstractTest method testCompute.

/**
 * @throws Exception If failed.
 */
public void testCompute() throws Exception {
    IgniteConfiguration cfg = optimize(getConfiguration("g1"));
    try (Ignite g1 = G.start(cfg)) {
        IgniteCompute compute = compute(grid().cluster().forNode(g1.cluster().localNode()));
        compute.run(new IgniteRunnable() {

            @Override
            public void run() {
            // No-op.
            }
        });
        GridMarshallerTestBean inBean = newTestBean(compute);
        byte[] buf = marshal(inBean);
        GridMarshallerTestBean outBean = unmarshal(buf);
        assert inBean.getObjectField() != null;
        assert outBean.getObjectField() != null;
        assert inBean.getObjectField().getClass().equals(IgniteComputeImpl.class);
        assert outBean.getObjectField().getClass().equals(IgniteComputeImpl.class);
        assert inBean != outBean;
        assert inBean.equals(outBean);
        ClusterGroup inPrj = compute.clusterGroup();
        ClusterGroup outPrj = ((IgniteCompute) outBean.getObjectField()).clusterGroup();
        assert inPrj.getClass().equals(outPrj.getClass());
        assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes());
        outBean.checkNullResources();
    }
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Aggregations

IgniteCompute (org.apache.ignite.IgniteCompute)41 Ignite (org.apache.ignite.Ignite)19 IgniteException (org.apache.ignite.IgniteException)14 ArrayList (java.util.ArrayList)10 IgniteFuture (org.apache.ignite.lang.IgniteFuture)9 UUID (java.util.UUID)6 ClusterGroup (org.apache.ignite.cluster.ClusterGroup)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 IgniteCallable (org.apache.ignite.lang.IgniteCallable)4 Nullable (org.jetbrains.annotations.Nullable)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 ClusterNode (org.apache.ignite.cluster.ClusterNode)3 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)3 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)3 Collection (java.util.Collection)2 Callable (java.util.concurrent.Callable)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2