use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class ComputeBroadcastExample method hello.
/**
* Print 'Hello' message on all nodes.
*
* @param ignite Ignite instance.
* @throws IgniteException If failed.
*/
private static void hello(Ignite ignite) throws IgniteException {
// Print out hello message on all nodes.
ignite.compute().broadcast(new IgniteRunnable() {
@Override
public void run() {
System.out.println();
System.out.println(">>> Hello Node! :)");
}
});
System.out.println();
System.out.println(">>> Check all nodes for hello message output.");
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class EventsExample method remoteListen.
/**
* Listen to events coming from all cluster nodes.
*
* @throws IgniteException If failed.
*/
private static void remoteListen() throws IgniteException {
System.out.println();
System.out.println(">>> Remote event listener example.");
// This optional local callback is called for each event notification
// that passed remote predicate listener.
IgniteBiPredicate<UUID, TaskEvent> locLsnr = (nodeId, evt) -> {
// Remote filter only accepts tasks whose name being with "good-task" prefix.
assert evt.taskName().startsWith("good-task");
System.out.println("Received task event [evt=" + evt.name() + ", taskName=" + evt.taskName());
// Return true to continue listening.
return true;
};
// Remote filter which only accepts tasks whose name begins with "good-task" prefix.
IgnitePredicate<TaskEvent> rmtLsnr = evt -> evt.taskName().startsWith("good-task");
Ignite ignite = Ignition.ignite();
// Register event listeners on all nodes to listen for task events.
ignite.events().remoteListen(locLsnr, rmtLsnr, EVTS_TASK_EXECUTION);
// Generate task events.
for (int i = 0; i < 10; i++) {
ignite.compute().withName(i < 5 ? "good-task-" + i : "bad-task-" + i).run(new IgniteRunnable() {
// Auto-inject task session.
@TaskSessionResource
private ComputeTaskSession ses;
@Override
public void run() {
System.out.println("Executing sample job for task: " + ses.getTaskName());
}
});
}
}
use of org.apache.ignite.lang.IgniteRunnable in project camel by apache.
the class IgniteComputeProducer method doAffinityRun.
private void doAffinityRun(final Exchange exchange, final AsyncCallback callback, IgniteCompute compute) throws Exception {
IgniteRunnable job = exchange.getIn().getBody(IgniteRunnable.class);
String affinityCache = exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_AFFINITY_CACHE_NAME, String.class);
Object affinityKey = exchange.getIn().getHeader(IgniteConstants.IGNITE_COMPUTE_AFFINITY_KEY, Object.class);
if (job == null || affinityCache == null || affinityKey == null) {
throw new RuntimeCamelException(String.format("Ignite Compute endpoint with AFFINITY_RUN executionType is only " + "supported for IgniteRunnable payloads, along with an affinity cache and key. The payload type was: %s.", exchange.getIn().getBody().getClass().getName()));
}
compute.affinityRun(affinityCache, affinityKey, job);
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class IgniteCacheLockPartitionOnAffinityRunTest method testCheckReservePartitionException.
/**
* @throws Exception If failed.
*/
public void testCheckReservePartitionException() throws Exception {
int orgId = primaryKey(grid(1).cache(Organization.class.getSimpleName()));
try {
grid(0).compute().affinityRun(Arrays.asList(Organization.class.getSimpleName(), OTHER_CACHE_NAME), new Integer(orgId), new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
fail("Exception is expected");
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Failed partition reservation. Partition is not primary on the node."));
}
try {
grid(0).compute().affinityCall(Arrays.asList(Organization.class.getSimpleName(), OTHER_CACHE_NAME), new Integer(orgId), new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
return null;
}
});
fail("Exception is expected");
} catch (Exception e) {
assertTrue(e.getMessage().startsWith("Failed partition reservation. Partition is not primary on the node."));
}
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class GridDhtPartitionsExchangeFuture method onDynamicCacheChangeFail.
/**
* Cache change failure message callback, processed from the discovery thread.
*
* @param node Message sender node.
* @param msg Failure message.
*/
public void onDynamicCacheChangeFail(final ClusterNode node, final DynamicCacheChangeFailureMessage msg) {
assert exchId.equals(msg.exchangeId()) : msg;
assert firstDiscoEvt.type() == EVT_DISCOVERY_CUSTOM_EVT && dynamicCacheStartExchange();
final ExchangeActions actions = exchangeActions();
onDiscoveryEvent(new IgniteRunnable() {
@Override
public void run() {
// The rollbackExchange() method has to wait for checkpoint.
// That operation is time consumed, and therefore it should be executed outside the discovery thread.
cctx.kernalContext().pools().getSystemExecutorService().submit(new Runnable() {
@Override
public void run() {
if (isDone() || !enterBusy())
return;
try {
assert msg.error() != null : msg;
// Try to revert all the changes that were done during initialization phase
cctx.affinity().forceCloseCaches(GridDhtPartitionsExchangeFuture.this, crd.isLocal(), msg.exchangeActions());
synchronized (mux) {
finishState = new FinishState(crd.id(), initialVersion(), null);
state = ExchangeLocalState.DONE;
}
if (actions != null)
actions.completeRequestFutures(cctx, msg.error());
onDone(exchId.topologyVersion());
} catch (Throwable e) {
onDone(e);
} finally {
leaveBusy();
}
}
});
}
});
}
Aggregations