Search in sources :

Example 16 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class FunctionStreamingResultCollector method getResult.

public Object getResult(long timeout, TimeUnit unit) throws FunctionException, InterruptedException {
    long timeoutInMillis = unit.toMillis(timeout);
    if (this.resultCollected) {
        throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_ALREADY_COLLECTED.toLocalizedString());
    }
    this.resultCollected = true;
    // Should convert it from unit to milliseconds
    if (this.userRC != null) {
        try {
            long timeBefore = System.currentTimeMillis();
            boolean isNotTimedOut;
            if (execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) {
                isNotTimedOut = this.waitForCacheOrFunctionException(timeoutInMillis);
            } else {
                isNotTimedOut = this.waitForRepliesUninterruptibly(timeoutInMillis);
            }
            if (!isNotTimedOut) {
                throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_NOT_COLLECTED_IN_TIME_PROVIDED.toLocalizedString());
            }
            long timeAfter = System.currentTimeMillis();
            timeoutInMillis = timeoutInMillis - (timeAfter - timeBefore);
            if (timeoutInMillis < 0)
                timeoutInMillis = 0;
            if (this.removedNodes != null) {
                if (this.removedNodes.size() != 0) {
                    // end the rc and clear it
                    clearResults();
                    this.execution = this.execution.setIsReExecute();
                    ResultCollector newRc = null;
                    if (execution.isFnSerializationReqd()) {
                        newRc = this.execution.execute(fn);
                    } else {
                        newRc = this.execution.execute(fn.getId());
                    }
                    return newRc.getResult(timeoutInMillis, unit);
                }
            }
            if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
                throw new FunctionException(this.fites.get(0));
            }
        } catch (FunctionInvocationTargetException fite) {
            // function.
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(fite.getMessage());
                throw new FunctionException(iFITE);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult(timeoutInMillis, unit);
            }
        } catch (CacheClosedException e) {
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult(timeoutInMillis, unit);
            }
        }// }
         catch (ForceReattemptException e) {
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult(timeoutInMillis, unit);
            }
        } catch (ReplyException e) {
            if (!(execution.waitOnException || execution.forwardExceptions)) {
                throw new FunctionException(e.getCause());
            }
        }
        return this.userRC.getResult(timeoutInMillis, unit);
    }
    return null;
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 17 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class FunctionStreamingResultCollector method stillWaitingFromNodes.

protected boolean stillWaitingFromNodes() {
    if (shutdown) {
        // Create the exception here, so that the call stack reflects the
        // failed computation. If you set the exception in onShutdown,
        // the resulting stack is not of interest.
        ReplyException re = new ReplyException(new DistributedSystemDisconnectedException(LocalizedStrings.ReplyProcessor21_ABORTED_DUE_TO_SHUTDOWN.toLocalizedString()));
        this.exception = re;
        return false;
    }
    // return (numMembers()-this.numMemberDeparted) > 0;
    return numMembers() > 0;
}
Also used : DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 18 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class FunctionStreamingResultCollector method getResult.

public Object getResult() throws FunctionException {
    if (this.resultCollected) {
        throw new FunctionException(LocalizedStrings.ExecuteFunction_RESULTS_ALREADY_COLLECTED.toLocalizedString());
    }
    this.resultCollected = true;
    if (this.userRC != null) {
        try {
            if (execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) {
                this.waitForCacheOrFunctionException(0);
            } else {
                waitForRepliesUninterruptibly(0);
            }
            if (this.removedNodes != null) {
                if (this.removedNodes.size() != 0) {
                    // end the rc and clear it
                    clearResults();
                    this.execution = this.execution.setIsReExecute();
                    ResultCollector newRc = null;
                    if (execution.isFnSerializationReqd()) {
                        newRc = this.execution.execute(fn);
                    } else {
                        newRc = this.execution.execute(fn.getId());
                    }
                    return newRc.getResult();
                }
            }
            if (!this.execution.getWaitOnExceptionFlag() && this.fites.size() > 0) {
                throw new FunctionException(this.fites.get(0));
            }
        } catch (FunctionInvocationTargetException fite) {
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException iFITE = new InternalFunctionInvocationTargetException(fite.getMessage());
                throw new FunctionException(iFITE);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult();
            }
        } catch (CacheClosedException e) {
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult();
            }
        }// }
         catch (ForceReattemptException e) {
            if (!(execution instanceof DistributedRegionFunctionExecutor || execution instanceof MultiRegionFunctionExecutor) || !fn.isHA()) {
                FunctionInvocationTargetException fite = new FunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else if (execution.isClientServerMode()) {
                clearResults();
                FunctionInvocationTargetException fite = new InternalFunctionInvocationTargetException(e.getMessage());
                throw new FunctionException(fite);
            } else {
                clearResults();
                this.execution = this.execution.setIsReExecute();
                ResultCollector newRc = null;
                if (execution.isFnSerializationReqd()) {
                    newRc = this.execution.execute(fn);
                } else {
                    newRc = this.execution.execute(fn.getId());
                }
                return newRc.getResult();
            }
        } catch (ReplyException e) {
            if (!(execution.waitOnException || execution.forwardExceptions)) {
                throw new FunctionException(e.getCause());
            }
        }
        return this.userRC.getResult();
    }
    return null;
}
Also used : ForceReattemptException(org.apache.geode.internal.cache.ForceReattemptException) FunctionException(org.apache.geode.cache.execute.FunctionException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) CacheClosedException(org.apache.geode.cache.CacheClosedException) ResultCollector(org.apache.geode.cache.execute.ResultCollector) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 19 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class CheckTypeRegistryState method send.

public static void send(DM dm) {
    Set recipients = dm.getOtherDistributionManagerIds();
    ReplyProcessor21 replyProcessor = new ReplyProcessor21(dm, recipients);
    CheckTypeRegistryState msg = new CheckTypeRegistryState(replyProcessor.getProcessorId());
    msg.setRecipients(recipients);
    dm.putOutgoing(msg);
    try {
        replyProcessor.waitForReplies();
    } catch (ReplyException e) {
        if (e.getCause() instanceof PdxInitializationException) {
            throw new PdxInitializationException("Bad PDX configuration on member " + e.getSender() + ": " + e.getCause().getMessage(), e.getCause());
        } else {
            throw new InternalGemFireError("Unexpected exception", e);
        }
    } catch (InterruptedException e) {
        throw new InternalGemFireError("Unexpected exception", e);
    }
}
Also used : Set(java.util.Set) ReplyException(org.apache.geode.distributed.internal.ReplyException) PdxInitializationException(org.apache.geode.pdx.PdxInitializationException) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21) InternalGemFireError(org.apache.geode.InternalGemFireError)

Example 20 with ReplyException

use of org.apache.geode.distributed.internal.ReplyException in project geode by apache.

the class CheckTypeRegistryState method process.

@Override
protected void process(DistributionManager dm) {
    ReplyException e = null;
    try {
        InternalCache cache = GemFireCacheImpl.getInstance();
        if (cache != null && !cache.isClosed()) {
            TypeRegistry pdxRegistry = cache.getPdxRegistry();
            if (pdxRegistry != null) {
                TypeRegistration registry = pdxRegistry.getTypeRegistration();
                if (registry instanceof PeerTypeRegistration) {
                    PeerTypeRegistration peerRegistry = (PeerTypeRegistration) registry;
                    peerRegistry.verifyConfiguration();
                }
            }
        }
    } catch (Exception ex) {
        e = new ReplyException(ex);
    } finally {
        ReplyMessage rm = new ReplyMessage();
        rm.setException(e);
        rm.setProcessorId(processorId);
        rm.setRecipient(getSender());
        dm.putOutgoing(rm);
    }
}
Also used : InternalCache(org.apache.geode.internal.cache.InternalCache) ReplyException(org.apache.geode.distributed.internal.ReplyException) PdxInitializationException(org.apache.geode.pdx.PdxInitializationException) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ReplyMessage(org.apache.geode.distributed.internal.ReplyMessage)

Aggregations

ReplyException (org.apache.geode.distributed.internal.ReplyException)75 CancelException (org.apache.geode.CancelException)24 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)20 Set (java.util.Set)16 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)16 HashSet (java.util.HashSet)12 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)10 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)8 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)8 IOException (java.io.IOException)7 CacheClosedException (org.apache.geode.cache.CacheClosedException)7 ReplyMessage (org.apache.geode.distributed.internal.ReplyMessage)7 Cache (org.apache.geode.cache.Cache)6 CacheException (org.apache.geode.cache.CacheException)6 Region (org.apache.geode.cache.Region)6 PartitionedRegionDataStore (org.apache.geode.internal.cache.PartitionedRegionDataStore)6 PrimaryBucketException (org.apache.geode.internal.cache.PrimaryBucketException)6 Released (org.apache.geode.internal.offheap.annotations.Released)6 DistributedSystemDisconnectedException (org.apache.geode.distributed.DistributedSystemDisconnectedException)5 ReplyProcessor21 (org.apache.geode.distributed.internal.ReplyProcessor21)5