use of org.apache.geode.internal.cache.execute.MemberFunctionExecutor in project geode by apache.
the class ExecuteFunction70 method executeFunctionOnGroups.
@Override
protected void executeFunctionOnGroups(Object function, Object args, String[] groups, boolean allMembers, Function functionObject, ServerToClientFunctionResultSender resultSender, boolean ignoreFailedMembers) {
DistributedSystem ds = InternalDistributedSystem.getConnectedInstance();
if (ds == null) {
throw new IllegalStateException(LocalizedStrings.ExecuteFunction_DS_NOT_CREATED_OR_NOT_READY.toLocalizedString());
}
Set<DistributedMember> members = new HashSet<DistributedMember>();
for (String group : groups) {
if (allMembers) {
members.addAll(ds.getGroupMembers(group));
} else {
ArrayList<DistributedMember> memberList = new ArrayList<DistributedMember>(ds.getGroupMembers(group));
if (!memberList.isEmpty()) {
if (!FunctionServiceManager.RANDOM_onMember && memberList.contains(ds.getDistributedMember())) {
members.add(ds.getDistributedMember());
} else {
Collections.shuffle(memberList);
members.add(memberList.get(0));
}
}
}
}
if (logger.isDebugEnabled()) {
logger.debug("Executing Function on Groups: {} all members: {} members are: {}", Arrays.toString(groups), allMembers, members);
}
Execution execution = new MemberFunctionExecutor(ds, members, resultSender);
if (args != null) {
execution = execution.setArguments(args);
}
if (ignoreFailedMembers) {
if (logger.isDebugEnabled()) {
logger.debug("Function will ignore failed members");
}
((AbstractExecution) execution).setIgnoreDepartedMembers(true);
}
if (!functionObject.isHA()) {
((AbstractExecution) execution).setWaitOnExceptionFlag(true);
}
if (function instanceof String) {
execution.execute(functionObject.getId()).getResult();
} else {
execution.execute(functionObject).getResult();
}
}
Aggregations