use of org.apache.geode.cache.asyncqueue.AsyncEventListener in project geode by apache.
the class SerialGatewaySenderEventListenerDUnitTest method validateReceivedEventsMapSizeListener1.
public static void validateReceivedEventsMapSizeListener1(final String senderId, final Map map) {
Set<GatewaySender> senders = cache.getGatewaySenders();
GatewaySender sender = null;
for (GatewaySender s : senders) {
if (s.getId().equals(senderId)) {
sender = s;
break;
}
}
final List<AsyncEventListener> listeners = ((AbstractGatewaySender) sender).getAsyncEventListeners();
if (listeners.size() == 1) {
final AsyncEventListener l = listeners.get(0);
WaitCriterion wc = new WaitCriterion() {
Map listenerMap;
public boolean done() {
listenerMap = ((MyGatewaySenderEventListener) l).getEventsMap();
boolean sizeCorrect = map.size() == listenerMap.size();
boolean keySetCorrect = listenerMap.keySet().containsAll(map.keySet());
boolean valuesCorrect = listenerMap.values().containsAll(map.values());
return sizeCorrect && keySetCorrect && valuesCorrect;
}
public String description() {
return "Waiting for all sites to get updated, the sizes are " + listenerMap.size() + " and " + map.size();
}
};
Wait.waitForCriterion(wc, 60000, 500, true);
}
}
use of org.apache.geode.cache.asyncqueue.AsyncEventListener 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);
}
}
use of org.apache.geode.cache.asyncqueue.AsyncEventListener in project geode by apache.
the class ParallelAsyncEventQueueImpl method stop.
@Override
public void stop() {
this.getLifeCycleLock().writeLock().lock();
try {
if (!this.isRunning()) {
return;
}
// Stop the dispatcher
AbstractGatewaySenderEventProcessor ev = this.eventProcessor;
if (ev != null && !ev.isStopped()) {
ev.stopProcessing();
}
// Stop the proxy (after the dispatcher, so the socket is still
// alive until after the dispatcher has stopped)
stompProxyDead();
// Close the listeners
for (AsyncEventListener listener : this.listeners) {
listener.close();
}
// stop the running threads, open sockets if any
((ConcurrentParallelGatewaySenderQueue) this.eventProcessor.getQueue()).cleanUp();
logger.info(LocalizedMessage.create(LocalizedStrings.GatewayImpl_STOPPED__0, this));
InternalDistributedSystem system = (InternalDistributedSystem) this.cache.getDistributedSystem();
system.handleResourceEvent(ResourceEvent.GATEWAYSENDER_STOP, this);
clearTempEventsAfterSenderStopped();
} finally {
this.getLifeCycleLock().writeLock().unlock();
}
}
use of org.apache.geode.cache.asyncqueue.AsyncEventListener in project geode by apache.
the class GatewaySenderAdvisor method checkCompatibility.
private void checkCompatibility(GatewaySenderProfile sp) {
if (sp.remoteDSId != sender.getRemoteDSId()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_REMOTE_DS_ID_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_2_REMOTE_DS_ID.toString(new Object[] { sp.Id, sp.remoteDSId, sender.remoteDSId }));
}
if (sp.isParallel && !sender.isParallel()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_AS_PARALLEL_GATEWAY_SENDER_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_AS_SERIAL_GATEWAY_SENDER.toString(new Object[] { sp.Id }));
}
if (!sp.isParallel && sender.isParallel()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_AS_SERIAL_GATEWAY_SENDER_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_AS_PARALLEL_GATEWAY_SENDER.toString(new Object[] { sp.Id }));
}
if (sp.isBatchConflationEnabled != sender.isBatchConflationEnabled()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_IS_BACTH_CONFLATION_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_IS_BATCH_CONFLATION_2.toString(new Object[] { sp.Id, sp.isBatchConflationEnabled, sender.isBatchConflationEnabled() }));
}
if (sp.isPersistenceEnabled != sender.isPersistenceEnabled()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_IS_PERSISTENT_ENABLED_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_IS_PERSISTENT_ENABLED_2.toString(new Object[] { sp.Id, sp.isPersistenceEnabled, sender.isPersistenceEnabled() }));
}
if (sp.alertThreshold != sender.getAlertThreshold()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_ALERT_THRESHOLD_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_ALERT_THRESHOLD_2.toString(new Object[] { sp.Id, sp.alertThreshold, sender.getAlertThreshold() }));
}
if (!sender.isParallel()) {
if (sp.manualStart != sender.isManualStart()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_MANUAL_START_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_MANUAL_START_2.toString(new Object[] { sp.Id, sp.manualStart, sender.isManualStart() }));
}
}
if (!sp.isParallel) {
if (sp.orderPolicy != sender.getOrderPolicy()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_CANNOT_CREATE_GATEWAYSENDER_0_WITH_ORDER_POLICY_1_BECAUSE_ANOTHER_CACHE_HAS_THE_SAME_SENDER_WITH_ORDER_POLICY_2.toString(new Object[] { sp.Id, sp.orderPolicy, sender.getOrderPolicy() }));
}
}
List<String> senderEventFilterClassNames = new ArrayList<String>();
for (org.apache.geode.cache.wan.GatewayEventFilter filter : sender.getGatewayEventFilters()) {
senderEventFilterClassNames.add(filter.getClass().getName());
}
if (sp.eventFiltersClassNames.size() != senderEventFilterClassNames.size()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_EVENT_FILTERS_MISMATCH.toString(new Object[] { sp.Id, sp.eventFiltersClassNames, senderEventFilterClassNames }));
} else {
for (String filterName : senderEventFilterClassNames) {
if (!sp.eventFiltersClassNames.contains(filterName)) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_EVENT_FILTERS_MISMATCH.toString(new Object[] { sp.Id, sp.eventFiltersClassNames, senderEventFilterClassNames }));
}
}
}
Set<String> senderTransportFilterClassNames = new LinkedHashSet<String>();
for (GatewayTransportFilter filter : sender.getGatewayTransportFilters()) {
senderTransportFilterClassNames.add(filter.getClass().getName());
}
if (sp.transFiltersClassNames.size() != senderTransportFilterClassNames.size()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_TRANSPORT_FILTERS_MISMATCH.toString(new Object[] { sp.Id, sp.transFiltersClassNames, senderTransportFilterClassNames }));
} else {
Iterator<String> i1 = sp.transFiltersClassNames.iterator();
Iterator<String> i2 = senderTransportFilterClassNames.iterator();
while (i1.hasNext() && i2.hasNext()) {
if (!i1.next().equals(i2.next())) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_TRANSPORT_FILTERS_MISMATCH.toString(new Object[] { sp.Id, sp.transFiltersClassNames, senderTransportFilterClassNames }));
}
}
}
List<String> senderEventListenerClassNames = new ArrayList<String>();
for (AsyncEventListener listener : sender.getAsyncEventListeners()) {
senderEventListenerClassNames.add(listener.getClass().getName());
}
if (sp.senderEventListenerClassNames.size() != senderEventListenerClassNames.size()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_SENDER_LISTENER_MISMATCH.toString(new Object[] { sp.Id, sp.senderEventListenerClassNames, senderEventListenerClassNames }));
} else {
for (String listenerName : senderEventListenerClassNames) {
if (!sp.senderEventListenerClassNames.contains(listenerName)) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_SENDER_LISTENER_MISMATCH.toString(new Object[] { sp.Id, sp.senderEventListenerClassNames, senderEventListenerClassNames }));
}
}
}
if (sp.isDiskSynchronous != sender.isDiskSynchronous()) {
throw new IllegalStateException(LocalizedStrings.GatewaySenderAdvisor_GATEWAY_SENDER_IS_DISK_SYNCHRONOUS_MISMATCH.toString(new Object[] { sp.Id, sp.isDiskSynchronous, sender.isDiskSynchronous() }));
}
}
use of org.apache.geode.cache.asyncqueue.AsyncEventListener in project geode by apache.
the class GatewaySenderEventCallbackDispatcher method dispatchBatch.
/**
* Sends a batch of messages to the registered <code>AsyncEventListener</code>s.
*
* @param events The <code>List</code> of events to send
*
* @throws GatewaySenderException
*/
protected boolean dispatchBatch(List events) throws GatewaySenderException {
if (events.isEmpty()) {
return true;
}
int batchId = this.eventProcessor.getBatchId();
boolean successAll = true;
try {
for (AsyncEventListener listener : this.eventListeners) {
boolean successOne = listener.processEvents(events);
if (!successOne) {
successAll = false;
}
}
} catch (Exception e) {
final StringId alias = LocalizedStrings.SerialGatewayEventCallbackDispatcher__0___EXCEPTION_DURING_PROCESSING_BATCH__1_;
final Object[] aliasArgs = new Object[] { this, Integer.valueOf(batchId) };
String exMsg = alias.toLocalizedString(aliasArgs);
GatewaySenderException ge = new GatewaySenderException(exMsg, e);
logger.warn(LocalizedMessage.create(alias, aliasArgs), ge);
throw ge;
}
return successAll;
}
Aggregations