Search in sources :

Example 36 with CacheListener

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;
        }
    }
}
Also used : CacheListener(org.apache.geode.cache.CacheListener) AttributesMutator(org.apache.geode.cache.AttributesMutator)

Example 37 with CacheListener

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);
                }
            }
        }
    }
}
Also used : AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) GatewaySender(org.apache.geode.cache.wan.GatewaySender) HashSet(java.util.HashSet) Set(java.util.Set) ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) RegionMembershipListener(org.apache.geode.cache.RegionMembershipListener) CacheListener(org.apache.geode.cache.CacheListener) PartitionListener(org.apache.geode.cache.partition.PartitionListener) ConcurrentParallelGatewaySenderQueue(org.apache.geode.internal.cache.wan.parallel.ConcurrentParallelGatewaySenderQueue) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender)

Example 38 with CacheListener

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);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) Region(org.apache.geode.cache.Region) CacheListener(org.apache.geode.cache.CacheListener) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 39 with CacheListener

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());
        }
    });
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) EntryEvent(org.apache.geode.cache.EntryEvent) CacheListener(org.apache.geode.cache.CacheListener)

Example 40 with CacheListener

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);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) EntryEvent(org.apache.geode.cache.EntryEvent) Region(org.apache.geode.cache.Region) CacheListener(org.apache.geode.cache.CacheListener) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

CacheListener (org.apache.geode.cache.CacheListener)55 AttributesFactory (org.apache.geode.cache.AttributesFactory)28 Region (org.apache.geode.cache.Region)24 RegionAttributes (org.apache.geode.cache.RegionAttributes)17 EntryEvent (org.apache.geode.cache.EntryEvent)13 Test (org.junit.Test)13 CacheException (org.apache.geode.cache.CacheException)12 Properties (java.util.Properties)11 CacheListenerAdapter (org.apache.geode.cache.util.CacheListenerAdapter)11 VM (org.apache.geode.test.dunit.VM)11 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)11 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)8 CacheWriter (org.apache.geode.cache.CacheWriter)7 AttributesMutator (org.apache.geode.cache.AttributesMutator)6 Host (org.apache.geode.test.dunit.Host)6 Iterator (java.util.Iterator)5 CacheTransactionManager (org.apache.geode.cache.CacheTransactionManager)5 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)5 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)5 CacheLoader (org.apache.geode.cache.CacheLoader)4