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();
}
}
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;
}
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;
}
}));
}
}
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));
}
}
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.");
}
}
Aggregations