Search in sources :

Example 31 with ServerRegionProxy

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;
}
Also used : DynamicRegionAttributes(org.apache.geode.internal.cache.DynamicRegionAttributes) DynamicRegionAttributes(org.apache.geode.internal.cache.DynamicRegionAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) GemFireSecurityException(org.apache.geode.security.GemFireSecurityException) EvictionAttributesImpl(org.apache.geode.internal.cache.EvictionAttributesImpl) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) Pool(org.apache.geode.cache.client.Pool)

Example 32 with ServerRegionProxy

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;
            }
        }
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) StoredObject(org.apache.geode.internal.offheap.StoredObject)

Example 33 with ServerRegionProxy

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");
                        }
                    }
                }
            }
        }
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) StoredObject(org.apache.geode.internal.offheap.StoredObject) Operation(org.apache.geode.cache.Operation)

Example 34 with ServerRegionProxy

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());
        }
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl)

Aggregations

ServerRegionProxy (org.apache.geode.cache.client.internal.ServerRegionProxy)34 Connection (org.apache.geode.cache.client.internal.Connection)10 LocalRegion (org.apache.geode.internal.cache.LocalRegion)8 ArrayList (java.util.ArrayList)7 List (java.util.List)7 EventID (org.apache.geode.internal.cache.EventID)7 FunctionException (org.apache.geode.cache.execute.FunctionException)6 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)6 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)5 StoredObject (org.apache.geode.internal.offheap.StoredObject)5 CacheClosedException (org.apache.geode.cache.CacheClosedException)4 Region (org.apache.geode.cache.Region)4 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)4 CacheException (org.apache.geode.cache.CacheException)3 CacheWriterException (org.apache.geode.cache.CacheWriterException)3 Operation (org.apache.geode.cache.Operation)3 VM (org.apache.geode.test.dunit.VM)3 EntryNotFoundException (org.apache.geode.cache.EntryNotFoundException)2 EventIDHolder (org.apache.geode.internal.cache.EventIDHolder)2 ConcurrentCacheModificationException (org.apache.geode.internal.cache.versions.ConcurrentCacheModificationException)2