To send tasks to all remote nodes, you need to get the remote cluster group and then create a compute object from the remote compute group. The code will look as follows, but you need a remote Apache Ignite server instance to verify the code's execution:
package com.packt;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCluster;
import org.apache.ignite.IgniteCompute;
import org.apache.ignite.Ignition;
import org.apache.ignite.cluster.ClusterGroup;
import org.apache.ignite.configuration.IgniteConfiguration;
public class RemoteNodes {
public static void main(String[] args) {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setPeerClassLoadingEnabled(true);
try (Ignite ignite = Ignition.start(cfg)) {
IgniteCluster cluster = ignite.cluster();
//Get remote server group
ClusterGroup forRemotes = cluster.forRemotes();
//Get a compute task for remote servers
IgniteCompute compute = ignite.compute(forRemotes);
//broadcast the computation to remote nodes
compute.broadcast(() -> {
System.out.println("Only remote nodes");
});
}
}
}