Search in sources :

Example 91 with FunctionException

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

the class ServerToClientFunctionResultSender65 method lastResult.

@Override
public synchronized void lastResult(Object oneResult, DistributedMember memberID) {
    this.lastResultReceived = true;
    if (!isOkayToSendResult()) {
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 not sending lastResult {} as the server has shutdown", oneResult);
        }
        return;
    }
    try {
        if (logger.isDebugEnabled()) {
            logger.debug("ServerToClientFunctionResultSender sending last result2 {} " + oneResult);
        }
        authorizeResult(oneResult);
        if (!this.fn.hasResult()) {
            throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
        }
        if (!headerSent) {
            sendHeader();
        }
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 sending lastResult {}", oneResult);
        }
        List<Object> result = new ArrayList<Object>();
        result.add(oneResult);
        result.add(memberID);
        this.setBuffer();
        this.msg.setServerConnection(this.sc);
        if (oneResult instanceof InternalFunctionException) {
            this.msg.setNumberOfParts(2);
            this.msg.setLastChunkAndNumParts(true, 2);
        } else {
            this.msg.setNumberOfParts(1);
            this.msg.setLastChunkAndNumParts(true, 1);
        }
        this.msg.addObjPart(result);
        if (oneResult instanceof InternalFunctionException) {
            List<Object> result2 = new ArrayList<Object>();
            result2.add(BaseCommand.getExceptionTrace((Throwable) oneResult));
            result2.add(memberID);
            this.msg.addObjPart(result2);
        }
        this.msg.sendChunk(this.sc);
        this.sc.setAsTrue(Command.RESPONDED);
        FunctionStats.getFunctionStats(fn.getId()).incResultsReturned();
    } catch (IOException ex) {
        if (isOkayToSendResult()) {
            throw new FunctionException(LocalizedStrings.ExecuteFunction_IOEXCEPTION_WHILE_SENDING_LAST_CHUNK.toLocalizedString(), ex);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException)

Example 92 with FunctionException

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

the class ServerToClientFunctionResultSender65 method sendResult.

@Override
public synchronized void sendResult(Object oneResult, DistributedMember memberID) {
    if (!isOkayToSendResult()) {
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 not sending result {}  as the server has shutdown", oneResult);
        }
        return;
    }
    try {
        authorizeResult(oneResult);
        if (!this.fn.hasResult()) {
            throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
        }
        if (!headerSent) {
            sendHeader();
        }
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 sending result {}", oneResult);
        }
        List<Object> result = new ArrayList<Object>();
        result.add(oneResult);
        result.add(memberID);
        this.setBuffer();
        this.msg.setNumberOfParts(1);
        this.msg.addObjPart(result);
        this.msg.sendChunk(this.sc);
        FunctionStats.getFunctionStats(fn.getId()).incResultsReturned();
    } catch (IOException ex) {
        if (isOkayToSendResult()) {
            throw new FunctionException(LocalizedStrings.ExecuteFunction_IOEXCEPTION_WHILE_SENDING_RESULT_CHUNK.toLocalizedString(), ex);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException)

Example 93 with FunctionException

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

the class ServerToClientFunctionResultSender65 method sendResult.

@Override
public synchronized void sendResult(Object oneResult) {
    if (!isOkayToSendResult()) {
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 not sending result {}  as the server has shutdown", oneResult);
        }
        return;
    }
    try {
        authorizeResult(oneResult);
        if (!this.fn.hasResult()) {
            throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
        }
        if (!headerSent) {
            sendHeader();
        }
        if (logger.isDebugEnabled()) {
            logger.debug(" ServerToClientFunctionResultSender65 sending result {}", oneResult);
        }
        DistributedMember memberID = InternalDistributedSystem.getAnyInstance().getDistributionManager().getId();
        List<Object> result = new ArrayList<Object>();
        result.add(oneResult);
        result.add(memberID);
        this.setBuffer();
        this.msg.setNumberOfParts(1);
        this.msg.addObjPart(result);
        this.msg.sendChunk(this.sc);
        FunctionStats.getFunctionStats(fn.getId()).incResultsReturned();
    } catch (IOException ex) {
        if (isOkayToSendResult()) {
            throw new FunctionException(LocalizedStrings.ExecuteFunction_IOEXCEPTION_WHILE_SENDING_RESULT_CHUNK.toLocalizedString(), ex);
        }
    }
}
Also used : DistributedMember(org.apache.geode.distributed.DistributedMember) ArrayList(java.util.ArrayList) FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException)

Example 94 with FunctionException

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

the class ServerRegionFunctionExecutor method executeOnServer.

private ResultCollector executeOnServer(String functionId, ResultCollector collector, byte hasResult, boolean isHA, boolean optimizeForWrite) throws FunctionException {
    ServerRegionProxy srp = getServerRegionProxy();
    FunctionStats stats = FunctionStats.getFunctionStats(functionId, this.region.getSystem());
    try {
        validateExecution(null, null);
        long start = stats.startTime();
        stats.startFunctionExecution(true);
        srp.executeFunction(this.region.getFullPath(), functionId, this, collector, hasResult, isHA, optimizeForWrite, false);
        stats.endFunctionExecution(start, true);
        return collector;
    } catch (FunctionException functionException) {
        stats.endFunctionExecutionWithException(true);
        throw functionException;
    } catch (Exception exception) {
        stats.endFunctionExecutionWithException(true);
        throw new FunctionException(exception);
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionException(org.apache.geode.cache.execute.FunctionException) CacheClosedException(org.apache.geode.cache.CacheClosedException)

Example 95 with FunctionException

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

the class ServerToClientFunctionResultSender method lastResult.

public synchronized void lastResult(Object oneResult) {
    this.lastResultReceived = true;
    if (!isOkayToSendResult()) {
        if (logger.isDebugEnabled()) {
            logger.debug("ServerToClientFunctionResultSender not sending lastResult {} as the server has shutdown", oneResult);
        }
        return;
    }
    if (this.lastResultReceived) {
        return;
    }
    if (logger.isDebugEnabled()) {
        logger.debug("ServerToClientFunctionResultSender sending last result1 {} " + oneResult);
    }
    try {
        authorizeResult(oneResult);
        if (!this.fn.hasResult()) {
            throw new IllegalStateException(LocalizedStrings.ExecuteFunction_CANNOT_0_RESULTS_HASRESULT_FALSE.toLocalizedString("send"));
        }
        if (!headerSent) {
            sendHeader();
        }
        if (logger.isDebugEnabled()) {
            logger.debug("ServerToClientFunctionResultSender sending lastResult {}", oneResult);
        }
        this.setBuffer();
        this.msg.setNumberOfParts(1);
        this.msg.addObjPart(oneResult);
        this.msg.setLastChunk(true);
        this.msg.sendChunk(this.sc);
        this.sc.setAsTrue(Command.RESPONDED);
        FunctionStats.getFunctionStats(fn.getId()).incResultsReturned();
    } catch (IOException ex) {
        if (isOkayToSendResult()) {
            throw new FunctionException(LocalizedStrings.ExecuteFunction_IOEXCEPTION_WHILE_SENDING_LAST_CHUNK.toLocalizedString(), ex);
        }
    }
}
Also used : FunctionException(org.apache.geode.cache.execute.FunctionException) IOException(java.io.IOException)

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