Search in sources :

Example 41 with ClusterGroup

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

the class TcpCommunicationStatisticsTest method testStatistics.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("ConstantConditions")
public void testStatistics() throws Exception {
    startGrids(2);
    try {
        // Send custom message from node0 to node1.
        grid(0).context().io().sendToGridTopic(grid(1).cluster().localNode(), GridTopic.TOPIC_IO_TEST, new GridTestMessage(), GridIoPolicy.PUBLIC_POOL);
        latch.await(10, TimeUnit.SECONDS);
        ClusterGroup clusterGroupNode1 = grid(0).cluster().forNodeId(grid(1).localNode().id());
        // Send job from node0 to node1.
        grid(0).compute(clusterGroupNode1).call(new IgniteCallable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
                return Boolean.TRUE;
            }
        });
        synchronized (mux) {
            TcpCommunicationSpiMBean mbean0 = mbean(0);
            TcpCommunicationSpiMBean mbean1 = mbean(1);
            Map<UUID, Long> msgsSentByNode0 = mbean0.getSentMessagesByNode();
            Map<UUID, Long> msgsSentByNode1 = mbean1.getSentMessagesByNode();
            Map<UUID, Long> msgsReceivedByNode0 = mbean0.getReceivedMessagesByNode();
            Map<UUID, Long> msgsReceivedByNode1 = mbean1.getReceivedMessagesByNode();
            UUID nodeId0 = grid(0).localNode().id();
            UUID nodeId1 = grid(1).localNode().id();
            assertEquals(msgsReceivedByNode0.get(nodeId1).longValue(), mbean0.getReceivedMessagesCount());
            assertEquals(msgsReceivedByNode1.get(nodeId0).longValue(), mbean1.getReceivedMessagesCount());
            assertEquals(msgsSentByNode0.get(nodeId1).longValue(), mbean0.getSentMessagesCount());
            assertEquals(msgsSentByNode1.get(nodeId0).longValue(), mbean1.getSentMessagesCount());
            assertEquals(mbean0.getSentMessagesCount(), mbean1.getReceivedMessagesCount());
            assertEquals(mbean1.getSentMessagesCount(), mbean0.getReceivedMessagesCount());
            Map<String, Long> msgsSentByType0 = mbean0.getSentMessagesByType();
            Map<String, Long> msgsSentByType1 = mbean1.getSentMessagesByType();
            Map<String, Long> msgsReceivedByType0 = mbean0.getReceivedMessagesByType();
            Map<String, Long> msgsReceivedByType1 = mbean1.getReceivedMessagesByType();
            // Node0 sent exactly the same types and count of messages as node1 received.
            assertEquals(msgsSentByType0, msgsReceivedByType1);
            // Node1 sent exactly the same types and count of messages as node0 received.
            assertEquals(msgsSentByType1, msgsReceivedByType0);
            assertEquals(1, msgsSentByType0.get(GridTestMessage.class.getName()).longValue());
            assertEquals(1, msgsReceivedByType1.get(GridTestMessage.class.getName()).longValue());
        }
    } finally {
        stopAllGrids();
    }
}
Also used : GridTestMessage(org.apache.ignite.spi.communication.GridTestMessage) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) UUID(java.util.UUID) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IgniteException(org.apache.ignite.IgniteException) MalformedObjectNameException(javax.management.MalformedObjectNameException)

Example 42 with ClusterGroup

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

the class IgniteEventsEndpoint method createIgniteEvents.

private IgniteEvents createIgniteEvents() {
    Ignite ignite = ignite();
    IgniteEvents events;
    if (clusterGroupExpression == null) {
        LOG.info("Ignite Events endpoint for event types {} using no Cluster Group.", this.events);
        events = ignite.events();
    } else {
        ClusterGroup group = clusterGroupExpression.getClusterGroup(ignite);
        LOG.info("Ignite Events endpoint for event types {} using Cluster Group: {}.", this.events, group);
        events = ignite.events(group);
    }
    return events;
}
Also used : IgniteEvents(org.apache.ignite.IgniteEvents) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 43 with ClusterGroup

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

the class ClusterGroupExample 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")) {
        if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
            return;
        System.out.println();
        System.out.println("Compute example started.");
        IgniteCluster cluster = ignite.cluster();
        // Say hello to all nodes in the cluster, including local node.
        sayHello(ignite, cluster);
        // Say hello to all remote nodes.
        sayHello(ignite, cluster.forRemotes());
        // Pick random node out of remote nodes.
        ClusterGroup randomNode = cluster.forRemotes().forRandom();
        // Say hello to a random node.
        sayHello(ignite, randomNode);
        // Say hello to all nodes residing on the same host with random node.
        sayHello(ignite, cluster.forHost(randomNode.node()));
        // Say hello to all nodes that have current CPU load less than 50%.
        sayHello(ignite, cluster.forPredicate(new IgnitePredicate<ClusterNode>() {

            @Override
            public boolean apply(ClusterNode n) {
                return n.metrics().getCurrentCpuLoad() < 0.5;
            }
        }));
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCluster(org.apache.ignite.IgniteCluster) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 44 with ClusterGroup

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

the class ClusterGroupExample 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")) {
        if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
            return;
        System.out.println();
        System.out.println("Compute example started.");
        IgniteCluster cluster = ignite.cluster();
        // Say hello to all nodes in the cluster, including local node.
        sayHello(ignite, cluster);
        // Say hello to all remote nodes.
        sayHello(ignite, cluster.forRemotes());
        // Pick random node out of remote nodes.
        ClusterGroup randomNode = cluster.forRemotes().forRandom();
        // Say hello to a random node.
        sayHello(ignite, randomNode);
        // Say hello to all nodes residing on the same host with random node.
        sayHello(ignite, cluster.forHost(randomNode.node()));
        // Say hello to all nodes that have current CPU load less than 50%.
        sayHello(ignite, cluster.forPredicate(n -> n.metrics().getCurrentCpuLoad() < 0.5));
    }
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignition(org.apache.ignite.Ignition) IgniteCluster(org.apache.ignite.IgniteCluster) ExamplesUtils(org.apache.ignite.examples.ExamplesUtils) IgniteException(org.apache.ignite.IgniteException) Ignite(org.apache.ignite.Ignite) ExampleNodeStartup(org.apache.ignite.examples.ExampleNodeStartup) IgniteCluster(org.apache.ignite.IgniteCluster) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite)

Example 45 with ClusterGroup

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

the class MessagingExample method main.

/**
     * Executes example.
     *
     * @param args Command line arguments, none required.
     * @throws IgniteException If example execution failed.
     */
public static void main(String[] args) throws Exception {
    try (Ignite ignite = Ignition.start("examples/config/example-ignite.xml")) {
        if (!ExamplesUtils.checkMinTopologySize(ignite.cluster(), 2))
            return;
        System.out.println();
        System.out.println(">>> Messaging example started.");
        // Group for remote nodes.
        ClusterGroup rmtGrp = ignite.cluster().forRemotes();
        // Listen for messages from remote nodes to make sure that they received all the messages.
        int msgCnt = rmtGrp.nodes().size() * MESSAGES_NUM;
        CountDownLatch orderedLatch = new CountDownLatch(msgCnt);
        CountDownLatch unorderedLatch = new CountDownLatch(msgCnt);
        localListen(ignite.message(ignite.cluster().forLocal()), orderedLatch, unorderedLatch);
        // Register listeners on all cluster nodes.
        startListening(ignite, ignite.message(rmtGrp));
        // Send unordered messages to all remote nodes.
        for (int i = 0; i < MESSAGES_NUM; i++) ignite.message(rmtGrp).send(TOPIC.UNORDERED, Integer.toString(i));
        System.out.println(">>> Finished sending unordered messages.");
        // Send ordered messages to all remote nodes.
        for (int i = 0; i < MESSAGES_NUM; i++) ignite.message(rmtGrp).sendOrdered(TOPIC.ORDERED, Integer.toString(i), 0);
        System.out.println(">>> Finished sending ordered messages.");
        System.out.println(">>> Check output on all nodes for message printouts.");
        System.out.println(">>> Will wait for messages acknowledgements from all remote nodes.");
        orderedLatch.await();
        unorderedLatch.await();
        System.out.println(">>> Messaging example finished.");
    }
}
Also used : ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) CountDownLatch(java.util.concurrent.CountDownLatch)

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