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(); }
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; }
public static void createAsyncEventQueue(String asyncChannelId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isConflation, boolean isPersistent, String diskStoreName, boolean isDiskSynchronous, int numDispatcherThreads, final AsyncEventListener asyncEventListener) { createDiskStore(asyncChannelId, diskStoreName); AsyncEventQueueFactory factory = getInitialAsyncEventQueueFactory(isParallel, maxMemory, batchSize, isPersistent, diskStoreName); factory.setDiskSynchronous(isDiskSynchronous); factory.setBatchConflationEnabled(isConflation); // set dispatcher threads factory.setDispatcherThreads(numDispatcherThreads); // Set GatewayEventSubstitutionFilter AsyncEventQueue asyncChannel = factory.create(asyncChannelId, asyncEventListener); }
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); }
public static String createAsyncEventQueueWithDiskStore(String asyncChannelId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isPersistent, String diskStoreName) { AsyncEventListener asyncEventListener = new MyAsyncEventListener(); File persistentDirectory = null; if (diskStoreName == null) { persistentDirectory = new File( asyncChannelId + "_disk_" + System.currentTimeMillis() + "_" + VM.getCurrentVMNum()); } else { persistentDirectory = new File(diskStoreName); } LogWriterUtils.getLogWriter().info("The ds is : " + persistentDirectory.getName()); persistentDirectory.mkdir(); DiskStoreFactory dsf = cache.createDiskStoreFactory(); File[] dirs1 = new File[] {persistentDirectory}; AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory(); factory.setBatchSize(batchSize); factory.setParallel(isParallel); if (isPersistent) { factory.setPersistent(isPersistent); factory.setDiskStoreName(dsf.setDiskDirs(dirs1).create(asyncChannelId).getName()); } factory.setMaximumQueueMemory(maxMemory); // set dispatcher threads factory.setDispatcherThreads(numDispatcherThreadsForTheRun); AsyncEventQueue asyncChannel = factory.create(asyncChannelId, asyncEventListener); return persistentDirectory.getName(); }
@Override protected void doInit() { Assert.state(this.asyncEventListener != null, "AsyncEventListener must not be null"); AsyncEventQueueFactory asyncEventQueueFactory = this.factory != null ? (AsyncEventQueueFactory) this.factory : this.cache.createAsyncEventQueueFactory(); Optional.ofNullable(this.batchConflationEnabled).ifPresent(asyncEventQueueFactory::setBatchConflationEnabled); Optional.ofNullable(this.batchSize).ifPresent(asyncEventQueueFactory::setBatchSize); Optional.ofNullable(this.batchTimeInterval).ifPresent(asyncEventQueueFactory::setBatchTimeInterval); Optional.ofNullable(this.diskStoreReference).ifPresent(asyncEventQueueFactory::setDiskStoreName); Optional.ofNullable(this.diskSynchronous).ifPresent(asyncEventQueueFactory::setDiskSynchronous); Optional.ofNullable(this.dispatcherThreads).ifPresent(asyncEventQueueFactory::setDispatcherThreads); Optional.ofNullable(this.forwardExpirationDestroy).ifPresent(asyncEventQueueFactory::setForwardExpirationDestroy); Optional.ofNullable(this.gatewayEventSubstitutionFilter).ifPresent(asyncEventQueueFactory::setGatewayEventSubstitutionListener); Optional.ofNullable(this.maximumQueueMemory).ifPresent(asyncEventQueueFactory::setMaximumQueueMemory); Optional.ofNullable(this.persistent).ifPresent(asyncEventQueueFactory::setPersistent); asyncEventQueueFactory.setParallel(isParallelEventQueue()); nullSafeList(this.gatewayEventFilters).forEach(asyncEventQueueFactory::addGatewayEventFilter); if (this.orderPolicy != null) { Assert.state(isSerialEventQueue(), "OrderPolicy cannot be used with a Parallel AsyncEventQueue"); asyncEventQueueFactory.setOrderPolicy(this.orderPolicy); } setAsyncEventQueue(asyncEventQueueFactory.create(getName(), this.asyncEventListener)); }
/** * Create an async-event-queue with the given name. * For a partitioned region a parallel queue is created. * Otherwise a serial queue is created. */ private void createAsyncEventQueue(Cache cache, String queueName, boolean isPartitioned) { AsyncEventQueueFactory asyncEventQueueFactory = cache.createAsyncEventQueueFactory(); asyncEventQueueFactory.setParallel(isPartitioned); asyncEventQueueFactory.create(queueName, new JdbcAsyncWriter()); }
public static void createAsyncEventQueueWithListener2(String asyncChannelId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isPersistent, String diskStoreName) { createDiskStore(asyncChannelId, diskStoreName); AsyncEventListener asyncEventListener = new MyAsyncEventListener2(); AsyncEventQueueFactory factory = getInitialAsyncEventQueueFactory(isParallel, maxMemory, batchSize, isPersistent, diskStoreName); // set dispatcher threads factory.setDispatcherThreads(numDispatcherThreadsForTheRun); AsyncEventQueue asyncChannel = factory.create(asyncChannelId, asyncEventListener); }
/** * Test to verify that AsyncEventQueue can not be created when null listener is passed. */ @Test public void testCreateAsyncEventQueueWithNullListener() { asyncEventQueueFactory = new AsyncEventQueueFactoryImpl(cache); assertThatThrownBy(() -> asyncEventQueueFactory.create("id", null)) .isInstanceOf(IllegalArgumentException.class); } }
public static void createAsyncEventQueue(String asyncChannelId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isConflation, boolean isPersistent, String diskStoreName, boolean isDiskSynchronous, String asyncListenerClass, String substitutionFilterClass) throws Exception { createDiskStore(asyncChannelId, diskStoreName); AsyncEventQueueFactory factory = getInitialAsyncEventQueueFactory(isParallel, maxMemory, batchSize, isPersistent, diskStoreName); factory.setDiskSynchronous(isDiskSynchronous); factory.setBatchConflationEnabled(isConflation); if (substitutionFilterClass != null) { factory.setGatewayEventSubstitutionListener( (GatewayEventSubstitutionFilter) getClass(substitutionFilterClass).newInstance()); } // set dispatcher threads factory.setDispatcherThreads(numDispatcherThreadsForTheRun); AsyncEventQueue asyncChannel = factory.create(asyncChannelId, (AsyncEventListener) getClass(asyncListenerClass).newInstance()); }
@Override protected void doInit() { Assert.state(this.asyncEventListener != null, "AsyncEventListener must not be null"); AsyncEventQueueFactory asyncEventQueueFactory = this.factory != null ? (AsyncEventQueueFactory) this.factory : this.cache.createAsyncEventQueueFactory(); Optional.ofNullable(this.batchConflationEnabled).ifPresent(asyncEventQueueFactory::setBatchConflationEnabled); Optional.ofNullable(this.batchSize).ifPresent(asyncEventQueueFactory::setBatchSize); Optional.ofNullable(this.batchTimeInterval).ifPresent(asyncEventQueueFactory::setBatchTimeInterval); Optional.ofNullable(this.diskStoreReference).ifPresent(asyncEventQueueFactory::setDiskStoreName); Optional.ofNullable(this.diskSynchronous).ifPresent(asyncEventQueueFactory::setDiskSynchronous); Optional.ofNullable(this.dispatcherThreads).ifPresent(asyncEventQueueFactory::setDispatcherThreads); Optional.ofNullable(this.forwardExpirationDestroy).ifPresent(asyncEventQueueFactory::setForwardExpirationDestroy); Optional.ofNullable(this.gatewayEventSubstitutionFilter).ifPresent(asyncEventQueueFactory::setGatewayEventSubstitutionListener); Optional.ofNullable(this.maximumQueueMemory).ifPresent(asyncEventQueueFactory::setMaximumQueueMemory); Optional.ofNullable(this.persistent).ifPresent(asyncEventQueueFactory::setPersistent); asyncEventQueueFactory.setParallel(isParallelEventQueue()); nullSafeList(this.gatewayEventFilters).forEach(asyncEventQueueFactory::addGatewayEventFilter); if (this.orderPolicy != null) { Assert.state(isSerialEventQueue(), "OrderPolicy cannot be used with a Parallel AsyncEventQueue"); asyncEventQueueFactory.setOrderPolicy(this.orderPolicy); } setAsyncEventQueue(asyncEventQueueFactory.create(getName(), this.asyncEventListener)); }
@Test public void executeCreatesParallelAsyncQueueForPartitionedRegion() throws Exception { when(attributes.getDataPolicy()).thenReturn(DataPolicy.PARTITION); function.executeFunction(context); verify(asyncEventQueueFactory, times(1)).create(any(), any()); verify(asyncEventQueueFactory, times(1)).setParallel(true); }
public static void createAsyncEventQueueWithCustomListener(String asyncChannelId, boolean isParallel, Integer maxMemory, Integer batchSize, boolean isConflation, boolean isPersistent, String diskStoreName, boolean isDiskSynchronous, int nDispatchers) { IgnoredException exp = IgnoredException.addIgnoredException(ForceReattemptException.class.getName()); try { createDiskStore(asyncChannelId, diskStoreName); AsyncEventListener asyncEventListener = new CustomAsyncEventListener(); AsyncEventQueueFactory factory = getInitialAsyncEventQueueFactory(isParallel, maxMemory, batchSize, isPersistent, diskStoreName); factory.setDispatcherThreads(nDispatchers); AsyncEventQueue asyncChannel = factory.create(asyncChannelId, asyncEventListener); } finally { exp.remove(); } }
@Test public void executeWithSynchronousNeverCreatesAsyncQueue() throws Exception { setupSynchronous(); function.executeFunction(context); verify(asyncEventQueueFactory, never()).create(any(), any()); }
cache.createAsyncEventQueueFactory().setParallel(config.isParallel()) .setBatchConflationEnabled(config.isEnableBatchConflation()) .setBatchSize(Integer.parseInt(config.getBatchSize())) .setBatchTimeInterval(Integer.parseInt(config.getBatchTimeInterval())) .setPersistent(config.isPersistent()).setDiskStoreName(config.getDiskStoreName()) .setDiskSynchronous(config.isDiskSynchronous()) .setForwardExpirationDestroy(config.isForwardExpirationDestroy()) .setMaximumQueueMemory(Integer.parseInt(config.getMaximumQueueMemory())) .setDispatcherThreads(Integer.parseInt(config.getDispatcherThreads())) .setOrderPolicy(OrderPolicy.valueOf(config.getOrderPolicy())); for (String gatewayEventFilter : gatewayEventFilters) { asyncEventQueueFactory .addGatewayEventFilter((GatewayEventFilter) newInstance(gatewayEventFilter)); asyncEventQueueFactory.setGatewayEventSubstitutionListener( (GatewayEventSubstitutionFilter<?, ?>) newInstance(gatewaySubstitutionFilter)); asyncEventQueueFactory.create(config.getId(), (AsyncEventListener) listenerInstance);
@Test public void executeCreatesSerialAsyncQueueForNonPartitionedRegion() throws Exception { when(attributes.getDataPolicy()).thenReturn(DataPolicy.REPLICATE); function.executeFunction(context); verify(asyncEventQueueFactory, times(1)).create(any(), any()); verify(asyncEventQueueFactory, times(1)).setParallel(false); }
when(mockAsyncEventQueueFactory.setBatchConflationEnabled(anyBoolean())) .thenAnswer(newSetter(batchConflationEnabled, mockAsyncEventQueueFactory)); when(mockAsyncEventQueueFactory.setBatchSize(anyInt())) .thenAnswer(newSetter(batchSize, mockAsyncEventQueueFactory)); when(mockAsyncEventQueueFactory.setBatchTimeInterval(anyInt())) .thenAnswer(newSetter(batchTimeInterval, mockAsyncEventQueueFactory)); when(mockAsyncEventQueueFactory.setDiskStoreName(anyString())) .thenAnswer(newSetter(diskStoreName, mockAsyncEventQueueFactory)); when(mockAsyncEventQueueFactory.setDiskSynchronous(anyBoolean())) .thenAnswer(newSetter(diskSynchronous, mockAsyncEventQueueFactory)); when(mockAsyncEventQueueFactory.setDispatcherThreads(anyInt())) .thenAnswer(newSetter(dispatcherThreads, mockAsyncEventQueueFactory)); when(mockAsyncEventQueueFactory.setForwardExpirationDestroy(anyBoolean())) .thenAnswer(newSetter(forwardExpirationDestroy, mockAsyncEventQueueFactory)); when(mockAsyncEventQueueFactory.setGatewayEventSubstitutionListener(any(GatewayEventSubstitutionFilter.class))) .thenAnswer(newSetter(gatewayEventSubstitutionFilter, mockAsyncEventQueueFactory)); when(mockAsyncEventQueueFactory.setMaximumQueueMemory(anyInt())) .thenAnswer(newSetter(maximumQueueMemory, mockAsyncEventQueueFactory)); when(mockAsyncEventQueueFactory.setOrderPolicy(any(GatewaySender.OrderPolicy.class))) .thenAnswer(newSetter(orderPolicy, mockAsyncEventQueueFactory));