Search in sources :

Example 6 with GatewaySenderException

use of org.apache.geode.internal.cache.wan.GatewaySenderException in project geode by apache.

the class WANConfigurationJUnitTest method test_GatewaySenderWithGatewaySenderEventListener1.

@Test
public void test_GatewaySenderWithGatewaySenderEventListener1() {
    cache = new CacheFactory().set(MCAST_PORT, "0").create();
    InternalGatewaySenderFactory fact = (InternalGatewaySenderFactory) cache.createGatewaySenderFactory();
    AsyncEventListener listener = new MyGatewaySenderEventListener();
    ((InternalGatewaySenderFactory) fact).addAsyncEventListener(listener);
    try {
        fact.create("ln", 2);
        fail("Expected GatewaySenderException. When a sender is added , remoteDSId should not be provided.");
    } catch (Exception e) {
        if (e instanceof GatewaySenderException && e.getMessage().contains("cannot define a remote site because at least AsyncEventListener is already added.")) {
        } else {
            fail("Expected GatewaySenderException but received :" + e);
        }
    }
}
Also used : MyGatewaySenderEventListener(org.apache.geode.internal.cache.wan.MyGatewaySenderEventListener) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) InternalGatewaySenderFactory(org.apache.geode.internal.cache.wan.InternalGatewaySenderFactory) IOException(java.io.IOException) GatewayReceiverException(org.apache.geode.internal.cache.wan.GatewayReceiverException) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 7 with GatewaySenderException

use of org.apache.geode.internal.cache.wan.GatewaySenderException in project geode by apache.

the class RemoteParallelGatewaySenderEventProcessor method shouldSendVersionEvents.

/**
   * Returns if corresponding receiver WAN site of this GatewaySender has GemfireVersion > 7.0.1
   * 
   * @param disp
   * @return true if remote site Gemfire Version is >= 7.0.1
   */
private boolean shouldSendVersionEvents(GatewaySenderEventDispatcher disp) throws GatewaySenderException {
    try {
        GatewaySenderEventRemoteDispatcher remoteDispatcher = (GatewaySenderEventRemoteDispatcher) disp;
        // This will create a new connection if no batch has been sent till
        // now.
        Connection conn = remoteDispatcher.getConnection(false);
        if (conn != null) {
            short remoteSiteVersion = conn.getWanSiteVersion();
            if (Version.GFE_701.compareTo(remoteSiteVersion) <= 0) {
                return true;
            }
        }
    } catch (GatewaySenderException e) {
        Throwable cause = e.getCause();
        if (cause instanceof IOException || e instanceof GatewaySenderConfigurationException || cause instanceof ConnectionDestroyedException) {
            try {
                int sleepInterval = GatewaySender.CONNECTION_RETRY_INTERVAL;
                if (logger.isDebugEnabled()) {
                    logger.debug("Sleeping for {} milliseconds", sleepInterval);
                }
                Thread.sleep(sleepInterval);
            } catch (InterruptedException ie) {
                // log the exception
                if (logger.isDebugEnabled()) {
                    logger.debug(ie.getMessage(), ie);
                }
            }
        }
        throw e;
    }
    return false;
}
Also used : GatewaySenderEventRemoteDispatcher(org.apache.geode.internal.cache.wan.GatewaySenderEventRemoteDispatcher) GatewaySenderConfigurationException(org.apache.geode.internal.cache.wan.GatewaySenderConfigurationException) Connection(org.apache.geode.cache.client.internal.Connection) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) IOException(java.io.IOException) ConnectionDestroyedException(org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException)

Example 8 with GatewaySenderException

use of org.apache.geode.internal.cache.wan.GatewaySenderException in project geode by apache.

the class PartitionedRegion method destroyParallelGatewaySenderRegion.

public void destroyParallelGatewaySenderRegion(Operation op, boolean cacheWrite, boolean lock, boolean callbackEvents) {
    if (logger.isDebugEnabled()) {
        logger.debug("Destoying parallel queue region for senders: {}", this.getParallelGatewaySenderIds());
    }
    boolean keepWaiting = true;
    while (true) {
        List<String> pausedSenders = new ArrayList<String>();
        List<ConcurrentParallelGatewaySenderQueue> parallelQueues = new ArrayList<ConcurrentParallelGatewaySenderQueue>();
        isDestroyedForParallelWAN = true;
        int countOfQueueRegionsToBeDestroyed = 0;
        for (String senderId : this.getParallelGatewaySenderIds()) {
            AbstractGatewaySender sender = (AbstractGatewaySender) this.cache.getGatewaySender(senderId);
            if (sender == null || sender.getEventProcessor() == null) {
                continue;
            }
            if (cacheWrite) {
                // resumed
                if (sender.isPaused()) {
                    pausedSenders.add(senderId);
                    continue;
                }
            }
            if (pausedSenders.isEmpty()) {
                // if there are puase sender then only
                // check for other pause senders instead
                // of creating list of shadowPR
                AbstractGatewaySenderEventProcessor ep = sender.getEventProcessor();
                if (ep == null)
                    continue;
                ConcurrentParallelGatewaySenderQueue parallelQueue = (ConcurrentParallelGatewaySenderQueue) ep.getQueue();
                PartitionedRegion parallelQueueRegion = parallelQueue.getRegion(this.getFullPath());
                // this may be removed in previous iteration
                if (parallelQueueRegion == null || parallelQueueRegion.isDestroyed || parallelQueueRegion.isClosed) {
                    continue;
                }
                parallelQueues.add(parallelQueue);
                countOfQueueRegionsToBeDestroyed++;
            }
        }
        if (!pausedSenders.isEmpty()) {
            String exception = null;
            if (pausedSenders.size() == 1) {
                exception = LocalizedStrings.PartitionedRegion_GATEWAYSENDER_0_IS_PAUSED_RESUME_IT_BEFORE_DESTROYING_USER_REGION_1.toLocalizedString(pausedSenders, this.getName());
            } else {
                exception = LocalizedStrings.PartitionedRegion_GATEWAYSENDERS_0_ARE_PAUSED_RESUME_THEM_BEFORE_DESTROYING_USER_REGION_1.toLocalizedString(pausedSenders, this.getName());
            }
            isDestroyedForParallelWAN = false;
            throw new GatewaySenderException(exception);
        }
        if (countOfQueueRegionsToBeDestroyed == 0) {
            break;
        }
        for (ConcurrentParallelGatewaySenderQueue parallelQueue : parallelQueues) {
            PartitionedRegion parallelQueueRegion = parallelQueue.getRegion(this.getFullPath());
            // keepWaiting : comes from the MAXIMUM_SHUTDOWN_WAIT_TIME case handled
            if (cacheWrite && parallelQueueRegion.size() != 0 && keepWaiting) {
                continue;
            } else {
                // In any case, destroy shadow PR locally. distributed destroy of
                // userPR will take care of detsroying shadowPR locally on other
                // nodes.
                RegionEventImpl event = null;
                if (op.isClose()) {
                    // In case of cache close operation, we want SPR's basic destroy to go
                    // through CACHE_CLOSE condition of postDestroyRegion not
                    // closePartitionedRegion code
                    event = new RegionEventImpl(parallelQueueRegion, op, null, false, getMyId(), generateEventID());
                } else {
                    event = new RegionEventImpl(parallelQueueRegion, Operation.REGION_LOCAL_DESTROY, null, false, getMyId(), generateEventID());
                }
                parallelQueueRegion.basicDestroyRegion(event, false, lock, callbackEvents);
                parallelQueue.removeShadowPR(this.getFullPath());
                countOfQueueRegionsToBeDestroyed--;
                continue;
            }
        }
        if (countOfQueueRegionsToBeDestroyed == 0) {
            break;
        }
        if (cacheWrite) {
            if (AbstractGatewaySender.MAXIMUM_SHUTDOWN_WAIT_TIME == -1) {
                keepWaiting = true;
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException ignore) {
                // interrupted
                }
            } else {
                try {
                    Thread.sleep(AbstractGatewaySender.MAXIMUM_SHUTDOWN_WAIT_TIME * 1000);
                } catch (InterruptedException ignore) {
                /* ignore */
                // interrupted
                }
                keepWaiting = false;
            }
        }
    }
}
Also used : CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) GatewaySenderException(org.apache.geode.internal.cache.wan.GatewaySenderException) AbstractGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.AbstractGatewaySenderEventProcessor) ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Aggregations

GatewaySenderException (org.apache.geode.internal.cache.wan.GatewaySenderException)8 IOException (java.io.IOException)3 InternalGatewaySenderFactory (org.apache.geode.internal.cache.wan.InternalGatewaySenderFactory)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 Test (org.junit.Test)3 Cache (org.apache.geode.cache.Cache)2 GatewaySender (org.apache.geode.cache.wan.GatewaySender)2 AbstractGatewaySender (org.apache.geode.internal.cache.wan.AbstractGatewaySender)2 ArrayList (java.util.ArrayList)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 AttributesFactory (org.apache.geode.cache.AttributesFactory)1 EvictionAttributes (org.apache.geode.cache.EvictionAttributes)1 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 AsyncEventListener (org.apache.geode.cache.asyncqueue.AsyncEventListener)1 Connection (org.apache.geode.cache.client.internal.Connection)1 ConnectionDestroyedException (org.apache.geode.cache.client.internal.pooling.ConnectionDestroyedException)1 InternalCache (org.apache.geode.internal.cache.InternalCache)1 InternalRegionArguments (org.apache.geode.internal.cache.InternalRegionArguments)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1