use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.
the class DynamicRegionFactory method createDynamicRegionImpl.
private Region createDynamicRegionImpl(String parentRegionName, String newRegionName, boolean addEntry) throws CacheException {
Region parentRegion = this.cache.getRegion(parentRegionName);
if (parentRegion == null) {
String errMsg = LocalizedStrings.DynamicRegionFactory_ERROR__COULD_NOT_FIND_A_REGION_NAMED___0_.toLocalizedString(parentRegionName);
RegionDestroyedException e = new RegionDestroyedException(errMsg, parentRegionName);
this.cache.getLoggerI18n().warning(LocalizedStrings.DynamicRegionFactory_ERROR__COULD_NOT_FIND_A_REGION_NAMED___0_, parentRegionName, e);
throw e;
}
// Create RegionAttributes by inheriting from the parent
RegionAttributes rra = parentRegion.getAttributes();
AttributesFactory af = new AttributesFactory(rra);
EvictionAttributes ev = rra.getEvictionAttributes();
if (ev != null && ev.getAlgorithm().isLRU()) {
EvictionAttributes rev = new EvictionAttributesImpl((EvictionAttributesImpl) ev);
af.setEvictionAttributes(rev);
}
// regions
if (newRegionName.endsWith("_PRTEST_")) {
af.setPartitionAttributes(new PartitionAttributesFactory().create());
}
RegionAttributes newRegionAttributes = af.create();
Region newRegion;
try {
newRegion = parentRegion.createSubregion(newRegionName, newRegionAttributes);
this.cache.getLoggerI18n().fine("Created dynamic region " + newRegion);
} catch (RegionExistsException ex) {
// a race condition exists that can cause this so just fine log it
this.cache.getLoggerI18n().fine("DynamicRegion " + newRegionName + " in parent " + parentRegionName + " already existed");
newRegion = ex.getRegion();
}
if (addEntry) {
DynamicRegionAttributes dra = new DynamicRegionAttributes();
dra.name = newRegionName;
dra.rootRegionName = parentRegion.getFullPath();
if (this.cache.getLoggerI18n().fineEnabled()) {
this.cache.getLoggerI18n().fine("Putting entry into dynamic region list at key: " + newRegion.getFullPath());
}
this.dynamicRegionList.put(newRegion.getFullPath(), dra);
}
if (this.config.getRegisterInterest()) {
ServerRegionProxy proxy = ((LocalRegion) newRegion).getServerProxy();
if (proxy != null) {
if (((Pool) proxy.getPool()).getSubscriptionEnabled()) {
try {
newRegion.registerInterest("ALL_KEYS");
} catch (GemFireSecurityException ex) {
// Ignore security exceptions here
this.cache.getSecurityLoggerI18n().warning(LocalizedStrings.DynamicRegionFactory_EXCEPTION_WHEN_REGISTERING_INTEREST_FOR_ALL_KEYS_IN_DYNAMIC_REGION_0_1, new Object[] { newRegion.getFullPath(), ex });
}
}
}
}
if (regionCreateSleepMillis > 0) {
try {
Thread.sleep(regionCreateSleepMillis);
} catch (InterruptedException ignore) {
Thread.currentThread().interrupt();
}
}
if (this.cache.getLoggerI18n().fineEnabled()) {
this.cache.getLoggerI18n().fine("Created Dynamic Region " + newRegion.getFullPath());
}
return newRegion;
}
use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.
the class LocalRegion method serverDestroy.
/**
* Destroy an entry on the server given its event.
*
* @since GemFire 5.7
*/
void serverDestroy(EntryEventImpl event, Object expectedOldValue) {
if (event.getOperation().isDistributed()) {
ServerRegionProxy mySRP = getServerProxy();
if (mySRP != null) {
// send to server
Object key = event.getKey();
Object callbackArg = event.getRawCallbackArgument();
Object result = mySRP.destroy(key, expectedOldValue, event.getOperation(), event, callbackArg);
if (result instanceof EntryNotFoundException) {
throw (EntryNotFoundException) result;
}
}
}
}
use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.
the class LocalRegion method serverPut.
/**
* @since GemFire 5.7
*/
void serverPut(EntryEventImpl event, boolean requireOldValue, Object expectedOldValue) {
if (event.getOperation().isDistributed() && !event.isFromServer()) {
ServerRegionProxy mySRP = getServerProxy();
if (mySRP != null) {
if (event.isBulkOpInProgress()) {
// this is a put all, ignore this!
return;
}
Operation op = event.getOperation();
// TODO: is the newEntry flag needed?
Object key = event.getKey();
Object value = event.getRawNewValue();
// serverPut is called by cacheWriteBeforePut so the new value will not yet be off-heap
Object callbackArg = event.getRawCallbackArgument();
boolean isCreate = event.isCreate();
Object result = mySRP.put(key, value, event.getDeltaBytes(), event, op, requireOldValue, expectedOldValue, callbackArg, isCreate);
// bug #42296, serverProxy returns null when cache is closing
getCancelCriterion().checkCancelInProgress(null);
// to apply the operation and need to throw an exception
if (op.guaranteesOldValue()) {
if (op != Operation.REPLACE || requireOldValue) {
event.setConcurrentMapOldValue(result);
}
if (op == Operation.PUT_IF_ABSENT) {
if (result != null) {
// customers don't see this exception
throw new EntryNotFoundException("entry existed for putIfAbsent");
}
} else if (op == Operation.REPLACE) {
if (requireOldValue && result == null) {
throw new EntryNotFoundException("entry not found for replace");
} else if (!requireOldValue) {
if (!(Boolean) result) {
// customers don't see this exception
throw new EntryNotFoundException("entry found with wrong value");
}
}
}
}
}
}
}
use of org.apache.geode.cache.client.internal.ServerRegionProxy in project geode by apache.
the class LocalRegion method detachPool.
/**
* Release the client connection pool if we have one
*
* @since GemFire 5.7
*/
private void detachPool() {
ServerRegionProxy serverRegionProxy = getServerProxy();
if (serverRegionProxy != null) {
InternalCache internalCache = getCache();
String poolName = this.getPoolName();
PoolImpl pool = (PoolImpl) PoolManager.find(this.getPoolName());
if (poolName != null && pool != null) {
serverRegionProxy.detach(internalCache.keepDurableSubscriptionsAlive() || pool.getKeepAlive());
} else {
serverRegionProxy.detach(internalCache.keepDurableSubscriptionsAlive());
}
}
}
Aggregations