Search in sources :

Example 36 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class IgniteMessagingConfigVariationFullApiTest method localListenerInternal.

/**
 * Single server test with local listener.
 * @throws Exception If failed.
 */
private void localListenerInternal() throws Exception {
    int messages = MSGS;
    Ignite ignite = grid(SERVER_NODE_IDX);
    LATCH = new CountDownLatch(messages);
    ClusterGroup grp = grid(SERVER_NODE_IDX).cluster().forLocal();
    MessageListener c = new MessageListener();
    try {
        ignite.message(grp).localListen("localListenerTopic", c);
        for (int i = 0; i < messages; i++) ignite.message(grp).send("localListenerTopic", value(i));
        assertTrue(LATCH.await(10, TimeUnit.SECONDS));
    } finally {
        ignite.message().stopLocalListen("localListenerTopic", c);
    }
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 37 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class IgniteMessagingConfigVariationFullApiTest method serverClientMessage.

/**
 * Server sends a message and client receives it.
 *
 * @param async Async message send flag.
 * @throws Exception If failed.
 */
private void serverClientMessage(boolean async) throws Exception {
    Ignite ignite = grid(SERVER_NODE_IDX);
    ClusterGroup grp = ignite.cluster().forClients();
    assert grp.nodes().size() > 0;
    registerListenerAndSendMessages(ignite, grp, async);
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 38 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class IgniteMessagingConfigVariationFullApiTest method serverClientOrderedMessage.

/**
 * @throws Exception If fail.
 */
private void serverClientOrderedMessage() throws Exception {
    Ignite ignite = grid(SERVER_NODE_IDX);
    ClusterGroup grp = ignite.cluster().forClients();
    assert grp.nodes().size() > 0;
    registerListenerAndSendOrderedMessages(ignite, grp);
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 39 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class GridProjectionForCachesOnDaemonNodeSelfTest method testForCacheNodes.

/**
 * @throws Exception If failed.
 */
public void testForCacheNodes() throws Exception {
    ClusterGroup grp = ignite.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
    assertFalse(grp.nodes().isEmpty());
    try {
        daemon.cluster().forCacheNodes(DEFAULT_CACHE_NAME);
    } catch (IllegalStateException ignored) {
        return;
    }
    fail();
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup)

Example 40 with ClusterGroup

use of org.apache.ignite.cluster.ClusterGroup in project ignite by apache.

the class TcpCommunicationSpiHalfOpenedConnectionTest method checkReconnect.

/**
 * @throws Exception If failed.
 */
private void checkReconnect() throws Exception {
    Ignite srv = startGrid("server");
    Ignite client = startGrid("client");
    UUID nodeId = srv.cluster().localNode().id();
    System.out.println(">> Server ID: " + nodeId);
    ClusterGroup srvGrp = client.cluster().forNodeId(nodeId);
    System.out.println(">> Send job");
    // Establish connection
    client.compute(srvGrp).run(F.noop());
    ConcurrentMap<UUID, GridCommunicationClient[]> clients = U.field(clientSpi, "clients");
    ConcurrentMap<?, GridNioRecoveryDescriptor> recoveryDescs = U.field(clientSpi, "recoveryDescs");
    ConcurrentMap<?, GridNioRecoveryDescriptor> outRecDescs = U.field(clientSpi, "outRecDescs");
    ConcurrentMap<?, GridNioRecoveryDescriptor> inRecDescs = U.field(clientSpi, "inRecDescs");
    GridNioServerListener<Message> lsnr = U.field(clientSpi, "srvLsnr");
    Iterator<GridNioRecoveryDescriptor> it = F.concat(recoveryDescs.values().iterator(), outRecDescs.values().iterator(), inRecDescs.values().iterator());
    while (it.hasNext()) {
        GridNioRecoveryDescriptor desc = it.next();
        // Need to simulate connection close in GridNioServer as it
        // releases descriptors on disconnect.
        desc.release();
    }
    // Remove client to avoid calling close(), in that case server
    // will close connection too, but we want to keep the server
    // uninformed and force ping old connection.
    GridCommunicationClient[] clients0 = clients.remove(nodeId);
    for (GridCommunicationClient commClient : clients0) lsnr.onDisconnected(((GridTcpNioCommunicationClient) commClient).session(), new IOException("Test exception"));
    info(">> Removed client");
    // Reestablish connection
    client.compute(srvGrp).run(F.noop());
    info(">> Sent second job");
}
Also used : Message(org.apache.ignite.plugin.extensions.communication.Message) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) IOException(java.io.IOException) GridCommunicationClient(org.apache.ignite.internal.util.nio.GridCommunicationClient) GridTcpNioCommunicationClient(org.apache.ignite.internal.util.nio.GridTcpNioCommunicationClient) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID)

Aggregations

ClusterGroup (org.apache.ignite.cluster.ClusterGroup)86 Ignite (org.apache.ignite.Ignite)45 UUID (java.util.UUID)22 CountDownLatch (java.util.concurrent.CountDownLatch)17 ClusterNode (org.apache.ignite.cluster.ClusterNode)14 IgniteException (org.apache.ignite.IgniteException)11 ArrayList (java.util.ArrayList)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 IgniteCompute (org.apache.ignite.IgniteCompute)6 GridConcurrentHashSet (org.apache.ignite.internal.util.GridConcurrentHashSet)5 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 IgniteEx (org.apache.ignite.internal.IgniteEx)4 Map (java.util.Map)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IgniteCluster (org.apache.ignite.IgniteCluster)3 IgniteClusterEx (org.apache.ignite.internal.cluster.IgniteClusterEx)3 IgniteFuture (org.apache.ignite.lang.IgniteFuture)3 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)3 List (java.util.List)2