Search in sources :

Example 1 with GatewayCancelledException

use of org.apache.geode.distributed.GatewayCancelledException in project geode by apache.

the class AbstractGatewaySender method distribute.

public void distribute(EnumListenerEvent operation, EntryEventImpl event, List<Integer> allRemoteDSIds) {
    final boolean isDebugEnabled = logger.isDebugEnabled();
    // If this gateway is not running, return
    if (!isRunning()) {
        if (isDebugEnabled) {
            logger.debug("Returning back without putting into the gateway sender queue");
        }
        return;
    }
    final GatewaySenderStats stats = getStatistics();
    stats.incEventsReceived();
    if (!checkForDistribution(event, stats)) {
        stats.incEventsNotQueued();
        return;
    }
    // not considering this filter
    if (!this.filter.enqueueEvent(event)) {
        stats.incEventsFiltered();
        return;
    }
    // released by this method or transfers ownership to TmpQueueEvent
    @Released EntryEventImpl clonedEvent = new EntryEventImpl(event, false);
    boolean freeClonedEvent = true;
    try {
        Region region = event.getRegion();
        setModifiedEventId(clonedEvent);
        Object callbackArg = clonedEvent.getRawCallbackArgument();
        if (isDebugEnabled) {
            // We can't deserialize here for logging purposes so don't
            // call getNewValue.
            // event.getNewValue(); // to deserialize the value if necessary
            logger.debug("{} : About to notify {} to perform operation {} for {} callback arg {}", this.isPrimary(), getId(), operation, clonedEvent, callbackArg);
        }
        if (callbackArg instanceof GatewaySenderEventCallbackArgument) {
            GatewaySenderEventCallbackArgument seca = (GatewaySenderEventCallbackArgument) callbackArg;
            if (isDebugEnabled) {
                logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}. The recipients are: {}", this, seca.getOriginatingDSId(), this.getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
            }
            if (seca.getOriginatingDSId() == DEFAULT_DISTRIBUTED_SYSTEM_ID) {
                if (isDebugEnabled) {
                    logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}. The recipients are: {}", this, seca.getOriginatingDSId(), this.getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
                }
                seca.setOriginatingDSId(this.getMyDSId());
                seca.initializeReceipientDSIds(allRemoteDSIds);
            } else {
                // if the dispatcher is GatewaySenderEventCallbackDispatcher (which is the case of WBCL),
                // skip the below check of remoteDSId.
                // Fix for #46517
                AbstractGatewaySenderEventProcessor ep = getEventProcessor();
                if (ep != null && !(ep.getDispatcher() instanceof GatewaySenderEventCallbackDispatcher)) {
                    if (seca.getOriginatingDSId() == this.getRemoteDSId()) {
                        if (isDebugEnabled) {
                            logger.debug("{}: Event originated in {}. My DS id is {}. It is being dropped as remote is originator.", this, seca.getOriginatingDSId(), getMyDSId());
                        }
                        return;
                    } else if (seca.getRecipientDSIds().contains(this.getRemoteDSId())) {
                        if (isDebugEnabled) {
                            logger.debug("{}: Event originated in {}. My DS id is {}. The remote DS id is {}.. It is being dropped as remote ds is already a recipient. Recipients are: {}", this, seca.getOriginatingDSId(), getMyDSId(), this.getRemoteDSId(), seca.getRecipientDSIds());
                        }
                        return;
                    }
                }
                seca.getRecipientDSIds().addAll(allRemoteDSIds);
            }
        } else {
            GatewaySenderEventCallbackArgument geCallbackArg = new GatewaySenderEventCallbackArgument(callbackArg, this.getMyDSId(), allRemoteDSIds);
            clonedEvent.setCallbackArgument(geCallbackArg);
        }
        if (!this.getLifeCycleLock().readLock().tryLock()) {
            synchronized (this.queuedEventsSync) {
                if (!this.enqueuedAllTempQueueEvents) {
                    if (!this.getLifeCycleLock().readLock().tryLock()) {
                        Object substituteValue = getSubstituteValue(clonedEvent, operation);
                        this.tmpQueuedEvents.add(new TmpQueueEvent(operation, clonedEvent, substituteValue));
                        freeClonedEvent = false;
                        stats.incTempQueueSize();
                        if (isDebugEnabled) {
                            logger.debug("Event : {} is added to TempQueue", clonedEvent);
                        }
                        return;
                    }
                }
            }
            if (this.enqueuedAllTempQueueEvents) {
                this.getLifeCycleLock().readLock().lock();
            }
        }
        try {
            // The sender may have stopped, after we have checked the status in the beginning.
            if (!isRunning()) {
                if (isDebugEnabled) {
                    logger.debug("Returning back without putting into the gateway sender queue");
                }
                return;
            }
            try {
                AbstractGatewaySenderEventProcessor ev = this.eventProcessor;
                if (ev == null) {
                    getStopper().checkCancelInProgress(null);
                    this.getCache().getDistributedSystem().getCancelCriterion().checkCancelInProgress(null);
                    // connecting to the other site (bug #40681)
                    if (ev == null) {
                        throw new GatewayCancelledException("Event processor thread is gone");
                    }
                }
                // Get substitution value to enqueue if necessary
                Object substituteValue = getSubstituteValue(clonedEvent, operation);
                ev.enqueueEvent(operation, clonedEvent, substituteValue);
            } catch (CancelException e) {
                logger.debug("caught cancel exception", e);
                throw e;
            } catch (RegionDestroyedException e) {
                logger.warn(LocalizedMessage.create(LocalizedStrings.GatewayImpl_0_AN_EXCEPTION_OCCURRED_WHILE_QUEUEING_1_TO_PERFORM_OPERATION_2_FOR_3, new Object[] { this, getId(), operation, clonedEvent }), e);
            } catch (Exception e) {
                logger.fatal(LocalizedMessage.create(LocalizedStrings.GatewayImpl_0_AN_EXCEPTION_OCCURRED_WHILE_QUEUEING_1_TO_PERFORM_OPERATION_2_FOR_3, new Object[] { this, getId(), operation, clonedEvent }), e);
            }
        } finally {
            this.getLifeCycleLock().readLock().unlock();
        }
    } finally {
        if (freeClonedEvent) {
            // fix for bug 48035
            clonedEvent.release();
        }
    }
}
Also used : Released(org.apache.geode.internal.offheap.annotations.Released) EntryEventImpl(org.apache.geode.internal.cache.EntryEventImpl) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) GatewayCancelledException(org.apache.geode.distributed.GatewayCancelledException) RegionExistsException(org.apache.geode.cache.RegionExistsException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) CancelException(org.apache.geode.CancelException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) GatewayCancelledException(org.apache.geode.distributed.GatewayCancelledException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) CancelException(org.apache.geode.CancelException)

Aggregations

IOException (java.io.IOException)1 CancelException (org.apache.geode.CancelException)1 CacheException (org.apache.geode.cache.CacheException)1 Region (org.apache.geode.cache.Region)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 RegionExistsException (org.apache.geode.cache.RegionExistsException)1 GatewayCancelledException (org.apache.geode.distributed.GatewayCancelledException)1 EntryEventImpl (org.apache.geode.internal.cache.EntryEventImpl)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1 BucketMovedException (org.apache.geode.internal.cache.execute.BucketMovedException)1 Released (org.apache.geode.internal.offheap.annotations.Released)1