use of org.apache.geode.cache.TimeoutException 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.TimeoutException in project geode by apache.
the class SearchAndLoadDUnitTest method testNetLoadNoLoaders.
@Test
public void testNetLoadNoLoaders() 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 = "B";
SerializableRunnable create = new CacheSerializableRunnable("Create Region") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
createRegion(name, factory.create());
}
};
vm0.invoke(create);
vm1.invoke(create);
vm0.invoke(new SerializableRunnable("Get with No Loaders defined") {
public void run() {
try {
Object result = getRootRegion().getSubregion(name).get(objectName);
assertNull(result);
} catch (CacheLoaderException cle) {
Assert.fail("While getting value for ACK region", cle);
} catch (TimeoutException te) {
Assert.fail("While getting value for ACK region", te);
}
}
});
}
use of org.apache.geode.cache.TimeoutException 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.TimeoutException 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);
}
}
use of org.apache.geode.cache.TimeoutException in project geode by apache.
the class LocalManager method startLocalManagement.
/**
* Managed Node side resources are created
*
* Management Region : its a Replicated NO_ACK region Notification Region : its a Replicated Proxy
* NO_ACK region
*/
private void startLocalManagement(Map<ObjectName, FederationComponent> federatedComponentMap) {
synchronized (this) {
if (repo.getLocalMonitoringRegion() != null) {
return;
} else {
ThreadFactory tf = new ThreadFactory() {
public Thread newThread(final Runnable command) {
final Runnable r = new Runnable() {
public void run() {
command.run();
}
};
final ThreadGroup group = LoggingThreadGroup.createThreadGroup(ManagementStrings.MANAGEMENT_TASK_THREAD_GROUP.toLocalizedString(), logger);
Thread thread = new Thread(group, r, ManagementStrings.MANAGEMENT_TASK.toLocalizedString());
thread.setDaemon(true);
return thread;
}
};
singleThreadFederationScheduler = Executors.newSingleThreadScheduledExecutor(tf);
if (logger.isDebugEnabled()) {
logger.debug("Creating Management Region :");
}
/*
* Sharing the same Internal Argument for both notification region and monitoring region
*/
InternalRegionArguments internalArgs = new InternalRegionArguments();
internalArgs.setIsUsedForMetaRegion(true);
// Create anonymous stats holder for Management Regions
final HasCachePerfStats monitoringRegionStats = new HasCachePerfStats() {
public CachePerfStats getCachePerfStats() {
return new CachePerfStats(cache.getDistributedSystem(), "managementRegionStats");
}
};
internalArgs.setCachePerfStatsHolder(monitoringRegionStats);
AttributesFactory<String, Object> monitorRegionAttributeFactory = new AttributesFactory<String, Object>();
monitorRegionAttributeFactory.setScope(Scope.DISTRIBUTED_NO_ACK);
monitorRegionAttributeFactory.setDataPolicy(DataPolicy.REPLICATE);
monitorRegionAttributeFactory.setConcurrencyChecksEnabled(false);
MonitoringRegionCacheListener localListener = new MonitoringRegionCacheListener(service);
monitorRegionAttributeFactory.addCacheListener(localListener);
RegionAttributes<String, Object> monitoringRegionAttrs = monitorRegionAttributeFactory.create();
AttributesFactory<NotificationKey, Notification> notificationRegionAttributeFactory = new AttributesFactory<NotificationKey, Notification>();
notificationRegionAttributeFactory.setScope(Scope.DISTRIBUTED_NO_ACK);
notificationRegionAttributeFactory.setDataPolicy(DataPolicy.EMPTY);
notificationRegionAttributeFactory.setConcurrencyChecksEnabled(false);
RegionAttributes<NotificationKey, Notification> notifRegionAttrs = notificationRegionAttributeFactory.create();
String appender = MBeanJMXAdapter.getUniqueIDForMember(cache.getDistributedSystem().getDistributedMember());
boolean monitoringRegionCreated = false;
boolean notifRegionCreated = false;
try {
repo.setLocalMonitoringRegion(cache.createVMRegion(ManagementConstants.MONITORING_REGION + "_" + appender, monitoringRegionAttrs, internalArgs));
monitoringRegionCreated = true;
} catch (TimeoutException e) {
throw new ManagementException(e);
} catch (RegionExistsException e) {
throw new ManagementException(e);
} catch (IOException e) {
throw new ManagementException(e);
} catch (ClassNotFoundException e) {
throw new ManagementException(e);
}
try {
repo.setLocalNotificationRegion(cache.createVMRegion(ManagementConstants.NOTIFICATION_REGION + "_" + appender, notifRegionAttrs, internalArgs));
notifRegionCreated = true;
} catch (TimeoutException e) {
throw new ManagementException(e);
} catch (RegionExistsException e) {
throw new ManagementException(e);
} catch (IOException e) {
throw new ManagementException(e);
} catch (ClassNotFoundException e) {
throw new ManagementException(e);
} finally {
if (!notifRegionCreated && monitoringRegionCreated) {
repo.getLocalMonitoringRegion().localDestroyRegion();
}
}
managementTask = new ManagementTask(federatedComponentMap);
// call run to get us initialized immediately with a sync call
managementTask.run();
// All local resources are created for the ManagementTask
// Now Management tasks can proceed.
int updateRate = cache.getInternalDistributedSystem().getConfig().getJmxManagerUpdateRate();
singleThreadFederationScheduler.scheduleAtFixedRate(managementTask, updateRate, updateRate, TimeUnit.MILLISECONDS);
if (logger.isDebugEnabled()) {
logger.debug("Management Region created with Name : {}", repo.getLocalMonitoringRegion().getName());
logger.debug("Notification Region created with Name : {}", repo.getLocalNotificationRegion().getName());
}
}
}
}
Aggregations