Search in sources :

Example 16 with CacheWriter

use of org.apache.geode.cache.CacheWriter in project geode by apache.

the class PutAllGlobalDUnitTest method createCacheForVM1.

public static void createCacheForVM1() {
    try {
        CacheWriter aWriter = new BeforeCreateCallback();
        ds = (new PutAllGlobalDUnitTest()).getSystem(props);
        cache = CacheFactory.create(ds);
        cache.setLockTimeout(TIMEOUT_PERIOD / 1000);
        AttributesFactory factory = new AttributesFactory();
        factory.setScope(Scope.GLOBAL);
        factory.setCacheWriter(aWriter);
        RegionAttributes attr = factory.create();
        region = cache.createRegion("map", attr);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheWriter(org.apache.geode.cache.CacheWriter) TimeoutException(org.apache.geode.cache.TimeoutException) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 17 with CacheWriter

use of org.apache.geode.cache.CacheWriter in project geode by apache.

the class AbstractRegion method setCacheWriter.

@Override
public synchronized CacheWriter setCacheWriter(CacheWriter cacheWriter) {
    checkReadiness();
    CacheWriter oldWriter = this.cacheWriter;
    assignCacheWriter(cacheWriter);
    cacheWriterChanged(oldWriter);
    return oldWriter;
}
Also used : CacheWriter(org.apache.geode.cache.CacheWriter)

Example 18 with CacheWriter

use of org.apache.geode.cache.CacheWriter in project geode by apache.

the class CacheXmlParser method endCacheWriter.

/**
   * When a <code>cache-writer</code> element is finished, the {@link Parameter}s and class names
   * are popped off the stack. The cache writer is instantiated and initialized with the parameters,
   * if appropriate.
   * <p>
   * A cache-writer may be created in the context of region-attributes or dynamic-region-factory. In
   * the latter case, there may be a disk-dir on top of the stack, represented by a File object.
   */
private void endCacheWriter() {
    Declarable d = createDeclarable();
    if (!(d instanceof CacheWriter)) {
        throw new CacheXmlException(LocalizedStrings.CacheXmlParser_A_0_IS_NOT_AN_INSTANCE_OF_A_CACHEWRITER.toLocalizedString(d.getClass().getName()));
    }
    Object a = stack.peek();
    // check for disk-dir
    if ((a instanceof File)) {
        Object sav = stack.pop();
        // pop out disk size
        Object size = stack.pop();
        a = stack.peek();
        //
        if (!(a instanceof RegionAttributesCreation)) {
            throw new CacheXmlException(LocalizedStrings.CacheXmlParser_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_1.toLocalizedString(new Object[] { CACHE_WRITER, DYNAMIC_REGION_FACTORY }));
        }
        stack.push(size);
        stack.push(sav);
    } else // check for normal region-attributes
    if (!(a instanceof RegionAttributesCreation)) {
        throw new CacheXmlException(LocalizedStrings.CacheXmlParser_0_MUST_BE_DEFINED_IN_THE_CONTEXT_OF_REGIONATTRIBUTES.toLocalizedString(CACHE_WRITER));
    }
    RegionAttributesCreation attrs = (RegionAttributesCreation) a;
    attrs.setCacheWriter((CacheWriter) d);
}
Also used : Declarable(org.apache.geode.cache.Declarable) CacheXmlException(org.apache.geode.cache.CacheXmlException) CacheWriter(org.apache.geode.cache.CacheWriter) File(java.io.File)

Example 19 with CacheWriter

use of org.apache.geode.cache.CacheWriter in project geode by apache.

the class PartitionedRegion method cacheWriteBeforeRegionDestroy.

/**
   * This invokes a cache writer before a destroy operation. Although it has the same method
   * signature as the method in LocalRegion, it is invoked in a different code path. LocalRegion
   * invokes this method via its "entries" member, while PartitionedRegion invokes this method in
   * its region operation methods and messages.
   */
@Override
boolean cacheWriteBeforeRegionDestroy(RegionEventImpl event) throws CacheWriterException, TimeoutException {
    if (event.getOperation().isDistributed()) {
        serverRegionDestroy(event);
        CacheWriter localWriter = basicGetWriter();
        Set netWriteRecipients = localWriter == null ? this.distAdvisor.adviseNetWrite() : null;
        if (localWriter == null && (netWriteRecipients == null || netWriteRecipients.isEmpty())) {
            return false;
        }
        final long start = getCachePerfStats().startCacheWriterCall();
        try {
            SearchLoadAndWriteProcessor processor = SearchLoadAndWriteProcessor.getProcessor();
            processor.initialize(this, "preDestroyRegion", null);
            processor.doNetWrite(event, netWriteRecipients, localWriter, SearchLoadAndWriteProcessor.BEFOREREGIONDESTROY);
            processor.release();
        } finally {
            getCachePerfStats().endCacheWriterCall(start);
        }
        return true;
    }
    return false;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ResultsSet(org.apache.geode.cache.query.internal.ResultsSet) CacheWriter(org.apache.geode.cache.CacheWriter)

Example 20 with CacheWriter

use of org.apache.geode.cache.CacheWriter in project geode by apache.

the class ProxyRegionMap method basicPut.

public RegionEntry basicPut(EntryEventImpl event, long lastModified, boolean ifNew, boolean ifOld, Object expectedOldValue, boolean requireOldValue, boolean overwriteDestroyed) throws CacheWriterException, TimeoutException {
    if (!event.isOriginRemote() && event.getOperation() != Operation.REPLACE) {
        // bug 42167 - don't
        // convert replace
        // to CREATE
        event.makeCreate();
    }
    final CacheWriter cacheWriter = this.owner.basicGetWriter();
    final boolean cacheWrite = !event.isOriginRemote() && !event.isNetSearch() && !event.getInhibitDistribution() && event.isGenerateCallbacks() && (cacheWriter != null || this.owner.hasServerProxy() || this.owner.scope.isDistributed());
    if (cacheWrite) {
        final Set netWriteRecipients;
        if (cacheWriter == null && this.owner.scope.isDistributed()) {
            CacheDistributionAdvisor cda = ((DistributedRegion) this.owner).getDistributionAdvisor();
            netWriteRecipients = cda.adviseNetWrite();
        } else {
            netWriteRecipients = null;
        }
        if (event.getOperation() != Operation.REPLACE) {
            // bug #42167 - makeCreate() causes REPLACE
            // to eventually become UPDATE
            event.makeCreate();
        }
        this.owner.cacheWriteBeforePut(event, netWriteRecipients, cacheWriter, requireOldValue, expectedOldValue);
    }
    owner.recordEvent(event);
    // fix for bug 40129
    lastModified = this.owner.basicPutPart2(event, markerEntry, true, lastModified, false);
    this.owner.basicPutPart3(event, markerEntry, true, lastModified, true, ifNew, ifOld, expectedOldValue, requireOldValue);
    return markerEntry;
}
Also used : Set(java.util.Set) CacheWriter(org.apache.geode.cache.CacheWriter)

Aggregations

CacheWriter (org.apache.geode.cache.CacheWriter)31 AttributesFactory (org.apache.geode.cache.AttributesFactory)16 CacheException (org.apache.geode.cache.CacheException)12 RegionAttributes (org.apache.geode.cache.RegionAttributes)9 CacheListener (org.apache.geode.cache.CacheListener)7 Test (org.junit.Test)7 Set (java.util.Set)6 CacheWriterException (org.apache.geode.cache.CacheWriterException)6 EntryEvent (org.apache.geode.cache.EntryEvent)6 TimeoutException (org.apache.geode.cache.TimeoutException)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 HashSet (java.util.HashSet)5 RegionEvent (org.apache.geode.cache.RegionEvent)5 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)5 CacheLoader (org.apache.geode.cache.CacheLoader)4 Region (org.apache.geode.cache.Region)4 HashMap (java.util.HashMap)3 Map (java.util.Map)3 AttributesMutator (org.apache.geode.cache.AttributesMutator)3 CacheLoaderException (org.apache.geode.cache.CacheLoaderException)3