Search in sources :

Example 1 with MemberFunctionResultSender

use of org.apache.geode.internal.cache.execute.MemberFunctionResultSender in project geode by apache.

the class MemberFunctionStreamingMessage method process.

@Override
protected void process(final DistributionManager dm) {
    Throwable thr = null;
    ReplyException rex = null;
    if (this.functionObject == null) {
        rex = new ReplyException(new FunctionException(LocalizedStrings.ExecuteFunction_FUNCTION_NAMED_0_IS_NOT_REGISTERED.toLocalizedString(this.functionName)));
        replyWithException(dm, rex);
        return;
    }
    FunctionStats stats = FunctionStats.getFunctionStats(this.functionObject.getId(), dm.getSystem());
    TXStateProxy tx = null;
    try {
        tx = prepForTransaction();
        ResultSender resultSender = new MemberFunctionResultSender(dm, this, this.functionObject);
        Set<Region> regions = new HashSet<Region>();
        if (this.regionPathSet != null) {
            InternalCache cache = GemFireCacheImpl.getInstance();
            for (String regionPath : this.regionPathSet) {
                if (checkCacheClosing(dm) || checkDSClosing(dm)) {
                    thr = new CacheClosedException(LocalizedStrings.PartitionMessage_REMOTE_CACHE_IS_CLOSED_0.toLocalizedString(dm.getId()));
                    return;
                }
                regions.add(cache.getRegion(regionPath));
            }
        }
        FunctionContextImpl context = new MultiRegionFunctionContextImpl(this.functionObject.getId(), this.args, resultSender, regions, isReExecute);
        long start = stats.startTime();
        stats.startFunctionExecution(this.functionObject.hasResult());
        if (logger.isDebugEnabled()) {
            logger.debug("Executing Function: {} on remote member with context: {}", this.functionObject.getId(), context.toString());
        }
        this.functionObject.execute(context);
        if (!this.replyLastMsg && this.functionObject.hasResult()) {
            throw new FunctionException(LocalizedStrings.ExecuteFunction_THE_FUNCTION_0_DID_NOT_SENT_LAST_RESULT.toString(functionObject.getId()));
        }
        stats.endFunctionExecution(start, this.functionObject.hasResult());
    } catch (FunctionException functionException) {
        if (logger.isDebugEnabled()) {
            logger.debug("FunctionException occurred on remote member while executing Function: {}", this.functionObject.getId(), functionException);
        }
        stats.endFunctionExecutionWithException(this.functionObject.hasResult());
        rex = new ReplyException(functionException);
        replyWithException(dm, rex);
    // thr = functionException.getCause();
    } catch (CancelException exception) {
        // bug 37026: this is too noisy...
        // throw new CacheClosedException("remote system shutting down");
        // thr = se; cache is closed, no point trying to send a reply
        thr = new FunctionInvocationTargetException(exception);
        stats.endFunctionExecutionWithException(this.functionObject.hasResult());
        rex = new ReplyException(thr);
        replyWithException(dm, rex);
    } catch (Exception exception) {
        if (logger.isDebugEnabled()) {
            logger.debug("Exception occurred on remote member while executing Function: {}", this.functionObject.getId(), exception);
        }
        stats.endFunctionExecutionWithException(this.functionObject.hasResult());
        rex = new ReplyException(exception);
        replyWithException(dm, rex);
    // thr = e.getCause();
    } catch (VirtualMachineError err) {
        SystemFailure.initiateFailure(err);
        // now, so don't let this thread continue.
        throw err;
    } catch (Throwable t) {
        // Whenever you catch Error or Throwable, you must also
        // catch VirtualMachineError (see above). However, there is
        // _still_ a possibility that you are dealing with a cascading
        // error condition, so you also need to check to see if the JVM
        // is still usable:
        SystemFailure.checkFailure();
        thr = t;
    } finally {
        cleanupTransaction(tx);
        if (thr != null) {
            rex = new ReplyException(thr);
            replyWithException(dm, rex);
        }
    }
}
Also used : FunctionContextImpl(org.apache.geode.internal.cache.execute.FunctionContextImpl) MultiRegionFunctionContextImpl(org.apache.geode.internal.cache.execute.MultiRegionFunctionContextImpl) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ReplyException(org.apache.geode.distributed.internal.ReplyException) MemberFunctionResultSender(org.apache.geode.internal.cache.execute.MemberFunctionResultSender) ResultSender(org.apache.geode.cache.execute.ResultSender) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) ReplyException(org.apache.geode.distributed.internal.ReplyException) QueryException(org.apache.geode.cache.query.QueryException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionStats(org.apache.geode.internal.cache.execute.FunctionStats) MemberFunctionResultSender(org.apache.geode.internal.cache.execute.MemberFunctionResultSender) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException) MultiRegionFunctionContextImpl(org.apache.geode.internal.cache.execute.MultiRegionFunctionContextImpl) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)1 HashSet (java.util.HashSet)1 CancelException (org.apache.geode.CancelException)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 CacheException (org.apache.geode.cache.CacheException)1 Region (org.apache.geode.cache.Region)1 FunctionException (org.apache.geode.cache.execute.FunctionException)1 FunctionInvocationTargetException (org.apache.geode.cache.execute.FunctionInvocationTargetException)1 ResultSender (org.apache.geode.cache.execute.ResultSender)1 QueryException (org.apache.geode.cache.query.QueryException)1 ReplyException (org.apache.geode.distributed.internal.ReplyException)1 FunctionContextImpl (org.apache.geode.internal.cache.execute.FunctionContextImpl)1 FunctionStats (org.apache.geode.internal.cache.execute.FunctionStats)1 MemberFunctionResultSender (org.apache.geode.internal.cache.execute.MemberFunctionResultSender)1 MultiRegionFunctionContextImpl (org.apache.geode.internal.cache.execute.MultiRegionFunctionContextImpl)1