use of org.apache.geode.cache.asyncqueue.AsyncEventListener in project geode by apache.
the class SerialGatewaySenderImpl method stop.
@Override
public void stop() {
if (logger.isDebugEnabled()) {
logger.debug("Stopping Gateway Sender : {}", this);
}
this.getLifeCycleLock().writeLock().lock();
try {
// 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();
}
logger.info(LocalizedMessage.create(LocalizedStrings.GatewayImpl_STOPPED__0, this));
clearTempEventsAfterSenderStopped();
} finally {
this.getLifeCycleLock().writeLock().unlock();
}
if (this.isPrimary()) {
try {
DistributedLockService.destroy(getSenderAdvisor().getDLockServiceName());
} catch (IllegalArgumentException e) {
// service not found... ignore
}
}
Set<RegionQueue> queues = getQueues();
if (queues != null && !queues.isEmpty()) {
for (RegionQueue q : queues) {
((SerialGatewaySenderQueue) q).cleanUp();
}
}
this.setIsPrimary(false);
new UpdateAttributesProcessor(this).distribute(false);
Thread lockObtainingThread = getSenderAdvisor().getLockObtainingThread();
if (lockObtainingThread != null && lockObtainingThread.isAlive()) {
// wait a while for thread to terminate
try {
lockObtainingThread.join(3000);
} catch (InterruptedException ex) {
// we allowed our join to be canceled
// reset interrupt bit so this thread knows it has been interrupted
Thread.currentThread().interrupt();
}
if (lockObtainingThread.isAlive()) {
logger.info(LocalizedMessage.create(LocalizedStrings.GatewaySender_COULD_NOT_STOP_LOCK_OBTAINING_THREAD_DURING_GATEWAY_SENDER_STOP));
}
}
InternalDistributedSystem system = (InternalDistributedSystem) this.cache.getDistributedSystem();
system.handleResourceEvent(ResourceEvent.GATEWAYSENDER_STOP, this);
this.eventProcessor = null;
}
use of org.apache.geode.cache.asyncqueue.AsyncEventListener in project geode by apache.
the class CacheXml70GatewayDUnitTest 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);
factory.addGatewayEventFilter(new MyGatewayEventFilter());
AsyncEventListener eventListener = new CacheXml70DUnitTest.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);
}
}
use of org.apache.geode.cache.asyncqueue.AsyncEventListener in project geode by apache.
the class ParallelGatewaySenderImpl method fillInProfile.
public void fillInProfile(Profile profile) {
assert profile instanceof GatewaySenderProfile;
GatewaySenderProfile pf = (GatewaySenderProfile) profile;
pf.Id = getId();
pf.remoteDSId = getRemoteDSId();
pf.isRunning = isRunning();
pf.isPrimary = isPrimary();
pf.isParallel = true;
pf.isBatchConflationEnabled = isBatchConflationEnabled();
pf.isPersistenceEnabled = isPersistenceEnabled();
pf.alertThreshold = getAlertThreshold();
pf.manualStart = isManualStart();
pf.dispatcherThreads = getDispatcherThreads();
pf.orderPolicy = getOrderPolicy();
for (GatewayEventFilter filter : getGatewayEventFilters()) {
pf.eventFiltersClassNames.add(filter.getClass().getName());
}
for (GatewayTransportFilter filter : getGatewayTransportFilters()) {
pf.transFiltersClassNames.add(filter.getClass().getName());
}
for (AsyncEventListener listener : getAsyncEventListeners()) {
pf.senderEventListenerClassNames.add(listener.getClass().getName());
}
pf.isDiskSynchronous = isDiskSynchronous();
}
use of org.apache.geode.cache.asyncqueue.AsyncEventListener in project geode by apache.
the class WANConfigurationJUnitTest method test_GatewaySenderWithGatewaySenderEventListener2.
@Test
public void test_GatewaySenderWithGatewaySenderEventListener2() {
cache = new CacheFactory().set(MCAST_PORT, "0").create();
GatewaySenderFactory fact = cache.createGatewaySenderFactory();
AsyncEventListener listener = new MyGatewaySenderEventListener();
((InternalGatewaySenderFactory) fact).addAsyncEventListener(listener);
try {
((InternalGatewaySenderFactory) fact).create("ln");
} catch (Exception e) {
fail("Received Exception :" + e);
}
}
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);
}
}
Aggregations