use of org.apache.ignite.IgniteException in project ignite by apache.
the class GridP2PDisabledSelfTest method checkClassNotFound.
/**
* Test what happens if peer class loading is disabled.
*
* @throws Exception if error occur.
*/
@SuppressWarnings("unchecked")
private void checkClassNotFound() throws Exception {
initGar = false;
try {
Ignite ignite1 = startGrid(1);
Ignite ignite2 = startGrid(2);
Class task = extLdr.loadClass(TASK_NAME);
try {
ignite1.compute().execute(task, ignite2.cluster().localNode().id());
assert false;
} catch (IgniteException e) {
info("Received expected exception: " + e);
}
} finally {
stopGrid(1);
stopGrid(2);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class MessagingPingPongListenActorExample method main.
/**
* Executes example.
*
* @param args Command line arguments, none required.
*/
public static void main(String[] args) {
// Game is played over the default ignite.
try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
return;
System.out.println();
System.out.println(">>> Messaging ping-pong listen actor example started.");
// Pick first remote node as a partner.
Collection<ClusterNode> rmtNodes = ignite.cluster().forRemotes().nodes();
ClusterGroup nodeB = ignite.cluster().forNode(rmtNodes.iterator().next());
// Note that both nodeA and nodeB will always point to
// same nodes regardless of whether they were implicitly
// serialized and deserialized on another node as part of
// anonymous closure's state during its remote execution.
// Set up remote player.
ignite.message(nodeB).remoteListen(null, new MessagingListenActor<String>() {
@Override
public void receive(UUID nodeId, String rcvMsg) {
System.out.println(rcvMsg);
if ("PING".equals(rcvMsg))
respond("PONG");
else if ("STOP".equals(rcvMsg))
stop();
}
});
int MAX_PLAYS = 10;
final CountDownLatch cnt = new CountDownLatch(MAX_PLAYS);
// Set up local player.
ignite.message().localListen(null, new MessagingListenActor<String>() {
@Override
protected void receive(UUID nodeId, String rcvMsg) throws IgniteException {
System.out.println(rcvMsg);
if (cnt.getCount() == 1)
stop("STOP");
else if ("PONG".equals(rcvMsg))
respond("PING");
cnt.countDown();
}
});
// Serve!
ignite.message(nodeB).send(null, "PING");
// Wait til the game is over.
try {
cnt.await();
} catch (InterruptedException e) {
System.err.println("Hm... let us finish the game!\n" + e);
}
}
}
use of org.apache.ignite.IgniteException 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.IgniteException in project ignite by apache.
the class IgniteCacheOffheapManagerImpl method removeCacheData.
/**
* @param cacheId Cache ID.
*/
private void removeCacheData(int cacheId) {
assert grp.affinityNode();
try {
if (grp.sharedGroup()) {
assert cacheId != CU.UNDEFINED_CACHE_ID;
assert ctx.database().checkpointLockIsHeldByThread();
for (CacheDataStore store : cacheDataStores()) store.clear(cacheId);
if (pendingEntries != null) {
PendingRow row = new PendingRow(cacheId);
GridCursor<PendingRow> cursor = pendingEntries.find(row, row, PendingEntriesTree.WITHOUT_KEY);
while (cursor.next()) {
boolean res = pendingEntries.removex(cursor.get());
assert res;
}
}
}
} catch (IgniteCheckedException e) {
throw new IgniteException(e.getMessage(), e);
}
}
use of org.apache.ignite.IgniteException in project ignite by apache.
the class GridCacheAffinityImpl method affinityKey.
/**
* {@inheritDoc}
*/
@Override
public Object affinityKey(K key) {
A.notNull(key, "key");
if (key instanceof CacheObject && !(key instanceof BinaryObject)) {
CacheObjectContext ctx = cctx.cacheObjectContext();
if (ctx == null)
throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
key = ((CacheObject) key).value(ctx, false);
}
CacheConfiguration ccfg = cctx.config();
if (ccfg == null)
throw new IgniteException(FAILED_TO_FIND_CACHE_ERR_MSG + cctx.name());
return ccfg.getAffinityMapper().affinityKey(key);
}
Aggregations