Search in sources :

Example 1 with RegionQueue

use of org.apache.geode.internal.cache.RegionQueue in project geode by apache.

the class SerialGatewaySenderImpl method stop.

@Override
public void stop() {
    if (logger.isDebugEnabled()) {
        logger.debug("Stopping Gateway Sender : {}", this);
    }
    this.getLifeCycleLock().writeLock().lock();
    try {
        // Stop the dispatcher
        AbstractGatewaySenderEventProcessor ev = this.eventProcessor;
        if (ev != null && !ev.isStopped()) {
            ev.stopProcessing();
        }
        // Stop the proxy (after the dispatcher, so the socket is still
        // alive until after the dispatcher has stopped)
        stompProxyDead();
        // Close the listeners
        for (AsyncEventListener listener : this.listeners) {
            listener.close();
        }
        logger.info(LocalizedMessage.create(LocalizedStrings.GatewayImpl_STOPPED__0, this));
        clearTempEventsAfterSenderStopped();
    } finally {
        this.getLifeCycleLock().writeLock().unlock();
    }
    if (this.isPrimary()) {
        try {
            DistributedLockService.destroy(getSenderAdvisor().getDLockServiceName());
        } catch (IllegalArgumentException e) {
        // service not found... ignore
        }
    }
    Set<RegionQueue> queues = getQueues();
    if (queues != null && !queues.isEmpty()) {
        for (RegionQueue q : queues) {
            ((SerialGatewaySenderQueue) q).cleanUp();
        }
    }
    this.setIsPrimary(false);
    new UpdateAttributesProcessor(this).distribute(false);
    Thread lockObtainingThread = getSenderAdvisor().getLockObtainingThread();
    if (lockObtainingThread != null && lockObtainingThread.isAlive()) {
        // wait a while for thread to terminate
        try {
            lockObtainingThread.join(3000);
        } catch (InterruptedException ex) {
            // we allowed our join to be canceled
            // reset interrupt bit so this thread knows it has been interrupted
            Thread.currentThread().interrupt();
        }
        if (lockObtainingThread.isAlive()) {
            logger.info(LocalizedMessage.create(LocalizedStrings.GatewaySender_COULD_NOT_STOP_LOCK_OBTAINING_THREAD_DURING_GATEWAY_SENDER_STOP));
        }
    }
    InternalDistributedSystem system = (InternalDistributedSystem) this.cache.getDistributedSystem();
    system.handleResourceEvent(ResourceEvent.GATEWAYSENDER_STOP, this);
    this.eventProcessor = null;
}
Also used : UpdateAttributesProcessor(org.apache.geode.internal.cache.UpdateAttributesProcessor) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) AbstractGatewaySenderEventProcessor(org.apache.geode.internal.cache.wan.AbstractGatewaySenderEventProcessor) RegionQueue(org.apache.geode.internal.cache.RegionQueue) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 2 with RegionQueue

use of org.apache.geode.internal.cache.RegionQueue in project geode by apache.

the class WANTestBase method validateQueueClosedForConcurrentSerialGatewaySender.

// Ensure that the sender's queue(s) have been closed.
public static void validateQueueClosedForConcurrentSerialGatewaySender(final String senderId) {
    Set<GatewaySender> senders = cache.getGatewaySenders();
    GatewaySender sender = null;
    for (GatewaySender s : senders) {
        if (s.getId().equals(senderId)) {
            sender = s;
            break;
        }
    }
    final Set<RegionQueue> regionQueue;
    if (sender instanceof AbstractGatewaySender) {
        regionQueue = ((AbstractGatewaySender) sender).getQueuesForConcurrentSerialGatewaySender();
    } else {
        regionQueue = null;
    }
    assertEquals(null, regionQueue);
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) RegionQueue(org.apache.geode.internal.cache.RegionQueue)

Example 3 with RegionQueue

use of org.apache.geode.internal.cache.RegionQueue in project geode by apache.

the class WANTestBase method validateQueueContents.

public static void validateQueueContents(final String senderId, final int regionSize) {
    IgnoredException exp1 = IgnoredException.addIgnoredException(InterruptedException.class.getName());
    IgnoredException exp2 = IgnoredException.addIgnoredException(GatewaySenderException.class.getName());
    try {
        Set<GatewaySender> senders = cache.getGatewaySenders();
        GatewaySender sender = null;
        for (GatewaySender s : senders) {
            if (s.getId().equals(senderId)) {
                sender = s;
                break;
            }
        }
        if (!sender.isParallel()) {
            final Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
            Awaitility.await().atMost(120, TimeUnit.SECONDS).until(() -> {
                int size = 0;
                for (RegionQueue q : queues) {
                    size += q.size();
                }
                assertEquals("Expected queue entries: " + regionSize + " but actual entries: " + size, regionSize, size);
            });
        } else if (sender.isParallel()) {
            final RegionQueue regionQueue;
            regionQueue = ((AbstractGatewaySender) sender).getQueues().toArray(new RegionQueue[1])[0];
            Awaitility.await().atMost(120, TimeUnit.SECONDS).until(() -> assertEquals("Expected queue entries: " + regionSize + " but actual entries: " + regionQueue.size(), regionSize, regionQueue.size()));
        }
    } finally {
        exp1.remove();
        exp2.remove();
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) IgnoredException(org.apache.geode.test.dunit.IgnoredException) RegionQueue(org.apache.geode.internal.cache.RegionQueue)

Example 4 with RegionQueue

use of org.apache.geode.internal.cache.RegionQueue in project geode by apache.

the class WANTestBase method getPRQLocalSize.

/**
   * To be used only for ParallelGatewaySender.
   * 
   * @param senderId Id of the ParallelGatewaySender
   */
public static int getPRQLocalSize(String senderId) {
    GatewaySender sender = null;
    for (GatewaySender s : cache.getGatewaySenders()) {
        if (s.getId().equals(senderId)) {
            sender = s;
            break;
        }
    }
    if (sender.isParallel()) {
        int totalSize = 0;
        Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
        for (RegionQueue q : queues) {
            ConcurrentParallelGatewaySenderQueue prQ = (ConcurrentParallelGatewaySenderQueue) q;
            totalSize += prQ.localSize();
        }
        return totalSize;
    }
    return -1;
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) RegionQueue(org.apache.geode.internal.cache.RegionQueue)

Example 5 with RegionQueue

use of org.apache.geode.internal.cache.RegionQueue in project geode by apache.

the class WANTestBase method checkPRQLocalSize.

/**
   * To be used only for ParallelGatewaySender.
   * 
   * @param senderId Id of the ParallelGatewaySender
   * @param numQueueEntries Expected number of ParallelGatewaySenderQueue entries
   */
public static void checkPRQLocalSize(String senderId, final int numQueueEntries) {
    GatewaySender sender = null;
    for (GatewaySender s : cache.getGatewaySenders()) {
        if (s.getId().equals(senderId)) {
            sender = s;
            break;
        }
    }
    if (sender.isParallel()) {
        final Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
        Awaitility.await().atMost(120, TimeUnit.SECONDS).until(() -> {
            int size = 0;
            for (RegionQueue q : queues) {
                ConcurrentParallelGatewaySenderQueue prQ = (ConcurrentParallelGatewaySenderQueue) q;
                size += prQ.localSize();
            }
            assertEquals(" Expected local queue entries: " + numQueueEntries + " but actual entries: " + size, numQueueEntries, size);
        });
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) RegionQueue(org.apache.geode.internal.cache.RegionQueue)

Aggregations

RegionQueue (org.apache.geode.internal.cache.RegionQueue)39 GatewaySender (org.apache.geode.cache.wan.GatewaySender)28 IgnoredException (org.apache.geode.test.dunit.IgnoredException)8 Properties (java.util.Properties)7 AttributesFactory (org.apache.geode.cache.AttributesFactory)7 Test (org.junit.Test)7 Region (org.apache.geode.cache.Region)6 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)6 ConcurrentParallelGatewaySenderQueue (org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 CacheListener (org.apache.geode.cache.CacheListener)4 AsyncEventQueue (org.apache.geode.cache.asyncqueue.AsyncEventQueue)4 AsyncEventQueueImpl (org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl)4 BucketRegion (org.apache.geode.internal.cache.BucketRegion)4 AbstractGatewaySender (org.apache.geode.internal.cache.wan.AbstractGatewaySender)4 RegionAttributes (org.apache.geode.cache.RegionAttributes)3 GatewayEventFilter (org.apache.geode.cache.wan.GatewayEventFilter)3 GatewaySenderFactory (org.apache.geode.cache.wan.GatewaySenderFactory)3 GatewayTransportFilter (org.apache.geode.cache.wan.GatewayTransportFilter)3 MyGatewayEventFilter1 (org.apache.geode.cache30.MyGatewayEventFilter1)3