You can configure a node with specific attributes, similar to passing arguments to a JVM. The Apache Ignite clustering API provides a method to find cluster groups where a specific user-defined attribute is set. Now, launch a node with an attribute, 'FOO', and value, 'BAR', and set it in IgniteConfiguration:
public class NodeAttributeFoo {
public static void main(String[] args) throws InterruptedException {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setPeerClassLoadingEnabled(true);
HashMap<String, Object> userAttrb = new HashMap<>();
userAttrb.put("FOO", "BAR");
cfg.setUserAttributes(userAttrb);
try (Ignite ignite = Ignition.start(cfg)) {
while(true) {
Thread.sleep(1000);
}
}
}
}
Create a program to send compute to the nodes where the attribute 'FOO' and its value 'BAR' is set:
public class AttributeGrouping {
public static void main(String[] args) {
IgniteConfiguration cfg = new IgniteConfiguration();
cfg.setPeerClassLoadingEnabled(true);
try (Ignite ignite = Ignition.start(cfg)) {
IgniteCluster cluster = ignite.cluster();
The cluster.forAttribute takes the attribute name and its value to find all of the nodes in the cluster where the key-value pair matches:
ClusterGroup fooBarGroup = cluster.forAttribute("FOO", "BAR");
IgniteCompute fooBarGroupCompute = ignite.compute(fooBarGroup);
// broadcast the computation to fooBar nodes
fooBarGroupCompute.broadcast(() -> {
System.out.println("******** FOO BAR group ***********");
});
}
}
}
Run the program; it will only send the computation to the NodeAttributeFoo node: