Search in sources :

Example 56 with IgniteException

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);
    }
}
Also used : IgniteException(org.apache.ignite.IgniteException) Ignite(org.apache.ignite.Ignite)

Example 57 with IgniteException

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);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteException(org.apache.ignite.IgniteException) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 58 with IgniteException

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());
            }
        });
    }
}
Also used : EVTS_TASK_EXECUTION(org.apache.ignite.events.EventType.EVTS_TASK_EXECUTION) Ignition(org.apache.ignite.Ignition) IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) IgniteException(org.apache.ignite.IgniteException) TaskSessionResource(org.apache.ignite.resources.TaskSessionResource) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) UUID(java.util.UUID) Ignite(org.apache.ignite.Ignite) ExampleNodeStartup(org.apache.ignite.examples.ExampleNodeStartup) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession) TaskEvent(org.apache.ignite.events.TaskEvent) TaskEvent(org.apache.ignite.events.TaskEvent) Ignite(org.apache.ignite.Ignite) TaskSessionResource(org.apache.ignite.resources.TaskSessionResource) UUID(java.util.UUID) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) ComputeTaskSession(org.apache.ignite.compute.ComputeTaskSession)

Example 59 with IgniteException

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);
    }
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) PendingRow(org.apache.ignite.internal.processors.cache.tree.PendingRow)

Example 60 with IgniteException

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);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) IgniteException(org.apache.ignite.IgniteException) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) CacheObjectContext(org.apache.ignite.internal.processors.cache.CacheObjectContext) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration)

Aggregations

IgniteException (org.apache.ignite.IgniteException)498 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)160 Ignite (org.apache.ignite.Ignite)97 ClusterNode (org.apache.ignite.cluster.ClusterNode)54 ArrayList (java.util.ArrayList)52 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)45 CountDownLatch (java.util.concurrent.CountDownLatch)44 UUID (java.util.UUID)43 IOException (java.io.IOException)39 CacheException (javax.cache.CacheException)35 HashMap (java.util.HashMap)34 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)34 Transaction (org.apache.ignite.transactions.Transaction)34 List (java.util.List)24 CyclicBarrier (java.util.concurrent.CyclicBarrier)21 Map (java.util.Map)20 Collection (java.util.Collection)18 ClusterStartNodeResult (org.apache.ignite.cluster.ClusterStartNodeResult)18 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)18 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)17