Search in sources :

Example 1 with AsyncEventQueue

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

the class AsyncEventQueueFactoryImpl method create.

public AsyncEventQueue create(String asyncQueueId, AsyncEventListener listener) {
    if (listener == null) {
        throw new IllegalArgumentException(LocalizedStrings.AsyncEventQueue_ASYNC_EVENT_LISTENER_CANNOT_BE_NULL.toLocalizedString());
    }
    AsyncEventQueue asyncEventQueue = null;
    if (this.cache instanceof GemFireCacheImpl) {
        if (logger.isDebugEnabled()) {
            logger.debug("Creating GatewaySender that underlies the AsyncEventQueue");
        }
        addAsyncEventListener(listener);
        GatewaySender sender = create(AsyncEventQueueImpl.getSenderIdFromAsyncEventQueueId(asyncQueueId));
        AsyncEventQueueImpl queue = new AsyncEventQueueImpl(sender, listener);
        asyncEventQueue = queue;
        this.cache.addAsyncEventQueue(queue);
    } else if (this.cache instanceof CacheCreation) {
        asyncEventQueue = new AsyncEventQueueCreation(asyncQueueId, attrs, listener);
        ((CacheCreation) cache).addAsyncEventQueue(asyncEventQueue);
    }
    if (logger.isDebugEnabled()) {
        logger.debug("Returning AsyncEventQueue" + asyncEventQueue);
    }
    return asyncEventQueue;
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) SerialAsyncEventQueueCreation(org.apache.geode.internal.cache.xmlcache.SerialAsyncEventQueueCreation) AsyncEventQueueCreation(org.apache.geode.internal.cache.xmlcache.AsyncEventQueueCreation) ParallelAsyncEventQueueCreation(org.apache.geode.internal.cache.xmlcache.ParallelAsyncEventQueueCreation) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation)

Example 2 with AsyncEventQueue

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

the class CacheCreation method create.

/**
   * Fills in the contents of a {@link Cache} based on this creation object's state.
   */
void create(InternalCache cache) throws TimeoutException, CacheWriterException, GatewayException, RegionExistsException {
    this.extensionPoint.beforeCreate(cache);
    cache.setDeclarativeCacheConfig(this.cacheConfig);
    if (cache.isClient()) {
        throw new IllegalStateException("You must use client-cache in the cache.xml when ClientCacheFactory is used.");
    }
    if (this.hasLockLease()) {
        cache.setLockLease(this.lockLease);
    }
    if (this.hasLockTimeout()) {
        cache.setLockTimeout(this.lockTimeout);
    }
    if (this.hasSearchTimeout()) {
        cache.setSearchTimeout(this.searchTimeout);
    }
    if (this.hasMessageSyncInterval()) {
        cache.setMessageSyncInterval(this.getMessageSyncInterval());
    }
    if (this.gatewayConflictResolver != null) {
        cache.setGatewayConflictResolver(this.gatewayConflictResolver);
    }
    // create connection pools
    Map<String, Pool> pools = getPools();
    if (!pools.isEmpty()) {
        for (Pool pool : pools.values()) {
            PoolFactoryImpl poolFactory = (PoolFactoryImpl) PoolManager.createFactory();
            poolFactory.init(pool);
            poolFactory.create(pool.getName());
        }
    }
    if (hasResourceManager()) {
        // moved this up to fix bug 42128
        getResourceManager().configure(cache.getResourceManager());
    }
    DiskStoreAttributesCreation pdxRegDSC = initializePdxDiskStore(cache);
    cache.initializePdxRegistry();
    for (DiskStore diskStore : this.diskStores.values()) {
        DiskStoreAttributesCreation creation = (DiskStoreAttributesCreation) diskStore;
        if (creation != pdxRegDSC) {
            createDiskStore(creation, cache);
        }
    }
    if (this.hasDynamicRegionFactory()) {
        DynamicRegionFactory.get().open(this.getDynamicRegionFactoryConfig());
    }
    if (this.hasServer()) {
        cache.setIsServer(this.isServer);
    }
    if (this.hasCopyOnRead()) {
        cache.setCopyOnRead(this.copyOnRead);
    }
    if (this.txMgrCreation != null && this.txMgrCreation.getListeners().length > 0 && cache.getCacheTransactionManager() != null) {
        cache.getCacheTransactionManager().initListeners(this.txMgrCreation.getListeners());
    }
    if (this.txMgrCreation != null && cache.getCacheTransactionManager() != null) {
        cache.getCacheTransactionManager().setWriter(this.txMgrCreation.getWriter());
    }
    for (GatewaySender senderCreation : this.getGatewaySenders()) {
        GatewaySenderFactory factory = cache.createGatewaySenderFactory();
        ((InternalGatewaySenderFactory) factory).configureGatewaySender(senderCreation);
        GatewaySender gatewaySender = factory.create(senderCreation.getId(), senderCreation.getRemoteDSId());
        // Start the sender if it is not set to manually start
        if (gatewaySender.isManualStart()) {
            cache.getLoggerI18n().info(LocalizedStrings.CacheCreation_0_IS_NOT_BEING_STARTED_SINCE_IT_IS_CONFIGURED_FOR_MANUAL_START, gatewaySender);
        }
    }
    for (AsyncEventQueue asyncEventQueueCreation : this.getAsyncEventQueues()) {
        AsyncEventQueueFactoryImpl asyncQueueFactory = (AsyncEventQueueFactoryImpl) cache.createAsyncEventQueueFactory();
        asyncQueueFactory.configureAsyncEventQueue(asyncEventQueueCreation);
        AsyncEventQueue asyncEventQueue = cache.getAsyncEventQueue(asyncEventQueueCreation.getId());
        if (asyncEventQueue == null) {
            asyncQueueFactory.create(asyncEventQueueCreation.getId(), asyncEventQueueCreation.getAsyncEventListener());
        }
    }
    cache.initializePdxRegistry();
    for (String id : this.regionAttributesNames) {
        RegionAttributesCreation creation = (RegionAttributesCreation) getRegionAttributes(id);
        creation.inheritAttributes(cache, false);
        // Don't let the RegionAttributesCreation escape to the user
        AttributesFactory<?, ?> factory = new AttributesFactory<>(creation);
        RegionAttributes<?, ?> attrs = factory.create();
        cache.setRegionAttributes(id, attrs);
    }
    initializeRegions(this.roots, cache);
    cache.readyDynamicRegionFactory();
    // Create and start the BridgeServers. This code was moved from
    // before region initialization to after it to fix bug 33587.
    // Create and start the CacheServers after the gateways have been initialized
    // to fix bug 39736.
    Integer serverPort = CacheServerLauncher.getServerPort();
    String serverBindAdd = CacheServerLauncher.getServerBindAddress();
    Boolean disableDefaultServer = CacheServerLauncher.getDisableDefaultServer();
    startCacheServers(getCacheServers(), cache, serverPort, serverBindAdd, disableDefaultServer);
    for (GatewayReceiver receiverCreation : this.getGatewayReceivers()) {
        GatewayReceiverFactory factory = cache.createGatewayReceiverFactory();
        factory.setBindAddress(receiverCreation.getBindAddress());
        factory.setMaximumTimeBetweenPings(receiverCreation.getMaximumTimeBetweenPings());
        factory.setStartPort(receiverCreation.getStartPort());
        factory.setEndPort(receiverCreation.getEndPort());
        factory.setSocketBufferSize(receiverCreation.getSocketBufferSize());
        factory.setManualStart(receiverCreation.isManualStart());
        for (GatewayTransportFilter filter : receiverCreation.getGatewayTransportFilters()) {
            factory.addGatewayTransportFilter(filter);
        }
        factory.setHostnameForSenders(receiverCreation.getHost());
        GatewayReceiver receiver = factory.create();
        if (receiver.isManualStart()) {
            cache.getLoggerI18n().info(LocalizedStrings.CacheCreation_0_IS_NOT_BEING_STARTED_SINCE_IT_IS_CONFIGURED_FOR_MANUAL_START, receiver);
        }
    }
    cache.setBackupFiles(this.backups);
    cache.addDeclarableProperties(this.declarablePropertiesMap);
    runInitializer();
    cache.setInitializer(getInitializer(), getInitializerProps());
    // Create all extensions
    this.extensionPoint.fireCreate(cache);
}
Also used : AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) GatewaySender(org.apache.geode.cache.wan.GatewaySender) GatewayReceiverFactory(org.apache.geode.cache.wan.GatewayReceiverFactory) GatewayReceiver(org.apache.geode.cache.wan.GatewayReceiver) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl) DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) AsyncEventQueueFactoryImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueFactoryImpl) InternalGatewaySenderFactory(org.apache.geode.internal.cache.wan.InternalGatewaySenderFactory) GatewaySenderFactory(org.apache.geode.cache.wan.GatewaySenderFactory) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) Pool(org.apache.geode.cache.client.Pool) GatewayTransportFilter(org.apache.geode.cache.wan.GatewayTransportFilter) InternalGatewaySenderFactory(org.apache.geode.internal.cache.wan.InternalGatewaySenderFactory)

Example 3 with AsyncEventQueue

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

the class CacheXmlGenerator method generateAsyncEventQueue.

private void generateAsyncEventQueue(Cache cache) throws SAXException {
    Set<AsyncEventQueue> asyncEventQueues = cache.getAsyncEventQueues();
    for (AsyncEventQueue asyncEventQueue : asyncEventQueues) {
        AttributesImpl atts = new AttributesImpl();
        // id
        atts.addAttribute("", "", ID, "", asyncEventQueue.getId());
        // parallel
        if (generateDefaults() || asyncEventQueue.isParallel() != GatewaySender.DEFAULT_IS_PARALLEL)
            atts.addAttribute("", "", PARALLEL, "", String.valueOf(asyncEventQueue.isParallel()));
        // batch-size
        if (generateDefaults() || asyncEventQueue.getBatchSize() != GatewaySender.DEFAULT_BATCH_SIZE)
            atts.addAttribute("", "", BATCH_SIZE, "", String.valueOf(asyncEventQueue.getBatchSize()));
        // batch-time-interval
        if (generateDefaults() || asyncEventQueue.getBatchTimeInterval() != GatewaySender.DEFAULT_BATCH_TIME_INTERVAL)
            atts.addAttribute("", "", BATCH_TIME_INTERVAL, "", String.valueOf(asyncEventQueue.getBatchTimeInterval()));
        // enable-batch-conflation
        if (generateDefaults() || asyncEventQueue.isBatchConflationEnabled() != GatewaySender.DEFAULT_BATCH_CONFLATION)
            atts.addAttribute("", "", ENABLE_BATCH_CONFLATION, "", String.valueOf(asyncEventQueue.isBatchConflationEnabled()));
        // maximum-queue-memory
        if (generateDefaults() || asyncEventQueue.getMaximumQueueMemory() != GatewaySender.DEFAULT_MAXIMUM_QUEUE_MEMORY)
            atts.addAttribute("", "", MAXIMUM_QUEUE_MEMORY, "", String.valueOf(asyncEventQueue.getMaximumQueueMemory()));
        // enable-persistence
        if (generateDefaults() || asyncEventQueue.isPersistent() != GatewaySender.DEFAULT_PERSISTENCE_ENABLED)
            atts.addAttribute("", "", PERSISTENT, "", String.valueOf(asyncEventQueue.isPersistent()));
        if (asyncEventQueue.isPersistent()) {
            // disk-store-name
            if (generateDefaults() || (asyncEventQueue.getDiskStoreName() != null && !asyncEventQueue.getDiskStoreName().equals("")))
                atts.addAttribute("", "", DISK_STORE_NAME, "", String.valueOf(asyncEventQueue.getDiskStoreName()));
        }
        // dispatcher-threads
        if (generateDefaults() || asyncEventQueue.getDispatcherThreads() != GatewaySender.DEFAULT_DISPATCHER_THREADS)
            atts.addAttribute("", "", DISPATCHER_THREADS, "", String.valueOf(asyncEventQueue.getDispatcherThreads()));
        // order-policy
        if (asyncEventQueue.getOrderPolicy() != null) {
            if (generateDefaults() || !asyncEventQueue.getOrderPolicy().equals(GatewaySender.DEFAULT_ORDER_POLICY))
                atts.addAttribute("", "", ORDER_POLICY, "", String.valueOf(asyncEventQueue.getOrderPolicy()));
        }
        // eviction and expiration events
        if (this.version.compareTo(CacheXmlVersion.GEODE_1_0) >= 0) {
            if (generateDefaults() || asyncEventQueue.isForwardExpirationDestroy() != (GatewaySender.DEFAULT_FORWARD_EXPIRATION_DESTROY))
                atts.addAttribute("", "", FORWARD_EXPIRATION_DESTROY, "", String.valueOf(asyncEventQueue.isForwardExpirationDestroy()));
        }
        // disk-synchronous
        if (generateDefaults() || asyncEventQueue.isDiskSynchronous() != GatewaySender.DEFAULT_DISK_SYNCHRONOUS)
            atts.addAttribute("", "", DISK_SYNCHRONOUS, "", String.valueOf(asyncEventQueue.isDiskSynchronous()));
        // AsyncEventQueue element start
        handler.startElement("", ASYNC_EVENT_QUEUE, ASYNC_EVENT_QUEUE, atts);
        List<GatewayEventFilter> eventFilters = asyncEventQueue.getGatewayEventFilters();
        if (eventFilters != null) {
            for (GatewayEventFilter eventFilter : eventFilters) {
                generateGatewayEventFilter(eventFilter);
            }
        }
        if (this.version.compareTo(CacheXmlVersion.GEMFIRE_8_0) >= 0) {
            if (asyncEventQueue.getGatewayEventSubstitutionFilter() != null) {
                generateGatewayEventSubstitutionFilter(asyncEventQueue.getGatewayEventSubstitutionFilter());
            }
        }
        AsyncEventListener asyncListener = asyncEventQueue.getAsyncEventListener();
        if (asyncListener != null) {
            generate(ASYNC_EVENT_LISTENER, asyncListener);
        }
        handler.endElement("", ASYNC_EVENT_QUEUE, ASYNC_EVENT_QUEUE);
    }
}
Also used : DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) GatewayEventFilter(org.apache.geode.cache.wan.GatewayEventFilter) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 4 with AsyncEventQueue

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

the class CacheXml70DUnitTest method testAsyncEventQueueWithGatewayEventFilter.

/**
   * Added to test the scenario of defect #50600.
   */
@Test
public void testAsyncEventQueueWithGatewayEventFilter() throws Exception {
    getSystem();
    CacheCreation cache = new CacheCreation();
    String id = "WBCLChannel";
    AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory();
    factory.setBatchSize(100);
    factory.setBatchTimeInterval(500);
    factory.setBatchConflationEnabled(true);
    factory.setMaximumQueueMemory(200);
    factory.setDiskSynchronous(true);
    factory.setParallel(false);
    factory.setDispatcherThreads(33);
    AsyncEventListener eventListener = new MyAsyncEventListener();
    AsyncEventQueue asyncEventQueue = factory.create(id, eventListener);
    RegionAttributesCreation attrs = new RegionAttributesCreation();
    attrs.addAsyncEventQueueId(asyncEventQueue.getId());
    cache.createRegion("UserRegion", attrs);
    testXml(cache);
    Cache c = getCache();
    assertNotNull(c);
    Set<AsyncEventQueue> asyncEventQueuesOnCache = c.getAsyncEventQueues();
    assertTrue("Size of asyncEventQueues should be greater than 0", asyncEventQueuesOnCache.size() > 0);
    for (AsyncEventQueue asyncEventQueueOnCache : asyncEventQueuesOnCache) {
        CacheXml70DUnitTest.validateAsyncEventQueue(asyncEventQueue, asyncEventQueueOnCache);
    }
}
Also used : AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 5 with AsyncEventQueue

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

the class CacheXml70DUnitTest method testConcurrentAsyncEventQueue.

@Test
public void testConcurrentAsyncEventQueue() throws Exception {
    getSystem();
    CacheCreation cache = new CacheCreation();
    String id = "WBCLChannel";
    AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory();
    factory.setBatchSize(100);
    factory.setBatchTimeInterval(500);
    factory.setBatchConflationEnabled(true);
    factory.setMaximumQueueMemory(200);
    factory.setDiskSynchronous(true);
    factory.setDispatcherThreads(5);
    factory.setOrderPolicy(OrderPolicy.THREAD);
    AsyncEventListener eventListener = new MyAsyncEventListener();
    AsyncEventQueue asyncEventQueue = factory.create(id, eventListener);
    RegionAttributesCreation attrs = new RegionAttributesCreation();
    attrs.addAsyncEventQueueId(asyncEventQueue.getId());
    cache.createRegion("UserRegion", attrs);
    testXml(cache);
    Cache c = getCache();
    assertNotNull(c);
    Set<AsyncEventQueue> asyncEventQueuesOnCache = c.getAsyncEventQueues();
    assertTrue("Size of asyncEventQueues should be greater than 0", asyncEventQueuesOnCache.size() > 0);
    for (AsyncEventQueue asyncEventQueueOnCache : asyncEventQueuesOnCache) {
        validateConcurrentAsyncEventQueue(asyncEventQueue, asyncEventQueueOnCache);
    }
}
Also used : AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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