Hello Ricky,
There are several ways you can accomplish this.
1) You can create a policy that accepts either a local node or a slave node:
public static ExecutionPolicy createLocalOrSlavePolicy() {
return new Equal("jppf.channel.local", true).or(new Equal("jppf.node.provisioning.slave", true));
}
Here, we use the fact that each master or slave carries 2 boolean
configuration properties, "jppf.node.provisioning.master" and "jppf.node.provisioning.slave". Their values are (true, false) for a master node and (false, true) for a slave node. These values are automatically set by JPPF.
2) You can use the fact that the local node and its slaves are all on the same machine, and create an IP address-based policy, using the IP address of the driver which is also on the same machine:
public static ExecutionPolicy createIPPolicy(JPPFClient jppfClient) throws Exception {
// obtain the ip address from the driver connection pool
String ip = jppfClient.awaitWorkingConnectionPool().getDriverIPAddress();
// return a policy based on whether this is an IPv4 or IPv6 address
InetAddress addr = InetAddress.getByName(ip);
return (addr instanceof Inet4Address) ? new IsInIPv4Subnet(ip) : new IsInIPv6Subnet(ip);
}
Note that a drawback of this method is that it won't work if you have another master node on the same machine. For more details, I invite you to look at the javadoc for
IsInIPv4Subnet and
IsInIPv6Subnet.
3) You can also use the fact that each slave node carries the UUID of its master node via the string property "jppf.node.provisioning.master.uuid". Unfortunately, this property is not well documented, see the doc bug
JPPF-521 Document the "jppf.node.provisioning.master.uuid" configuration property. Example:
public static ExecutionPolicy createMasterGroupPolicy(JPPFClient jppfClient) throws Exception {
// find the uuid of the master node via JMX
JMXDriverConnectionWrapper jmx = jppfClient.awaitWorkingConnectionPool().awaitWorkingJMXConnection();
// restrict the node search to the local node via a node selector
Collection<JPPFManagementInfo> infos = jmx.nodesInformation(new ExecutionPolicySelector(new Equal("jppf.channel.local", true)));
JPPFManagementInfo info = infos.iterator().next();
return new Equal("jppf.channel.local", true).or(new Equal("jppf.node.provisioning.master.uuid", false, info.getUuid()));
}
Lastly, if you wish to exclude the local node and its slaves, you can simply negate the execution policy that includes them:
ExecutionPolicy includePolicy = ...;
ExecutionPolicy excludePolicy;
// the following 2 lines are equivalent
excludePolicy = includePolicy.not();
excludePolicy = new ExecutionPolicy.NotRule(includePolicy);
I hope this helps,
-Laurent