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();
}
}
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;
}
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);
}
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;
}
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;
}
Aggregations