Search in sources :

Example 16 with AsyncEventQueueFactory

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

the class MyGatewayEventSubstitutionFilter method getInitialAsyncEventQueueFactory.

private static AsyncEventQueueFactory getInitialAsyncEventQueueFactory(boolean isParallel, Integer maxMemory, Integer batchSize, boolean isPersistent, String diskStoreName) {
    AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory();
    factory.setBatchSize(batchSize);
    factory.setPersistent(isPersistent);
    factory.setDiskStoreName(diskStoreName);
    factory.setMaximumQueueMemory(maxMemory);
    factory.setParallel(isParallel);
    return factory;
}
Also used : AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory)

Example 17 with AsyncEventQueueFactory

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

the class MyGatewayEventSubstitutionFilter method createConcurrentAsyncEventQueue.

public static void createConcurrentAsyncEventQueue(String asyncChannelId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isConflation, boolean isPersistent, String diskStoreName, boolean isDiskSynchronous, int dispatcherThreads, OrderPolicy policy) {
    createDiskStore(asyncChannelId, diskStoreName);
    AsyncEventListener asyncEventListener = new MyAsyncEventListener();
    AsyncEventQueueFactory factory = getInitialAsyncEventQueueFactory(isParallel, maxMemory, batchSize, isPersistent, diskStoreName);
    factory.setDiskSynchronous(isDiskSynchronous);
    factory.setBatchConflationEnabled(isConflation);
    factory.setOrderPolicy(policy);
    AsyncEventQueue asyncChannel = factory.create(asyncChannelId, asyncEventListener);
}
Also used : AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) AsyncEventListener(org.apache.geode.cache.asyncqueue.AsyncEventListener)

Example 18 with AsyncEventQueueFactory

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

the class CacheXmlParser method endAsyncEventQueue.

private void endAsyncEventQueue() {
    AsyncEventQueueCreation asyncEventChannelCreation = (AsyncEventQueueCreation) stack.peek();
    AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory();
    factory.setParallel(asyncEventChannelCreation.isParallel());
    factory.setBatchSize(asyncEventChannelCreation.getBatchSize());
    factory.setBatchTimeInterval(asyncEventChannelCreation.getBatchTimeInterval());
    factory.setBatchConflationEnabled(asyncEventChannelCreation.isBatchConflationEnabled());
    factory.setPersistent(asyncEventChannelCreation.isPersistent());
    factory.setDiskStoreName(asyncEventChannelCreation.getDiskStoreName());
    factory.setDiskSynchronous(asyncEventChannelCreation.isDiskSynchronous());
    factory.setMaximumQueueMemory(asyncEventChannelCreation.getMaximumQueueMemory());
    factory.setDispatcherThreads(asyncEventChannelCreation.getDispatcherThreads());
    factory.setOrderPolicy(asyncEventChannelCreation.getOrderPolicy());
    factory.setForwardExpirationDestroy(asyncEventChannelCreation.isForwardExpirationDestroy());
    List<GatewayEventFilter> gatewayEventFilters = asyncEventChannelCreation.getGatewayEventFilters();
    for (GatewayEventFilter gatewayEventFilter : gatewayEventFilters) {
        factory.addGatewayEventFilter(gatewayEventFilter);
    }
    factory.setGatewayEventSubstitutionListener(asyncEventChannelCreation.getGatewayEventSubstitutionFilter());
    AsyncEventQueue asyncEventChannel = factory.create(asyncEventChannelCreation.getId(), asyncEventChannelCreation.getAsyncEventListener());
    stack.pop();
}
Also used : AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) GatewayEventFilter(org.apache.geode.cache.wan.GatewayEventFilter)

Example 19 with AsyncEventQueueFactory

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

the class SnapshotDUnitTest method addAsyncEventQueue.

private void addAsyncEventQueue(Region region, String name) {
    DiskStoreFactory dsFactory = getCache().createDiskStoreFactory();
    dsFactory.create(name);
    AsyncEventQueueFactory aeqFactory = getCache().createAsyncEventQueueFactory();
    aeqFactory.setDiskStoreName(name);
    aeqFactory.create(name, new CountingAsyncEventListener());
    region.getAttributesMutator().addAsyncEventQueueId(name);
}
Also used : AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory)

Example 20 with AsyncEventQueueFactory

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

the class CreateAsyncEventQueueFunction method execute.

@SuppressWarnings("deprecation")
@Override
public void execute(FunctionContext context) {
    // Declared here so that it's available when returning a Throwable
    String memberId = "";
    try {
        AsyncEventQueueFunctionArgs aeqArgs = (AsyncEventQueueFunctionArgs) context.getArguments();
        InternalCache cache = getCache();
        DistributedMember member = cache.getDistributedSystem().getDistributedMember();
        memberId = member.getId();
        // If they set a name use it instead
        if (!member.getName().equals("")) {
            memberId = member.getName();
        }
        AsyncEventQueueFactory asyncEventQueueFactory = cache.createAsyncEventQueueFactory().setParallel(aeqArgs.isParallel()).setBatchConflationEnabled(aeqArgs.isEnableBatchConflation()).setBatchSize(aeqArgs.getBatchSize()).setBatchTimeInterval(aeqArgs.getBatchTimeInterval()).setPersistent(aeqArgs.isPersistent()).setDiskStoreName(aeqArgs.getDiskStoreName()).setDiskSynchronous(aeqArgs.isDiskSynchronous()).setForwardExpirationDestroy(aeqArgs.isForwardExpirationDestroy()).setMaximumQueueMemory(aeqArgs.getMaxQueueMemory()).setDispatcherThreads(aeqArgs.getDispatcherThreads()).setOrderPolicy(OrderPolicy.valueOf(aeqArgs.getOrderPolicy()));
        String[] gatewayEventFilters = aeqArgs.getGatewayEventFilters();
        if (gatewayEventFilters != null) {
            for (String gatewayEventFilter : gatewayEventFilters) {
                Class<?> gatewayEventFilterKlass = forName(gatewayEventFilter, CliStrings.CREATE_ASYNC_EVENT_QUEUE__GATEWAYEVENTFILTER);
                asyncEventQueueFactory.addGatewayEventFilter((GatewayEventFilter) newInstance(gatewayEventFilterKlass, CliStrings.CREATE_ASYNC_EVENT_QUEUE__GATEWAYEVENTFILTER));
            }
        }
        String gatewaySubstitutionFilter = aeqArgs.getGatewaySubstitutionFilter();
        if (gatewaySubstitutionFilter != null) {
            Class<?> gatewayEventSubstitutionFilterKlass = forName(gatewaySubstitutionFilter, CliStrings.CREATE_ASYNC_EVENT_QUEUE__SUBSTITUTION_FILTER);
            asyncEventQueueFactory.setGatewayEventSubstitutionListener((GatewayEventSubstitutionFilter<?, ?>) newInstance(gatewayEventSubstitutionFilterKlass, CliStrings.CREATE_ASYNC_EVENT_QUEUE__SUBSTITUTION_FILTER));
        }
        String listenerClassName = aeqArgs.getListenerClassName();
        Object listenerInstance;
        Class<?> listenerClass = InternalDataSerializer.getCachedClass(listenerClassName);
        listenerInstance = listenerClass.newInstance();
        Properties listenerProperties = aeqArgs.getListenerProperties();
        if (listenerProperties != null && !listenerProperties.isEmpty()) {
            if (!(listenerInstance instanceof Declarable)) {
                throw new IllegalArgumentException("Listener properties were provided, but the listener specified does not implement Declarable.");
            }
            ((Declarable) listenerInstance).init(listenerProperties);
            Map<Declarable, Properties> declarablesMap = new HashMap<Declarable, Properties>();
            declarablesMap.put((Declarable) listenerInstance, listenerProperties);
            cache.addDeclarableProperties(declarablesMap);
        }
        asyncEventQueueFactory.create(aeqArgs.getAsyncEventQueueId(), (AsyncEventListener) listenerInstance);
        XmlEntity xmlEntity = new XmlEntity(CacheXml.ASYNC_EVENT_QUEUE, "id", aeqArgs.getAsyncEventQueueId());
        context.getResultSender().lastResult(new CliFunctionResult(memberId, xmlEntity, "Success"));
    } catch (CacheClosedException cce) {
        context.getResultSender().lastResult(new CliFunctionResult(memberId, false, null));
    } catch (VirtualMachineError e) {
        SystemFailure.initiateFailure(e);
        throw e;
    } catch (Throwable th) {
        SystemFailure.checkFailure();
        logger.error("Could not create async event queue: {}", th.getMessage(), th);
        context.getResultSender().lastResult(new CliFunctionResult(memberId, th, null));
    }
}
Also used : Declarable(org.apache.geode.cache.Declarable) HashMap(java.util.HashMap) InternalCache(org.apache.geode.internal.cache.InternalCache) CacheClosedException(org.apache.geode.cache.CacheClosedException) Properties(java.util.Properties) XmlEntity(org.apache.geode.management.internal.configuration.domain.XmlEntity) AsyncEventQueueFactory(org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory) DistributedMember(org.apache.geode.distributed.DistributedMember)

Aggregations

AsyncEventQueueFactory (org.apache.geode.cache.asyncqueue.AsyncEventQueueFactory)20 AsyncEventQueue (org.apache.geode.cache.asyncqueue.AsyncEventQueue)13 AsyncEventListener (org.apache.geode.cache.asyncqueue.AsyncEventListener)10 Test (org.junit.Test)9 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)7 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)6 RegionAttributesCreation (org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation)5 Cache (org.apache.geode.cache.Cache)4 DiskStoreFactory (org.apache.geode.cache.DiskStoreFactory)3 File (java.io.File)2 Properties (java.util.Properties)2 CacheFactory (org.apache.geode.cache.CacheFactory)2 CacheXml70DUnitTest (org.apache.geode.cache30.CacheXml70DUnitTest)2 AsyncEventQueueConfigurationException (org.apache.geode.internal.cache.wan.AsyncEventQueueConfigurationException)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 HashMap (java.util.HashMap)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 Declarable (org.apache.geode.cache.Declarable)1 Region (org.apache.geode.cache.Region)1 GatewayEventFilter (org.apache.geode.cache.wan.GatewayEventFilter)1