use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class SearchLoadAndWriteProcessor method netWrite.
/** Return true if cache writer was invoked */
private boolean netWrite(CacheEvent event, int action, Set writeCandidateSet) throws CacheWriterException, TimeoutException {
if (writeCandidateSet == null || writeCandidateSet.isEmpty()) {
return false;
}
ArrayList list = new ArrayList(writeCandidateSet);
Collections.shuffle(list);
InternalDistributedMember[] writeCandidates = (InternalDistributedMember[]) list.toArray(new InternalDistributedMember[list.size()]);
initRemainingTimeout();
int index = 0;
do {
InternalDistributedMember next = writeCandidates[index++];
Set set = new HashSet();
set.add(next);
this.netWriteSucceeded = false;
this.requestInProgress = true;
this.remoteException = null;
NetWriteRequestMessage.sendMessage(this, this.regionName, this.remainingTimeout, event, set, action);
if (this.remainingTimeout <= 0) {
// @todo: should this throw a timeout exception?
break;
}
waitForObject2(this.remainingTimeout);
if (this.netWriteSucceeded) {
this.netWrite = true;
break;
}
if (this.remoteException != null) {
Throwable cause;
if (this.remoteException instanceof TryAgainException) {
if (index < writeCandidates.length) {
continue;
} else {
break;
}
}
if (this.remoteException instanceof CacheWriterException && this.remoteException.getCause() != null) {
cause = this.remoteException.getCause();
} else {
cause = this.remoteException;
}
throw new CacheWriterException(LocalizedStrings.SearchLoadAndWriteProcessor_WHILE_INVOKING_A_REMOTE_NETWRITE_0.toLocalizedString(cause), cause);
}
} while (index < writeCandidates.length);
return this.netWriteSucceeded;
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class SearchAndLoadDUnitTest method testOneHopNetWrite.
@Test
public void testOneHopNetWrite() throws CacheException, InterruptedException {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final String name = this.getUniqueName() + "Region";
final String objectName = "Object7";
final Integer value = new Integer(483);
final Integer updateValue = new Integer(484);
vm0.invoke(new SerializableRunnable("Create replicated region with cacheWriter") {
public void run() {
netWriteInvoked = false;
operationWasCreate = false;
originWasRemote = false;
writerInvocationCount = 0;
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
factory.setCacheWriter(new CacheWriter() {
public void beforeCreate(EntryEvent e) throws CacheWriterException {
e.getRegion().getCache().getLogger().info("cache writer beforeCreate invoked for " + e);
netWriteInvoked = true;
operationWasCreate = true;
originWasRemote = e.isOriginRemote();
writerInvocationCount++;
return;
}
public void beforeUpdate(EntryEvent e) throws CacheWriterException {
e.getRegion().getCache().getLogger().info("cache writer beforeUpdate invoked for " + e);
netWriteInvoked = true;
operationWasCreate = false;
originWasRemote = e.isOriginRemote();
writerInvocationCount++;
return;
}
public void beforeDestroy(EntryEvent e) throws CacheWriterException {
}
public void beforeRegionDestroy(RegionEvent e) throws CacheWriterException {
}
public void beforeRegionClear(RegionEvent e) throws CacheWriterException {
}
public void close() {
}
});
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating replicated region", ex);
}
}
});
vm1.invoke(new SerializableRunnable("Create empty Region") {
public void run() {
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.EMPTY);
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating empty region", ex);
}
}
});
vm1.invoke(new SerializableRunnable("do a put that should be proxied in the other vm and invoke its cache writer") {
public void run() {
try {
getRootRegion().getSubregion(name).put(objectName, value);
} catch (CacheWriterException cwe) {
} catch (TimeoutException te) {
}
}
});
vm0.invoke(new SerializableRunnable("ensure that cache writer was invoked with correct settings in event") {
public void run() {
assertTrue("expected cache writer to be invoked", netWriteInvoked);
assertTrue("expected originRemote to be true", originWasRemote);
assertTrue("expected event to be create", operationWasCreate);
assertEquals("expected only one cache writer invocation", 1, writerInvocationCount);
// set flags for the next test - updating the same key
netWriteInvoked = false;
writerInvocationCount = 0;
}
});
vm1.invoke(new SerializableRunnable("do an update that should be proxied in the other vm and invoke its cache writer") {
public void run() {
try {
getRootRegion().getSubregion(name).put(objectName, updateValue);
} catch (CacheWriterException cwe) {
} catch (TimeoutException te) {
}
}
});
vm0.invoke(new SerializableRunnable("ensure that cache writer was invoked with correct settings in event") {
public void run() {
assertTrue("expected cache writer to be invoked", netWriteInvoked);
assertTrue("expected originRemote to be true", originWasRemote);
assertTrue("expected event to be create", operationWasCreate);
assertEquals("expected only one cache writer invocation", 1, writerInvocationCount);
}
});
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class SearchAndLoadDUnitTest method testNetWrite.
@Test
public void testNetWrite() throws CacheException, InterruptedException {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final String name = this.getUniqueName() + "-ACK";
final String objectName = "Gemfire7";
final Integer value = new Integer(483);
vm0.invoke(new SerializableRunnable("Create ACK Region with cacheWriter") {
public void run() {
netWriteInvoked = false;
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setCacheWriter(new CacheWriter() {
public void beforeCreate(EntryEvent e) throws CacheWriterException {
netWriteInvoked = true;
return;
}
public void beforeUpdate(EntryEvent e) throws CacheWriterException {
netWriteInvoked = true;
return;
}
public void beforeDestroy(EntryEvent e) throws CacheWriterException {
return;
}
public void beforeRegionDestroy(RegionEvent e) throws CacheWriterException {
return;
}
public void beforeRegionClear(RegionEvent e) throws CacheWriterException {
return;
}
public void close() {
}
});
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating ACK region", ex);
}
}
});
vm1.invoke(new SerializableRunnable("Create ACK Region") {
public void run() {
loaderInvoked = false;
remoteLoaderInvoked = false;
netWriteInvoked = false;
try {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
createRegion(name, factory.create());
} catch (CacheException ex) {
Assert.fail("While creating ACK region", ex);
}
}
});
vm1.invoke(new SerializableRunnable("Do a put operation resulting in cache writer notification in other vm") {
public void run() {
try {
getRootRegion().getSubregion(name).put(objectName, value);
try {
Object result = getRootRegion().getSubregion(name).get(objectName);
assertEquals(result, value);
} catch (CacheLoaderException cle) {
} catch (TimeoutException te) {
}
} catch (CacheWriterException cwe) {
} catch (TimeoutException te) {
}
}
});
vm0.invoke(new SerializableRunnable("ensure that cache writer was invoked") {
public void run() {
assertTrue("expected cache writer to be invoked", netWriteInvoked);
}
});
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class LocalRegion method evictDestroy.
/**
* @return true if the evict destroy was done; false if it was not needed
*/
boolean evictDestroy(LRUEntry entry) {
checkReadiness();
@Released final EntryEventImpl event = generateEvictDestroyEvent(entry.getKey());
try {
return mapDestroy(// cacheWrite
event, // cacheWrite
false, // isEviction
true, // expectedOldValue
null);
} catch (CacheWriterException error) {
throw new Error(LocalizedStrings.LocalRegion_CACHE_WRITER_SHOULD_NOT_HAVE_BEEN_CALLED_FOR_EVICTDESTROY.toLocalizedString(), error);
} catch (TimeoutException anotherError) {
throw new Error(LocalizedStrings.LocalRegion_NO_DISTRIBUTED_LOCK_SHOULD_HAVE_BEEN_ATTEMPTED_FOR_EVICTDESTROY.toLocalizedString(), anotherError);
} catch (EntryNotFoundException yetAnotherError) {
throw new Error(LocalizedStrings.LocalRegion_ENTRYNOTFOUNDEXCEPTION_SHOULD_BE_MASKED_FOR_EVICTDESTROY.toLocalizedString(), yetAnotherError);
} finally {
event.release();
}
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class LocalRegion method localDestroyRegion.
@Override
public void localDestroyRegion(Object aCallbackArgument) {
getDataView().checkSupportsRegionDestroy();
RegionEventImpl event = new RegionEventImpl(this, Operation.REGION_LOCAL_DESTROY, aCallbackArgument, false, getMyId(), generateEventID());
try {
basicDestroyRegion(event, false);
} catch (CacheWriterException e) {
// not possible with local operation, CacheWriter not called
throw new Error(LocalizedStrings.LocalRegion_CACHEWRITEREXCEPTION_SHOULD_NOT_BE_THROWN_IN_LOCALDESTROYREGION.toLocalizedString(), e);
} catch (TimeoutException e) {
// not possible with local operation, no distributed locks possible
throw new Error(LocalizedStrings.LocalRegion_TIMEOUTEXCEPTION_SHOULD_NOT_BE_THROWN_IN_LOCALDESTROYREGION.toLocalizedString(), e);
}
}
Aggregations