use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridJobExecutionLoadTestClient method call.
/**
* {@inheritDoc}
*/
@SuppressWarnings("InfiniteLoopStatement")
@Nullable
@Override
public Object call() throws Exception {
IgniteCompute rmts = g.compute(g.cluster().forRemotes());
while (!finish) {
try {
rmts.execute(GridJobExecutionLoadTestTask.class, null);
txCnt.increment();
} catch (IgniteException e) {
e.printStackTrace();
}
}
return null;
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridJobExecutionLoadTestClientSemaphore method warmUp.
/**
* Warms the JVM up.
*
* @param noThreads Number of threads to use.
*/
private static void warmUp(int noThreads) {
X.println("Warming up...");
final IgniteCompute rmts = g.compute(g.cluster().forRemotes());
GridLoadTestUtils.runMultithreadedInLoop(new Callable<Object>() {
@Nullable
@Override
public Object call() {
try {
rmts.execute(GridJobExecutionLoadTestTask.class, null);
} catch (IgniteException e) {
e.printStackTrace();
}
return null;
}
}, noThreads, WARM_UP_DURATION);
// Run GC on all nodes.
try {
g.compute().run(new GridAbsClosure() {
@Override
public void apply() {
System.gc();
}
});
} catch (IgniteException e) {
throw new IllegalStateException(e);
}
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridClusterStateProcessor method changeGlobalState.
/**
*
*/
public IgniteInternalFuture<?> changeGlobalState(final boolean activate) {
if (cacheProc.transactions().tx() != null || sharedCtx.lockedTopologyVersion(null) != null)
throw new IgniteException("Cannot " + prettyStr(activate) + " cluster, because cache locked on transaction.");
if ((globalState == ACTIVE && activate) || (this.globalState == INACTIVE && !activate))
return new GridFinishedFuture<>();
final UUID requestId = UUID.randomUUID();
final GridChangeGlobalStateFuture cgsFut = new GridChangeGlobalStateFuture(requestId, activate, ctx);
if (!cgsLocFut.compareAndSet(null, cgsFut)) {
GridChangeGlobalStateFuture locF = cgsLocFut.get();
if (locF.activate == activate)
return locF;
else
return new GridFinishedFuture<>(new IgniteException("fail " + prettyStr(activate) + ", because now in progress" + prettyStr(locF.activate)));
}
try {
if (ctx.clientNode()) {
AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute().withAsync();
if (log.isInfoEnabled())
log.info("Send " + prettyStr(activate) + " request from client node [id=" + ctx.localNodeId() + " topVer=" + topVer + " ]");
comp.run(new ClientChangeGlobalStateComputeRequest(activate));
comp.future().listen(new CI1<IgniteFuture>() {
@Override
public void apply(IgniteFuture fut) {
try {
fut.get();
cgsFut.onDone();
} catch (Exception e) {
cgsFut.onDone(e);
}
}
});
} else {
List<DynamicCacheChangeRequest> reqs = new ArrayList<>();
DynamicCacheChangeRequest changeGlobalStateReq = new DynamicCacheChangeRequest(requestId, activate ? ACTIVE : INACTIVE, ctx.localNodeId());
reqs.add(changeGlobalStateReq);
reqs.addAll(activate ? cacheProc.startAllCachesRequests() : cacheProc.stopAllCachesRequests());
ChangeGlobalStateMessage changeGlobalStateMsg = new ChangeGlobalStateMessage(requestId, ctx.localNodeId(), activate, new DynamicCacheChangeBatch(reqs));
try {
ctx.discovery().sendCustomEvent(changeGlobalStateMsg);
if (ctx.isStopping())
cgsFut.onDone(new IgniteCheckedException("Failed to execute " + prettyStr(activate) + " request, " + "node is stopping."));
} catch (IgniteCheckedException e) {
log.error("Fail create or send change global state request." + cgsFut, e);
cgsFut.onDone(e);
}
}
} catch (IgniteCheckedException e) {
log.error("Fail create or send change global state request." + cgsFut, e);
cgsFut.onDone(e);
}
return cgsFut;
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class ComputeAsyncExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
* @throws IgniteException If example execution failed.
*/
public static void main(String[] args) throws IgniteException {
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
System.out.println();
System.out.println("Compute asynchronous example started.");
// Enable asynchronous mode.
IgniteCompute compute = ignite.compute().withAsync();
Collection<IgniteFuture<?>> futs = new ArrayList<>();
// Iterate through all words in the sentence and create runnable jobs.
for (final String word : "Print words using runnable".split(" ")) {
// Execute runnable on some node.
compute.run(() -> {
System.out.println();
System.out.println(">>> Printing '" + word + "' on this node from ignite job.");
});
futs.add(compute.future());
}
// Wait for completion of all futures.
futs.forEach(IgniteFuture::get);
System.out.println();
System.out.println(">>> Finished printing words using runnable execution.");
System.out.println(">>> Check all nodes for output (this node is also part of the cluster).");
}
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridTaskExecutionSelfTest method testJobIdCollision.
/**
* Test for https://issues.apache.org/jira/browse/IGNITE-1384
*
* @throws Exception If failed.
*/
public void testJobIdCollision() throws Exception {
fail("Test refactoring is needed: https://issues.apache.org/jira/browse/IGNITE-4706");
long locId = IgniteUuid.lastLocalId();
ArrayList<IgniteFuture<Object>> futs = new ArrayList<>(2016);
IgniteCompute compute = grid(1).compute(grid(1).cluster().forNodeId(grid(3).localNode().id()));
for (int i = 0; i < 1000; i++) {
futs.add(compute.callAsync(new IgniteCallable<Object>() {
@JobContextResource
ComputeJobContext ctx;
boolean held;
@Override
public Object call() throws Exception {
if (!held) {
ctx.holdcc(1000);
held = true;
}
return null;
}
}));
}
info("Finished first loop.");
AtomicLong idx = U.field(IgniteUuid.class, "cntGen");
idx.set(locId);
IgniteCompute compute1 = grid(2).compute(grid(2).cluster().forNodeId(grid(3).localNode().id()));
for (int i = 0; i < 100; i++) {
futs.add(compute1.callAsync(new IgniteCallable<Object>() {
@JobContextResource
ComputeJobContext ctx;
boolean held;
@Override
public Object call() throws Exception {
if (!held) {
ctx.holdcc(1000);
held = true;
}
return null;
}
}));
}
for (IgniteFuture<Object> fut : futs) fut.get();
}
Aggregations