Search in sources :

Example 1 with MemberFunctionExecutor

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();
    }
}
Also used : MemberFunctionExecutor(org.apache.geode.internal.cache.execute.MemberFunctionExecutor) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) Execution(org.apache.geode.cache.execute.Execution) AbstractExecution(org.apache.geode.internal.cache.execute.AbstractExecution) DistributedMember(org.apache.geode.distributed.DistributedMember) ArrayList(java.util.ArrayList) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) HashSet(java.util.HashSet)

Aggregations

ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Execution (org.apache.geode.cache.execute.Execution)1 DistributedMember (org.apache.geode.distributed.DistributedMember)1 DistributedSystem (org.apache.geode.distributed.DistributedSystem)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 AbstractExecution (org.apache.geode.internal.cache.execute.AbstractExecution)1 MemberFunctionExecutor (org.apache.geode.internal.cache.execute.MemberFunctionExecutor)1