use of org.apache.geode.cache.CacheListener in project geode by apache.
the class SerialGatewaySenderQueue method removeCacheListener.
@SuppressWarnings("rawtypes")
public void removeCacheListener() {
AttributesMutator mutator = this.region.getAttributesMutator();
CacheListener[] listeners = this.region.getAttributes().getCacheListeners();
for (int i = 0; i < listeners.length; i++) {
if (listeners[i] instanceof SerialSecondaryGatewayListener) {
mutator.removeCacheListener(listeners[i]);
break;
}
}
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class PartitionedRegion method postCreateRegion.
@Override
protected void postCreateRegion() {
super.postCreateRegion();
CacheListener[] listeners = fetchCacheListenersField();
if (listeners != null && listeners.length > 0) {
Set others = getRegionAdvisor().adviseGeneric();
for (int i = 0; i < listeners.length; i++) {
if (listeners[i] instanceof RegionMembershipListener) {
RegionMembershipListener rml = (RegionMembershipListener) listeners[i];
try {
DistributedMember[] otherDms = new DistributedMember[others.size()];
others.toArray(otherDms);
rml.initialMembers(this, otherDms);
} catch (VirtualMachineError err) {
SystemFailure.initiateFailure(err);
// now, so don't let this thread continue.
throw err;
} catch (Throwable t) {
// Whenever you catch Error or Throwable, you must also
// catch VirtualMachineError (see above). However, there is
// _still_ a possibility that you are dealing with a cascading
// error condition, so you also need to check to see if the JVM
// is still usable:
SystemFailure.checkFailure();
logger.error(LocalizedMessage.create(LocalizedStrings.DistributedRegion_EXCEPTION_OCCURRED_IN_REGIONMEMBERSHIPLISTENER), t);
}
}
}
}
PartitionListener[] partitionListeners = this.getPartitionListeners();
if (partitionListeners != null && partitionListeners.length != 0) {
for (int i = 0; i < partitionListeners.length; i++) {
PartitionListener listener = partitionListeners[i];
if (listener != null) {
listener.afterRegionCreate(this);
}
}
}
Set<String> allGatewaySenderIds = getAllGatewaySenderIds();
if (!allGatewaySenderIds.isEmpty()) {
for (GatewaySender sender : cache.getAllGatewaySenders()) {
if (sender.isParallel() && allGatewaySenderIds.contains(sender.getId())) {
/*
* get the ParallelGatewaySender to create the colocated partitioned region for this
* region.
*/
if (sender.isRunning()) {
AbstractGatewaySender senderImpl = (AbstractGatewaySender) sender;
((ConcurrentParallelGatewaySenderQueue) senderImpl.getQueues().toArray(new RegionQueue[1])[0]).addShadowPartitionedRegionForUserPR(this);
}
}
}
}
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class Bug34387DUnitTest method testCreateAndLI.
/**
* test create followed by localInvalidate
*/
@Test
public void testCreateAndLI() throws CacheException {
initOtherId();
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
af.setScope(Scope.DISTRIBUTED_ACK);
af.setConcurrencyChecksEnabled(true);
callbackFailure = false;
CacheListener cl1 = new CacheListenerAdapter() {
public void afterCreate(EntryEvent e) {
callbackAssertEquals("key not equal", "createKey", e.getKey());
callbackAssertEquals("value not equal", "createValue", e.getNewValue());
Bug34387DUnitTest.this.invokeCount++;
}
};
af.addCacheListener(cl1);
Region r1 = createRootRegion("r1", af.create());
this.invokeCount = 0;
assertNull(r1.getEntry("createKey"));
doCommitOtherVm(false);
assertNotNull(r1.getEntry("createKey"));
assertEquals("createValue", r1.getEntry("createKey").getValue());
assertEquals(1, this.invokeCount);
assertFalse("Errors in callbacks; check logs for details", callbackFailure);
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class Bug38013DUnitTest method doCreateOtherVm.
private void doCreateOtherVm() {
VM vm = getOtherVm();
vm.invoke(new CacheSerializableRunnable("create root") {
public void run2() throws CacheException {
getSystem();
AttributesFactory af = new AttributesFactory();
CacheListener cl = new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
// getLogWriter().info("afterCreate " + event.getKey());
if (event.getCallbackArgument() != null) {
lastCallback = event.getCallbackArgument();
}
}
public void afterUpdate(EntryEvent event) {
// getLogWriter().info("afterUpdate " + event.getKey());
if (event.getCallbackArgument() != null) {
lastCallback = event.getCallbackArgument();
}
}
public void afterInvalidate(EntryEvent event) {
if (event.getCallbackArgument() != null) {
lastCallback = event.getCallbackArgument();
}
}
public void afterDestroy(EntryEvent event) {
if (event.getCallbackArgument() != null) {
lastCallback = event.getCallbackArgument();
}
}
};
af.setCacheListener(cl);
// create a pr with a data store
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(0);
// use defaults so this is a data store
af.setPartitionAttributes(paf.create());
createRootRegion("bug38013", af.create());
}
});
}
use of org.apache.geode.cache.CacheListener in project geode by apache.
the class Bug34387DUnitTest method testCreateAndLD.
////////////////////// Test Methods //////////////////////
/**
* test create followed by localDestroy
*/
@Test
public void testCreateAndLD() throws CacheException {
initOtherId();
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
af.setScope(Scope.DISTRIBUTED_ACK);
af.setConcurrencyChecksEnabled(true);
callbackFailure = false;
CacheListener cl1 = new CacheListenerAdapter() {
public void afterCreate(EntryEvent e) {
callbackAssertEquals("Keys not equal", "createKey", e.getKey());
callbackAssertEquals("Values not equal", "createValue", e.getNewValue());
Bug34387DUnitTest.this.invokeCount++;
}
};
af.addCacheListener(cl1);
Region r1 = createRootRegion("r1", af.create());
this.invokeCount = 0;
assertNull(r1.getEntry("createKey"));
doCommitOtherVm(true);
assertNotNull(r1.getEntry("createKey"));
assertEquals("createValue", r1.getEntry("createKey").getValue());
assertEquals(1, this.invokeCount);
assertFalse("Errors in callbacks; check logs for details", callbackFailure);
}
Aggregations