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;
}
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);
}
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();
}
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);
}
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));
}
}
Aggregations