Search in sources :

Example 56 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class ServerRegionFunctionExecutor method getServerRegionProxy.

private ServerRegionProxy getServerRegionProxy() throws FunctionException {
    ServerRegionProxy srp = region.getServerProxy();
    if (srp != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Found server region proxy on region. RegionName: {}", region.getName());
        }
        return srp;
    } else {
        StringBuilder message = new StringBuilder();
        message.append(srp).append(": ");
        message.append("No available connection was found. Server Region Proxy is not available for this region ").append(region.getName());
        throw new FunctionException(message.toString());
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) FunctionException(org.apache.geode.cache.execute.FunctionException)

Example 57 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class ClientExporter method export.

@Override
public long export(Region<K, V> region, ExportSink sink, SnapshotOptions<K, V> options) throws IOException {
    try {
        ClientArgs<K, V> args = new ClientArgs<K, V>(region.getFullPath(), pool.getPRSingleHopEnabled(), options);
        ClientExportCollector results = new ClientExportCollector(sink);
        // For single hop we rely on tcp queuing to throttle the export; otherwise
        // we allow the WindowedExporter to provide back pressure.
        Execution exec = pool.getPRSingleHopEnabled() ? FunctionService.onRegion(region) : FunctionService.onServer(pool);
        ResultCollector<?, ?> rc = exec.setArguments(args).withCollector(results).execute(new ProxyExportFunction<K, V>());
        // check for errors.
        return (Long) rc.getResult();
    } catch (FunctionException e) {
        throw new IOException(e);
    }
}
Also used : Execution(org.apache.geode.cache.execute.Execution) AtomicLong(java.util.concurrent.atomic.AtomicLong) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException)

Example 58 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class MemberFunctionExecutor method executeFunction.

@SuppressWarnings("unchecked")
private ResultCollector executeFunction(final Function function, ResultCollector resultCollector) {
    final DM dm = this.ds.getDistributionManager();
    final Set dest = new HashSet(this.members);
    if (dest.isEmpty()) {
        throw new FunctionException(LocalizedStrings.MemberFunctionExecutor_NO_MEMBER_FOUND_FOR_EXECUTING_FUNCTION_0.toLocalizedString(function.getId()));
    }
    validateExecution(function, dest);
    setExecutionNodes(dest);
    final InternalDistributedMember localVM = this.ds.getDistributionManager().getDistributionManagerId();
    final LocalResultCollector<?, ?> localRC = getLocalResultCollector(function, resultCollector);
    boolean remoteOnly = false;
    boolean localOnly = false;
    if (!dest.contains(localVM)) {
        remoteOnly = true;
    }
    if (dest.size() == 1 && dest.contains(localVM)) {
        localOnly = true;
    }
    final MemberFunctionResultSender resultSender = new MemberFunctionResultSender(dm, localRC, function, localOnly, remoteOnly, sender);
    if (dest.contains(localVM)) {
        // if member is local VM
        dest.remove(localVM);
        final FunctionContext context = new FunctionContextImpl(function.getId(), getArgumentsForMember(localVM.getId()), resultSender);
        boolean isTx = false;
        InternalCache cache = GemFireCacheImpl.getInstance();
        if (cache != null) {
            isTx = cache.getTxManager().getTXState() == null ? false : true;
        }
        executeFunctionOnLocalNode(function, context, resultSender, dm, isTx);
    }
    if (!dest.isEmpty()) {
        HashMap<InternalDistributedMember, Object> memberArgs = new HashMap<InternalDistributedMember, Object>();
        Iterator<DistributedMember> iter = dest.iterator();
        while (iter.hasNext()) {
            InternalDistributedMember recip = (InternalDistributedMember) iter.next();
            memberArgs.put(recip, getArgumentsForMember(recip.getId()));
        }
        Assert.assertTrue(memberArgs.size() == dest.size());
        MemberFunctionResultWaiter resultReciever = new MemberFunctionResultWaiter(this.ds, localRC, function, memberArgs, dest, resultSender);
        ResultCollector reply = resultReciever.getFunctionResultFrom(dest, function, this);
        return reply;
    }
    return localRC;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) FunctionException(org.apache.geode.cache.execute.FunctionException) DM(org.apache.geode.distributed.internal.DM) InternalCache(org.apache.geode.internal.cache.InternalCache) FunctionContext(org.apache.geode.cache.execute.FunctionContext) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) ResultCollector(org.apache.geode.cache.execute.ResultCollector) HashSet(java.util.HashSet)

Example 59 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class MemberFunctionResultSender method sendResult.

public void sendResult(Object oneResult) {
    if (!this.function.hasResult()) {
        throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
    }
    if (this.serverSender != null) {
        // Client-Server
        if (logger.isDebugEnabled()) {
            logger.debug("MemberFunctionResultSender sending result from local node to client {}", oneResult);
        }
        this.serverSender.sendResult(oneResult);
    } else {
        // P2P
        if (this.msg != null) {
            try {
                this.msg.sendReplyForOneResult(dm, oneResult, false, enableOrderedResultStreming);
            } catch (QueryException e) {
                throw new FunctionException(e);
            } catch (ForceReattemptException e) {
                throw new FunctionException(e);
            } catch (InterruptedException e) {
                throw new FunctionException(e);
            }
        } else {
            this.rc.addResult(this.dm.getDistributionManagerId(), oneResult);
            FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReceived();
        }
        // incrementing result sent stats.
        FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReturned();
    }
}
Also used : QueryException(org.apache.geode.cache.query.QueryException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException)

Example 60 with FunctionException

use of org.apache.geode.cache.execute.FunctionException in project geode by apache.

the class MemberFunctionResultSender method lastResult.

public void lastResult(Object oneResult) {
    if (!this.function.hasResult()) {
        throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
    }
    if (this.serverSender != null) {
        // client-server
        if (this.localLastResultRecieved) {
            return;
        }
        if (onlyLocal) {
            this.serverSender.lastResult(oneResult);
            this.rc.endResults();
            this.localLastResultRecieved = true;
        } else {
            lastResult(oneResult, rc, false, true, this.dm.getId());
        }
    } else {
        // P2P
        if (this.msg != null) {
            try {
                this.msg.sendReplyForOneResult(dm, oneResult, true, enableOrderedResultStreming);
            } catch (QueryException e) {
                throw new FunctionException(e);
            } catch (ForceReattemptException e) {
                throw new FunctionException(e);
            } catch (InterruptedException e) {
                throw new FunctionException(e);
            }
        } else {
            if (this.localLastResultRecieved) {
                return;
            }
            if (onlyLocal) {
                this.rc.addResult(this.dm.getDistributionManagerId(), oneResult);
                this.rc.endResults();
                this.localLastResultRecieved = true;
            } else {
                // call a synchronized method as local node is also waiting to send lastResult
                lastResult(oneResult, rc, false, true, this.dm.getDistributionManagerId());
            }
            FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReceived();
        }
    }
    FunctionStats.getFunctionStats(function.getId(), this.dm.getSystem()).incResultsReturned();
}
Also used : QueryException(org.apache.geode.cache.query.QueryException) ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException)

Aggregations

FunctionException (org.apache.geode.cache.execute.FunctionException)140 Function (org.apache.geode.cache.execute.Function)45 Execution (org.apache.geode.cache.execute.Execution)39 ResultCollector (org.apache.geode.cache.execute.ResultCollector)39 ArrayList (java.util.ArrayList)38 Test (org.junit.Test)38 HashSet (java.util.HashSet)36 CacheClosedException (org.apache.geode.cache.CacheClosedException)31 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)31 IOException (java.io.IOException)30 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)30 List (java.util.List)26 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)26 Host (org.apache.geode.test.dunit.Host)25 VM (org.apache.geode.test.dunit.VM)25 Region (org.apache.geode.cache.Region)24 IgnoredException (org.apache.geode.test.dunit.IgnoredException)24 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)24 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)22 Set (java.util.Set)21