Search in sources :

Example 16 with FunctionException

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

the class LocalResultCollectorImpl method getResult.

public Object getResult() throws FunctionException {
    if (this.resultCollected) {
        throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_ALREADY_COLLECTED.toLocalizedString());
    }
    this.resultCollected = true;
    try {
        this.latch.await();
    } catch (InterruptedException e) {
        this.latch.countDown();
        Thread.currentThread().interrupt();
    }
    this.latch = new CountDownLatch(1);
    if (this.functionException != null && !this.execution.isIgnoreDepartedMembers()) {
        if (this.function.isHA()) {
            if (this.functionException.getCause() instanceof InternalFunctionInvocationTargetException) {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(this.function);
                } else {
                    newRc = this.execution.execute(this.function.getId());
                }
                return newRc.getResult();
            }
        }
        throw this.functionException;
    } else {
        Object result = this.userRC.getResult();
        return result;
    }
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) CountDownLatch(java.util.concurrent.CountDownLatch) ResultCollector(org.apache.geode.cache.execute.ResultCollector)

Example 17 with FunctionException

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

the class LocalResultCollectorImpl method getResult.

public Object getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException {
    boolean resultRecieved = false;
    if (this.resultCollected) {
        throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_ALREADY_COLLECTED.toLocalizedString());
    }
    this.resultCollected = true;
    try {
        resultRecieved = this.latch.await(timeout, unit);
    } catch (InterruptedException e) {
        this.latch.countDown();
        Thread.currentThread().interrupt();
    }
    if (!resultRecieved) {
        throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_NOT_COLLECTED_IN_TIME_PROVIDED.toLocalizedString());
    }
    this.latch = new CountDownLatch(1);
    if (this.functionException != null && !this.execution.isIgnoreDepartedMembers()) {
        if (this.function.isHA()) {
            if (this.functionException.getCause() instanceof InternalFunctionInvocationTargetException) {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(this.function);
                } else {
                    newRc = this.execution.execute(this.function.getId());
                }
                return newRc.getResult(timeout, unit);
            }
        }
        throw this.functionException;
    } else {
        Object result = this.userRC.getResult(timeout, unit);
        return result;
    }
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) CountDownLatch(java.util.concurrent.CountDownLatch) ResultCollector(org.apache.geode.cache.execute.ResultCollector)

Example 18 with FunctionException

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

the class DistributedRegionFunctionExecutor method execute.

public ResultCollector execute(String functionName, boolean hasResult) throws FunctionException {
    if (functionName == null) {
        throw new FunctionException(LocalizedStrings.ExecuteFunction_THE_INPUT_FUNCTION_FOR_THE_EXECUTE_FUNCTION_REQUEST_IS_NULL.toLocalizedString());
    }
    Function functionObject = FunctionService.getFunction(functionName);
    if (functionObject == null) {
        throw new FunctionException(LocalizedStrings.ExecuteFunction_FUNCTION_NAMED_0_IS_NOT_REGISTERED.toLocalizedString(functionObject));
    }
    if (region.getAttributes().getDataPolicy().isNormal()) {
        throw new FunctionException(LocalizedStrings.ExecuteRegionFunction_CAN_NOT_EXECUTE_ON_NORMAL_REGION.toLocalizedString());
    }
    byte registeredFunctionState = AbstractExecution.getFunctionState(functionObject.isHA(), functionObject.hasResult(), functionObject.optimizeForWrite());
    byte functionState = AbstractExecution.getFunctionState(hasResult, hasResult, false);
    if (registeredFunctionState != functionState) {
        throw new FunctionException(LocalizedStrings.FunctionService_FUNCTION_ATTRIBUTE_MISMATCH_CLIENT_SERVER.toLocalizedString(functionName));
    }
    this.isFnSerializationReqd = false;
    // For other combination use next API
    return executeFunction(functionObject);
}
Also used : Function(org.apache.geode.cache.execute.Function) FunctionException(org.apache.geode.cache.execute.FunctionException)

Example 19 with FunctionException

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

the class DistributedRegionFunctionResultSender method lastResult.

public void lastResult(Object oneResult) {
    if (!this.functionObject.hasResult()) {
        throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
    }
    if (this.localLastResultRecieved) {
        return;
    }
    this.localLastResultRecieved = true;
    if (this.sender != null) {
        // Client-Server
        sender.lastResult(oneResult);
        if (this.rc != null) {
            this.rc.endResults();
        }
    } else {
        if (isLocal) {
            this.rc.addResult(dm.getDistributionManagerId(), oneResult);
            this.rc.endResults();
            FunctionStats.getFunctionStats(functionObject.getId(), this.dm.getSystem()).incResultsReceived();
        } else {
            try {
                this.msg.sendReplyForOneResult(dm, oneResult, true, enableOrderedResultStreming);
            } catch (ForceReattemptException e) {
                throw new FunctionException(e);
            } catch (InterruptedException e) {
                throw new FunctionException(e);
            }
        }
        // incrementing result sent stats.
        FunctionStats.getFunctionStats(functionObject.getId(), this.dm.getSystem()).incResultsReturned();
    }
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException)

Example 20 with FunctionException

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

the class DistributedRegionFunctionResultSender method sendResult.

public synchronized void sendResult(Object oneResult) {
    if (!this.functionObject.hasResult()) {
        throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
    }
    if (this.sender != null) {
        // Client-Server
        sender.sendResult(oneResult);
    } else {
        if (isLocal) {
            this.rc.addResult(dm.getDistributionManagerId(), oneResult);
            FunctionStats.getFunctionStats(functionObject.getId(), this.dm.getSystem()).incResultsReceived();
        } else {
            try {
                this.msg.sendReplyForOneResult(dm, oneResult, false, enableOrderedResultStreming);
            } catch (ForceReattemptException e) {
                throw new FunctionException(e);
            } catch (InterruptedException e) {
                throw new FunctionException(e);
            }
        }
        // incrementing result sent stats.
        FunctionStats.getFunctionStats(functionObject.getId(), this.dm.getSystem()).incResultsReturned();
    }
}
Also used : 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