Search in sources :

Example 51 with AsyncEventQueue

use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.

the class ManagementListener method handleEvent.

/**
   * Handles various GFE resource life-cycle methods vis-a-vis Management and Monitoring
   * 
   * It checks for race conditions cases by calling shouldProceed();
   *
   * @param event Management event for which invocation has happened
   * @param resource the GFE resource type
   */
public void handleEvent(ResourceEvent event, Object resource) {
    if (!shouldProceed(event)) {
        return;
    }
    switch(event) {
        case CACHE_CREATE:
            InternalCache createdCache = (InternalCache) resource;
            adapter.handleCacheCreation(createdCache);
            break;
        case CACHE_REMOVE:
            InternalCache removedCache = (InternalCache) resource;
            adapter.handleCacheRemoval(removedCache);
            break;
        case REGION_CREATE:
            Region createdRegion = (Region) resource;
            adapter.handleRegionCreation(createdRegion);
            break;
        case REGION_REMOVE:
            Region removedRegion = (Region) resource;
            adapter.handleRegionRemoval(removedRegion);
            break;
        case DISKSTORE_CREATE:
            DiskStore createdDisk = (DiskStore) resource;
            adapter.handleDiskCreation(createdDisk);
            break;
        case DISKSTORE_REMOVE:
            DiskStore removedDisk = (DiskStore) resource;
            adapter.handleDiskRemoval(removedDisk);
            break;
        case GATEWAYRECEIVER_CREATE:
            GatewayReceiver createdRecv = (GatewayReceiver) resource;
            adapter.handleGatewayReceiverCreate(createdRecv);
            break;
        case GATEWAYRECEIVER_START:
            GatewayReceiver startedRecv = (GatewayReceiver) resource;
            adapter.handleGatewayReceiverStart(startedRecv);
            break;
        case GATEWAYRECEIVER_STOP:
            GatewayReceiver stoppededRecv = (GatewayReceiver) resource;
            adapter.handleGatewayReceiverStop(stoppededRecv);
            break;
        case GATEWAYSENDER_CREATE:
            GatewaySender sender = (GatewaySender) resource;
            adapter.handleGatewaySenderCreation(sender);
            break;
        case GATEWAYSENDER_START:
            GatewaySender startedSender = (GatewaySender) resource;
            adapter.handleGatewaySenderStart(startedSender);
            break;
        case GATEWAYSENDER_STOP:
            GatewaySender stoppedSender = (GatewaySender) resource;
            adapter.handleGatewaySenderStop(stoppedSender);
            break;
        case GATEWAYSENDER_PAUSE:
            GatewaySender pausedSender = (GatewaySender) resource;
            adapter.handleGatewaySenderPaused(pausedSender);
            break;
        case GATEWAYSENDER_RESUME:
            GatewaySender resumedSender = (GatewaySender) resource;
            adapter.handleGatewaySenderResumed(resumedSender);
            break;
        case LOCKSERVICE_CREATE:
            DLockService createdLockService = (DLockService) resource;
            adapter.handleLockServiceCreation(createdLockService);
            break;
        case LOCKSERVICE_REMOVE:
            DLockService removedLockService = (DLockService) resource;
            adapter.handleLockServiceRemoval(removedLockService);
            break;
        case MANAGER_CREATE:
            adapter.handleManagerCreation();
            break;
        case MANAGER_START:
            adapter.handleManagerStart();
            break;
        case MANAGER_STOP:
            adapter.handleManagerStop();
            break;
        case ASYNCEVENTQUEUE_CREATE:
            AsyncEventQueue queue = (AsyncEventQueue) resource;
            adapter.handleAsyncEventQueueCreation(queue);
            break;
        case ASYNCEVENTQUEUE_REMOVE:
            AsyncEventQueue removedQueue = (AsyncEventQueue) resource;
            adapter.handleAsyncEventQueueRemoval(removedQueue);
            break;
        case SYSTEM_ALERT:
            AlertDetails details = (AlertDetails) resource;
            adapter.handleSystemNotification(details);
            break;
        case CACHE_SERVER_START:
            CacheServer startedServer = (CacheServer) resource;
            adapter.handleCacheServerStart(startedServer);
            break;
        case CACHE_SERVER_STOP:
            CacheServer stoppedServer = (CacheServer) resource;
            adapter.handleCacheServerStop(stoppedServer);
            break;
        case LOCATOR_START:
            Locator loc = (Locator) resource;
            adapter.handleLocatorStart(loc);
            break;
        case CACHE_SERVICE_CREATE:
            CacheService service = (CacheService) resource;
            adapter.handleCacheServiceCreation(service);
            break;
        default:
            break;
    }
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) GatewaySender(org.apache.geode.cache.wan.GatewaySender) Locator(org.apache.geode.distributed.Locator) AlertDetails(org.apache.geode.management.internal.AlertDetails) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) DLockService(org.apache.geode.distributed.internal.locks.DLockService) InternalCache(org.apache.geode.internal.cache.InternalCache) Region(org.apache.geode.cache.Region) GatewayReceiver(org.apache.geode.cache.wan.GatewayReceiver) CacheServer(org.apache.geode.cache.server.CacheServer) CacheService(org.apache.geode.internal.cache.CacheService)

Example 52 with AsyncEventQueue

use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.

the class SnapshotDUnitTest method verifyCallbacksInvoked.

private void verifyCallbacksInvoked() throws Exception {
    for (final RegionType rt : RegionType.values()) {
        for (final SerializationType st : SerializationType.values()) {
            SerializableCallable counts = new SerializableCallable() {

                @Override
                public Object call() throws Exception {
                    String name = "test-" + rt.name() + "-" + st.name();
                    Region<Integer, MyObject> region = getCache().getRegion(name);
                    // get CacheWriter and CacheListener events
                    CountingCacheWriter writer = (CountingCacheWriter) region.getAttributes().getCacheWriter();
                    CountingCacheListener listener = (CountingCacheListener) region.getAttributes().getCacheListener();
                    // get AsyncEventListener events
                    int numAeqEvents = 0;
                    AsyncEventQueue aeq = getCache().getAsyncEventQueue(name);
                    CountingAsyncEventListener aeqListener = (CountingAsyncEventListener) aeq.getAsyncEventListener();
                    if (aeq.isPrimary()) {
                        Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> aeqListener.getEvents() == NUM_ENTRIES);
                        numAeqEvents = aeqListener.getEvents();
                    }
                    return new int[] { writer.getEvents(), listener.getEvents(), numAeqEvents };
                }
            };
            Object result = forEachVm(counts, true);
            int totalWriterUpdates = 0, totalListenerUpdates = 0, totalAeqEvents = 0;
            List<int[]> list = (List) result;
            for (int[] vmResult : list) {
                totalWriterUpdates += vmResult[0];
                totalListenerUpdates += vmResult[1];
                totalAeqEvents += vmResult[2];
            }
            if (rt.name().contains("PARTITION")) {
                assertEquals(NUM_ENTRIES, totalListenerUpdates);
            } else {
                assertEquals(NUM_ENTRIES * (Host.getHost(0).getVMCount() + 1), totalListenerUpdates);
            }
            assertEquals(NUM_ENTRIES, totalWriterUpdates);
            assertEquals(NUM_ENTRIES, totalAeqEvents);
        }
    }
}
Also used : RegionType(org.apache.geode.cache.snapshot.RegionGenerator.RegionType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) MyObject(com.examples.snapshot.MyObject) MyObject(com.examples.snapshot.MyObject) ArrayList(java.util.ArrayList) List(java.util.List) SerializationType(org.apache.geode.cache.snapshot.RegionGenerator.SerializationType)

Example 53 with AsyncEventQueue

use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.

the class ListAsyncEventQueuesFunction method execute.

@Override
public void execute(final FunctionContext context) {
    // Declared here so that it's available when returning a Throwable
    String memberId = "";
    try {
        Cache cache = CacheFactory.getAnyInstance();
        DistributedMember member = cache.getDistributedSystem().getDistributedMember();
        memberId = member.getId();
        // If they set a name use it instead
        if (!member.getName().equals("")) {
            memberId = member.getName();
        }
        Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues();
        AsyncEventQueueDetails[] asyncEventQueueDetails = new AsyncEventQueueDetails[asyncEventQueues.size()];
        int i = 0;
        for (AsyncEventQueue queue : asyncEventQueues) {
            AsyncEventListener listener = queue.getAsyncEventListener();
            Properties listenerProperties = new Properties();
            if (listener instanceof Declarable2) {
                listenerProperties = ((Declarable2) listener).getConfig();
            }
            asyncEventQueueDetails[i++] = new AsyncEventQueueDetails(queue.getId(), queue.getBatchSize(), queue.isPersistent(), queue.getDiskStoreName(), queue.getMaximumQueueMemory(), listener.getClass().getName(), listenerProperties);
        }
        CliFunctionResult result = new CliFunctionResult(memberId, asyncEventQueueDetails);
        context.getResultSender().lastResult(result);
    } catch (CacheClosedException cce) {
        CliFunctionResult result = new CliFunctionResult(memberId, false, null);
        context.getResultSender().lastResult(result);
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        logger.error("Could not list async event queues: {}", th.getMessage(), th);
        CliFunctionResult result = new CliFunctionResult(memberId, th, null);
        context.getResultSender().lastResult(result);
    }
}
Also used : AsyncEventQueueDetails(org.apache.geode.management.internal.cli.domain.AsyncEventQueueDetails) Declarable2(org.apache.geode.internal.cache.xmlcache.Declarable2) CacheClosedException(org.apache.geode.cache.CacheClosedException) Properties(java.util.Properties) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) DistributedMember(org.apache.geode.distributed.DistributedMember) Cache(org.apache.geode.cache.Cache) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 54 with AsyncEventQueue

use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.

the class DescribeDiskStoreFunctionJUnitTest method setupAsyncEventQueuesForTestExecute.

private Set<DiskStoreDetails.AsyncEventQueueDetails> setupAsyncEventQueuesForTestExecute(final InternalCache mockCache, final String diskStoreName) {
    final AsyncEventQueue mockAsyncEventQueue1 = mockContext.mock(AsyncEventQueue.class, "AsyncEventQueue1");
    final AsyncEventQueue mockAsyncEventQueue2 = mockContext.mock(AsyncEventQueue.class, "AsyncEventQueue2");
    final AsyncEventQueue mockAsyncEventQueue3 = mockContext.mock(AsyncEventQueue.class, "AsyncEventQueue3");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockCache).getAsyncEventQueues();
            will(returnValue(CollectionUtils.asSet(mockAsyncEventQueue1, mockAsyncEventQueue2, mockAsyncEventQueue3)));
            oneOf(mockAsyncEventQueue1).isPersistent();
            will(returnValue(true));
            oneOf(mockAsyncEventQueue1).getDiskStoreName();
            will(returnValue(diskStoreName));
            oneOf(mockAsyncEventQueue1).getId();
            will(returnValue("9876543210"));
            oneOf(mockAsyncEventQueue2).isPersistent();
            will(returnValue(false));
            oneOf(mockAsyncEventQueue3).isPersistent();
            will(returnValue(true));
            oneOf(mockAsyncEventQueue3).getDiskStoreName();
            will(returnValue("memSto"));
        }
    });
    return CollectionUtils.asSet(createAsyncEventQueueDetails("9876543210"));
}
Also used : Expectations(org.jmock.Expectations) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue)

Example 55 with AsyncEventQueue

use of org.apache.geode.cache.asyncqueue.AsyncEventQueue in project geode by apache.

the class DescribeDiskStoreFunctionJUnitTest method testGetAsyncEventQueueDiskStoreNameUsingDefaultDiskStore.

@Test
public void testGetAsyncEventQueueDiskStoreNameUsingDefaultDiskStore() {
    final AsyncEventQueue mockQueue = mockContext.mock(AsyncEventQueue.class, "AsyncEventQueue");
    mockContext.checking(new Expectations() {

        {
            oneOf(mockQueue).getDiskStoreName();
            will(returnValue(null));
        }
    });
    final DescribeDiskStoreFunction function = createDescribeDiskStoreFunction(null);
    assertEquals(DiskStoreDetails.DEFAULT_DISK_STORE_NAME, function.getDiskStoreName(mockQueue));
}
Also used : Expectations(org.jmock.Expectations) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

AsyncEventQueue (org.apache.geode.cache.asyncqueue.AsyncEventQueue)62 Test (org.junit.Test)20 AsyncEventListener (org.apache.geode.cache.asyncqueue.AsyncEventListener)19 AsyncEventQueueFactory (org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory)13 AsyncEventQueueImpl (org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueImpl)13 Cache (org.apache.geode.cache.Cache)10 GatewaySender (org.apache.geode.cache.wan.GatewaySender)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)9 UnitTest (org.apache.geode.test.junit.categories.UnitTest)8 Expectations (org.jmock.Expectations)8 DiskStore (org.apache.geode.cache.DiskStore)7 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)7 HashMap (java.util.HashMap)6 Map (java.util.Map)6 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)6 Region (org.apache.geode.cache.Region)5 AsyncEventQueueStats (org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueStats)5 RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)5 File (java.io.File)4 Properties (java.util.Properties)4