Search in sources :

Example 51 with ReplyException

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

the class StreamingOperation method getDataFromAll.

/**
   * Returns normally if succeeded to get data, otherwise throws an exception
   * 
   * @throws InterruptedException TODO-javadocs
   */
public void getDataFromAll(Set recipients) throws org.apache.geode.cache.TimeoutException, InterruptedException {
    if (Thread.interrupted())
        throw new InterruptedException();
    if (recipients.isEmpty())
        return;
    StreamingProcessor processor = new StreamingProcessor(this.sys, recipients);
    DistributionMessage m = createRequestMessage(recipients, processor);
    this.sys.getDistributionManager().putOutgoing(m);
    // while() loop removed for bug 36983 - you can't loop on waitForReplies()
    try {
        // should we allow this to timeout?
        processor.waitForRepliesUninterruptibly();
    } catch (InternalGemFireException ex) {
        Throwable cause = ex.getCause();
        if (cause instanceof org.apache.geode.cache.TimeoutException) {
            throw (org.apache.geode.cache.TimeoutException) cause;
        }
        throw ex;
    } catch (ReplyException e) {
        e.handleAsUnexpected();
    // throws exception
    }
}
Also used : DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) PooledDistributionMessage(org.apache.geode.distributed.internal.PooledDistributionMessage) InternalGemFireException(org.apache.geode.InternalGemFireException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 52 with ReplyException

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

the class FunctionStreamingReplyMessage method toString.

@Override
public String toString() {
    StringBuffer buff = new StringBuffer();
    buff.append(getClass().getName());
    buff.append("(processorId=");
    buff.append(this.processorId);
    buff.append(" from ");
    buff.append(this.getSender());
    ReplyException ex = this.getException();
    if (ex != null) {
        buff.append(" with exception ");
        buff.append(ex);
    }
    buff.append(";msgNum ");
    buff.append(this.msgNum);
    buff.append(";lastMsg=");
    buff.append(this.lastMsg);
    buff.append(")");
    return buff.toString();
}
Also used : ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 53 with ReplyException

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

the class PartitionedRegion method sendInvalidateRegionMessage.

private void sendInvalidateRegionMessage(RegionEventImpl event) {
    final int retryAttempts = calcRetry();
    Throwable thr = null;
    int count = 0;
    while (count <= retryAttempts) {
        try {
            count++;
            Set recipients = getRegionAdvisor().adviseDataStore();
            ReplyProcessor21 response = InvalidatePartitionedRegionMessage.send(recipients, this, event);
            response.waitForReplies();
            thr = null;
            break;
        } catch (ReplyException e) {
            thr = e;
            if (!this.isClosed && !this.isDestroyed) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Invalidating partitioned region caught exception", e);
                }
            }
        } catch (InterruptedException e) {
            thr = e;
            if (!cache.getCancelCriterion().isCancelInProgress()) {
                if (logger.isDebugEnabled()) {
                    logger.debug("Invalidating partitioned region caught exception", e);
                }
            }
        }
    }
    if (thr != null) {
        PartitionedRegionDistributionException e = new PartitionedRegionDistributionException(LocalizedStrings.PartitionedRegion_INVALIDATING_REGION_CAUGHT_EXCEPTION.toLocalizedString(count));
        if (logger.isDebugEnabled()) {
            logger.debug(e.getMessage(), e);
        }
        throw e;
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) PartitionedRegionDistributionException(org.apache.geode.cache.PartitionedRegionDistributionException) ReplyException(org.apache.geode.distributed.internal.ReplyException) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21)

Example 54 with ReplyException

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

the class RemoteFetchVersionMessage method operateOnRegion.

@Override
protected boolean operateOnRegion(DistributionManager dm, LocalRegion r, long startTime) throws RemoteOperationException {
    if (!(r instanceof PartitionedRegion)) {
        r.waitOnInitialization();
    }
    VersionTag tag;
    try {
        RegionEntry re = r.getRegionEntry(key);
        if (re == null) {
            if (logger.isTraceEnabled(LogMarker.DM)) {
                logger.trace(LogMarker.DM, "RemoteFetchVersionMessage did not find entry for key:{}", key);
            }
            r.checkEntryNotFound(key);
        }
        tag = re.getVersionStamp().asVersionTag();
        if (logger.isTraceEnabled(LogMarker.DM)) {
            logger.debug("RemoteFetchVersionMessage for key:{} returning tag:{}", key, tag);
        }
        FetchVersionReplyMessage.send(getSender(), processorId, tag, dm);
    } catch (EntryNotFoundException e) {
        sendReply(getSender(), getProcessorId(), dm, new ReplyException(e), r, startTime);
    }
    return false;
}
Also used : VersionTag(org.apache.geode.internal.cache.versions.VersionTag) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) ReplyException(org.apache.geode.distributed.internal.ReplyException)

Example 55 with ReplyException

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

the class TXSynchronizationCommand method cmdExecute.

/*
   * (non-Javadoc)
   * 
   * @see
   * org.apache.geode.internal.cache.tier.sockets.BaseCommand#cmdExecute(org.apache.geode.internal.
   * cache.tier.sockets.Message, org.apache.geode.internal.cache.tier.sockets.ServerConnection,
   * long)
   */
@Override
public void cmdExecute(final Message clientMessage, final ServerConnection serverConnection, long start) throws IOException, ClassNotFoundException, InterruptedException {
    serverConnection.setAsTrue(REQUIRES_RESPONSE);
    CompletionType type = CompletionType.values()[clientMessage.getPart(0).getInt()];
    /* int txIdInt = */
    // [bruce] not sure if we need to
    clientMessage.getPart(1).getInt();
    // transmit this
    final Part statusPart;
    if (type == CompletionType.AFTER_COMPLETION) {
        statusPart = clientMessage.getPart(2);
    } else {
        statusPart = null;
    }
    final TXManagerImpl txMgr = (TXManagerImpl) serverConnection.getCache().getCacheTransactionManager();
    final InternalDistributedMember member = (InternalDistributedMember) serverConnection.getProxyID().getDistributedMember();
    // get the tx state without associating it with this thread. That's done later
    final TXStateProxy txProxy = txMgr.masqueradeAs(clientMessage, member, true);
    // releases them
    if (txProxy != null) {
        final boolean isDebugEnabled = logger.isDebugEnabled();
        try {
            if (type == CompletionType.BEFORE_COMPLETION) {
                Runnable beforeCompletion = new Runnable() {

                    @SuppressWarnings("synthetic-access")
                    public void run() {
                        TXStateProxy txState = null;
                        Throwable failureException = null;
                        try {
                            txState = txMgr.masqueradeAs(clientMessage, member, false);
                            if (isDebugEnabled) {
                                logger.debug("Executing beforeCompletion() notification for transaction {}", clientMessage.getTransactionId());
                            }
                            txState.setIsJTA(true);
                            txState.beforeCompletion();
                            try {
                                writeReply(clientMessage, serverConnection);
                            } catch (IOException e) {
                                if (isDebugEnabled) {
                                    logger.debug("Problem writing reply to client", e);
                                }
                            }
                            serverConnection.setAsTrue(RESPONDED);
                        } catch (ReplyException e) {
                            failureException = e.getCause();
                        } catch (InterruptedException e) {
                            Thread.currentThread().interrupt();
                        } catch (Exception e) {
                            failureException = e;
                        } finally {
                            txMgr.unmasquerade(txState);
                        }
                        if (failureException != null) {
                            try {
                                writeException(clientMessage, failureException, false, serverConnection);
                            } catch (IOException ioe) {
                                if (isDebugEnabled) {
                                    logger.debug("Problem writing reply to client", ioe);
                                }
                            }
                            serverConnection.setAsTrue(RESPONDED);
                        }
                    }
                };
                TXSynchronizationRunnable sync = new TXSynchronizationRunnable(beforeCompletion);
                txProxy.setSynchronizationRunnable(sync);
                Executor exec = InternalDistributedSystem.getConnectedInstance().getDistributionManager().getWaitingThreadPool();
                exec.execute(sync);
                sync.waitForFirstExecution();
            } else {
                Runnable afterCompletion = new Runnable() {

                    @SuppressWarnings("synthetic-access")
                    public void run() {
                        TXStateProxy txState = null;
                        try {
                            txState = txMgr.masqueradeAs(clientMessage, member, false);
                            int status = statusPart.getInt();
                            if (isDebugEnabled) {
                                logger.debug("Executing afterCompletion({}) notification for transaction {}", status, clientMessage.getTransactionId());
                            }
                            txState.setIsJTA(true);
                            txState.afterCompletion(status);
                            // GemFire commits during afterCompletion - send the commit info back to the client
                            // where it can be applied to the local cache
                            TXCommitMessage cmsg = txState.getCommitMessage();
                            try {
                                CommitCommand.writeCommitResponse(cmsg, clientMessage, serverConnection);
                                txMgr.removeHostedTXState(txState.getTxId());
                            } catch (IOException e) {
                                // not much can be done here
                                if (isDebugEnabled || (e instanceof MessageTooLargeException)) {
                                    logger.warn("Problem writing reply to client", e);
                                }
                            }
                            serverConnection.setAsTrue(RESPONDED);
                        } catch (RuntimeException e) {
                            try {
                                writeException(clientMessage, e, false, serverConnection);
                            } catch (IOException ioe) {
                                if (isDebugEnabled) {
                                    logger.debug("Problem writing reply to client", ioe);
                                }
                            }
                            serverConnection.setAsTrue(RESPONDED);
                        } catch (InterruptedException e) {
                            Thread.currentThread().interrupt();
                        } finally {
                            txMgr.unmasquerade(txState);
                        }
                    }
                };
                // if there was a beforeCompletion call then there will be a thread
                // sitting in the waiting pool to execute afterCompletion. Otherwise
                // we have failed-over and may need to do beforeCompletion & hope that it works
                TXSynchronizationRunnable sync = txProxy.getSynchronizationRunnable();
                if (sync != null) {
                    sync.runSecondRunnable(afterCompletion);
                } else {
                    if (statusPart.getInt() == Status.STATUS_COMMITTED) {
                        TXStateProxy txState = txMgr.masqueradeAs(clientMessage, member, false);
                        try {
                            if (isDebugEnabled) {
                                logger.debug("Executing beforeCompletion() notification for transaction {} after failover", clientMessage.getTransactionId());
                            }
                            txState.setIsJTA(true);
                            txState.beforeCompletion();
                        } finally {
                            txMgr.unmasquerade(txState);
                        }
                    }
                    afterCompletion.run();
                }
            }
        } catch (Exception e) {
            writeException(clientMessage, MessageType.EXCEPTION, e, false, serverConnection);
            serverConnection.setAsTrue(RESPONDED);
        }
        if (isDebugEnabled) {
            logger.debug("Sent tx synchronization response");
        }
    }
}
Also used : TXManagerImpl(org.apache.geode.internal.cache.TXManagerImpl) CompletionType(org.apache.geode.cache.client.internal.TXSynchronizationOp.CompletionType) IOException(java.io.IOException) ReplyException(org.apache.geode.distributed.internal.ReplyException) IOException(java.io.IOException) MessageTooLargeException(org.apache.geode.internal.cache.tier.sockets.MessageTooLargeException) ReplyException(org.apache.geode.distributed.internal.ReplyException) TXSynchronizationRunnable(org.apache.geode.internal.cache.TXSynchronizationRunnable) Executor(java.util.concurrent.Executor) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) TXStateProxy(org.apache.geode.internal.cache.TXStateProxy) Part(org.apache.geode.internal.cache.tier.sockets.Part) MessageTooLargeException(org.apache.geode.internal.cache.tier.sockets.MessageTooLargeException) TXSynchronizationRunnable(org.apache.geode.internal.cache.TXSynchronizationRunnable) TXCommitMessage(org.apache.geode.internal.cache.TXCommitMessage)

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