Search in sources :

Example 1 with DynamicRegionFactory

use of org.apache.geode.cache.DynamicRegionFactory in project geode by apache.

the class ClientAuthorizationTestCase method doOp.

protected static void doOp(OperationCode op, final int[] indices, final int flagsI, final int expectedResult) throws InterruptedException {
    boolean operationOmitted = false;
    final int flags = flagsI;
    Region region = getRegion();
    if ((flags & OpFlags.USE_SUBREGION) > 0) {
        assertNotNull(region);
        Region subregion = null;
        if ((flags & OpFlags.NO_CREATE_SUBREGION) > 0) {
            if ((flags & OpFlags.CHECK_NOREGION) > 0) {
                // Wait for some time for DRF update to come
                waitForCondition(() -> getSubregion() == null);
                subregion = getSubregion();
                assertNull(subregion);
                return;
            } else {
                // Wait for some time for DRF update to come
                waitForCondition(() -> getSubregion() != null);
                subregion = getSubregion();
                assertNotNull(subregion);
            }
        } else {
            subregion = createSubregion(region);
        }
        assertNotNull(subregion);
        region = subregion;
    } else if ((flags & OpFlags.CHECK_NOREGION) > 0) {
        // Wait for some time for region destroy update to come
        waitForCondition(() -> getRegion() == null);
        region = getRegion();
        assertNull(region);
        return;
    } else {
        assertNotNull(region);
    }
    final String[] keys = KEYS;
    final String[] vals;
    if ((flags & OpFlags.USE_NEWVAL) > 0) {
        vals = NVALUES;
    } else {
        vals = VALUES;
    }
    InterestResultPolicy policy = InterestResultPolicy.KEYS_VALUES;
    if ((flags & OpFlags.REGISTER_POLICY_NONE) > 0) {
        policy = InterestResultPolicy.NONE;
    }
    final int numOps = indices.length;
    System.out.println("Got doOp for op: " + op.toString() + ", numOps: " + numOps + ", indices: " + indicesToString(indices) + ", expect: " + expectedResult);
    boolean exceptionOccurred = false;
    boolean breakLoop = false;
    if (op.isGet() || op.isContainsKey() || op.isKeySet() || op.isQuery() || op.isExecuteCQ()) {
        Thread.sleep(PAUSE);
    }
    for (int indexIndex = 0; indexIndex < numOps; ++indexIndex) {
        if (breakLoop) {
            break;
        }
        int index = indices[indexIndex];
        try {
            final Object key = keys[index];
            final Object expectedVal = vals[index];
            if (op.isGet()) {
                Object value = null;
                // this is the case for testing GET_ALL
                if ((flags & OpFlags.USE_ALL_KEYS) > 0) {
                    breakLoop = true;
                    List keyList = new ArrayList(numOps);
                    Object searchKey;
                    for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                        int keyNum = indices[keyNumIndex];
                        searchKey = keys[keyNum];
                        keyList.add(searchKey);
                        // local invalidate some KEYS to force fetch of those KEYS from server
                        if ((flags & OpFlags.CHECK_NOKEY) > 0) {
                            AbstractRegionEntry entry = (AbstractRegionEntry) ((LocalRegion) region).getRegionEntry(searchKey);
                            System.out.println("" + keyNum + ": key is " + searchKey + " and entry is " + entry);
                            assertFalse(region.containsKey(searchKey));
                        } else {
                            if (keyNumIndex % 2 == 1) {
                                assertTrue(region.containsKey(searchKey));
                                region.localInvalidate(searchKey);
                            }
                        }
                    }
                    Map entries = region.getAll(keyList);
                    for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                        int keyNum = indices[keyNumIndex];
                        searchKey = keys[keyNum];
                        if ((flags & OpFlags.CHECK_FAIL) > 0) {
                            assertFalse(entries.containsKey(searchKey));
                        } else {
                            assertTrue(entries.containsKey(searchKey));
                            value = entries.get(searchKey);
                            assertEquals(vals[keyNum], value);
                        }
                    }
                    break;
                }
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    Callable<Boolean> condition = new Callable<Boolean>() {

                        private Region region;

                        @Override
                        public Boolean call() throws Exception {
                            Object value = getLocalValue(region, key);
                            return (flags & OpFlags.CHECK_FAIL) > 0 ? !expectedVal.equals(value) : expectedVal.equals(value);
                        }

                        public Callable<Boolean> init(Region region) {
                            this.region = region;
                            return this;
                        }
                    }.init(region);
                    waitForCondition(condition);
                    value = getLocalValue(region, key);
                } else if ((flags & OpFlags.USE_GET_ENTRY_IN_TX) > 0) {
                    getCache().getCacheTransactionManager().begin();
                    Entry e = region.getEntry(key);
                    // Also, check getAll()
                    ArrayList a = new ArrayList();
                    a.addAll(a);
                    region.getAll(a);
                    getCache().getCacheTransactionManager().commit();
                    value = e.getValue();
                } else {
                    if ((flags & OpFlags.CHECK_NOKEY) > 0) {
                        assertFalse(region.containsKey(key));
                    } else {
                        assertTrue(region.containsKey(key) || ((LocalRegion) region).getRegionEntry(key).isTombstone());
                        region.localInvalidate(key);
                    }
                    value = region.get(key);
                }
                if ((flags & OpFlags.CHECK_FAIL) > 0) {
                    assertFalse(expectedVal.equals(value));
                } else {
                    assertNotNull(value);
                    assertEquals(expectedVal, value);
                }
            } else if (op.isPut()) {
                region.put(key, expectedVal);
            } else if (op.isPutAll()) {
                HashMap map = new HashMap();
                for (int i = 0; i < indices.length; i++) {
                    map.put(keys[indices[i]], vals[indices[i]]);
                }
                region.putAll(map);
                breakLoop = true;
            } else if (op.isDestroy()) {
                // }
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    region.localDestroy(key);
                } else {
                    region.destroy(key);
                }
            } else if (op.isInvalidate()) {
                if (region.containsKey(key)) {
                    if ((flags & OpFlags.LOCAL_OP) > 0) {
                        region.localInvalidate(key);
                    } else {
                        region.invalidate(key);
                    }
                }
            } else if (op.isContainsKey()) {
                boolean result;
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    result = region.containsKey(key);
                } else {
                    result = region.containsKeyOnServer(key);
                }
                if ((flags & OpFlags.CHECK_FAIL) > 0) {
                    assertFalse(result);
                } else {
                    assertTrue(result);
                }
            } else if (op.isRegisterInterest()) {
                if ((flags & OpFlags.USE_LIST) > 0) {
                    breakLoop = true;
                    // Register interest list in this case
                    List keyList = new ArrayList(numOps);
                    for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                        int keyNum = indices[keyNumIndex];
                        keyList.add(keys[keyNum]);
                    }
                    region.registerInterest(keyList, policy);
                } else if ((flags & OpFlags.USE_REGEX) > 0) {
                    breakLoop = true;
                    region.registerInterestRegex("key[1-" + numOps + ']', policy);
                } else if ((flags & OpFlags.USE_ALL_KEYS) > 0) {
                    breakLoop = true;
                    region.registerInterest("ALL_KEYS", policy);
                } else {
                    region.registerInterest(key, policy);
                }
            } else if (op.isUnregisterInterest()) {
                if ((flags & OpFlags.USE_LIST) > 0) {
                    breakLoop = true;
                    // Register interest list in this case
                    List keyList = new ArrayList(numOps);
                    for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                        int keyNum = indices[keyNumIndex];
                        keyList.add(keys[keyNum]);
                    }
                    region.unregisterInterest(keyList);
                } else if ((flags & OpFlags.USE_REGEX) > 0) {
                    breakLoop = true;
                    region.unregisterInterestRegex("key[1-" + numOps + ']');
                } else if ((flags & OpFlags.USE_ALL_KEYS) > 0) {
                    breakLoop = true;
                    region.unregisterInterest("ALL_KEYS");
                } else {
                    region.unregisterInterest(key);
                }
            } else if (op.isKeySet()) {
                breakLoop = true;
                Set keySet;
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    keySet = region.keySet();
                } else {
                    keySet = region.keySetOnServer();
                }
                assertNotNull(keySet);
                if ((flags & OpFlags.CHECK_FAIL) == 0) {
                    assertEquals(numOps, keySet.size());
                }
                for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                    int keyNum = indices[keyNumIndex];
                    if ((flags & OpFlags.CHECK_FAIL) > 0) {
                        assertFalse(keySet.contains(keys[keyNum]));
                    } else {
                        assertTrue(keySet.contains(keys[keyNum]));
                    }
                }
            } else if (op.isQuery()) {
                breakLoop = true;
                SelectResults queryResults = region.query("SELECT DISTINCT * FROM " + region.getFullPath());
                assertNotNull(queryResults);
                Set queryResultSet = queryResults.asSet();
                if ((flags & OpFlags.CHECK_FAIL) == 0) {
                    assertEquals(numOps, queryResultSet.size());
                }
                for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                    int keyNum = indices[keyNumIndex];
                    if ((flags & OpFlags.CHECK_FAIL) > 0) {
                        assertFalse(queryResultSet.contains(vals[keyNum]));
                    } else {
                        assertTrue(queryResultSet.contains(vals[keyNum]));
                    }
                }
            } else if (op.isExecuteCQ()) {
                breakLoop = true;
                QueryService queryService = getCache().getQueryService();
                CqQuery cqQuery;
                if ((cqQuery = queryService.getCq("cq1")) == null) {
                    CqAttributesFactory cqFact = new CqAttributesFactory();
                    cqFact.addCqListener(new AuthzCqListener());
                    CqAttributes cqAttrs = cqFact.create();
                    cqQuery = queryService.newCq("cq1", "SELECT * FROM " + region.getFullPath(), cqAttrs);
                }
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    // Interpret this as testing results using CqListener
                    final AuthzCqListener listener = (AuthzCqListener) cqQuery.getCqAttributes().getCqListener();
                    WaitCriterion ev = new WaitCriterion() {

                        @Override
                        public boolean done() {
                            if ((flags & OpFlags.CHECK_FAIL) > 0) {
                                return 0 == listener.getNumUpdates();
                            } else {
                                return numOps == listener.getNumUpdates();
                            }
                        }

                        @Override
                        public String description() {
                            return null;
                        }
                    };
                    waitForCriterion(ev, 3 * 1000, 200, true);
                    if ((flags & OpFlags.CHECK_FAIL) > 0) {
                        assertEquals(0, listener.getNumUpdates());
                    } else {
                        assertEquals(numOps, listener.getNumUpdates());
                        listener.checkPuts(vals, indices);
                    }
                    assertEquals(0, listener.getNumCreates());
                    assertEquals(0, listener.getNumDestroys());
                    assertEquals(0, listener.getNumOtherOps());
                    assertEquals(0, listener.getNumErrors());
                } else {
                    SelectResults cqResults = cqQuery.executeWithInitialResults();
                    assertNotNull(cqResults);
                    Set cqResultValues = new HashSet();
                    for (Object o : cqResults.asList()) {
                        Struct s = (Struct) o;
                        cqResultValues.add(s.get("value"));
                    }
                    Set cqResultSet = cqResults.asSet();
                    if ((flags & OpFlags.CHECK_FAIL) == 0) {
                        assertEquals(numOps, cqResultSet.size());
                    }
                    for (int keyNumIndex = 0; keyNumIndex < numOps; ++keyNumIndex) {
                        int keyNum = indices[keyNumIndex];
                        if ((flags & OpFlags.CHECK_FAIL) > 0) {
                            assertFalse(cqResultValues.contains(vals[keyNum]));
                        } else {
                            assertTrue(cqResultValues.contains(vals[keyNum]));
                        }
                    }
                }
            } else if (op.isStopCQ()) {
                breakLoop = true;
                CqQuery cqQuery = getCache().getQueryService().getCq("cq1");
                ((AuthzCqListener) cqQuery.getCqAttributes().getCqListener()).reset();
                cqQuery.stop();
            } else if (op.isCloseCQ()) {
                breakLoop = true;
                CqQuery cqQuery = getCache().getQueryService().getCq("cq1");
                ((AuthzCqListener) cqQuery.getCqAttributes().getCqListener()).reset();
                cqQuery.close();
            } else if (op.isRegionClear()) {
                breakLoop = true;
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    region.localClear();
                } else {
                    region.clear();
                }
            } else if (op.isRegionCreate()) {
                breakLoop = true;
                // Region subregion = createSubregion(region);
                // subregion.createRegionOnServer();
                // Create region on server using the DynamicRegionFactory
                // Assume it has been already initialized
                DynamicRegionFactory drf = DynamicRegionFactory.get();
                Region subregion = drf.createDynamicRegion(regionName, SUBREGION_NAME);
                assertEquals('/' + regionName + '/' + SUBREGION_NAME, subregion.getFullPath());
            } else if (op.isRegionDestroy()) {
                breakLoop = true;
                if ((flags & OpFlags.LOCAL_OP) > 0) {
                    region.localDestroyRegion();
                } else {
                    if ((flags & OpFlags.USE_SUBREGION) > 0) {
                        try {
                            DynamicRegionFactory.get().destroyDynamicRegion(region.getFullPath());
                        } catch (RegionDestroyedException ex) {
                            // harmless to ignore this
                            System.out.println("doOp: sub-region " + region.getFullPath() + " already destroyed");
                            operationOmitted = true;
                        }
                    } else {
                        region.destroyRegion();
                    }
                }
            } else {
                fail("doOp: Unhandled operation " + op);
            }
            if (expectedResult != NO_EXCEPTION) {
                if (!operationOmitted && !op.isUnregisterInterest()) {
                    fail("Expected an exception while performing operation op =" + op + "flags = " + OpFlags.description(flags));
                }
            }
        } catch (Exception ex) {
            exceptionOccurred = true;
            if ((ex instanceof ServerConnectivityException || ex instanceof QueryInvocationTargetException || ex instanceof CqException) && (expectedResult == NOTAUTHZ_EXCEPTION) && (ex.getCause() instanceof NotAuthorizedException)) {
                System.out.println("doOp: Got expected NotAuthorizedException when doing operation [" + op + "] with flags " + OpFlags.description(flags) + ": " + ex.getCause());
                continue;
            } else if (expectedResult == OTHER_EXCEPTION) {
                System.out.println("doOp: Got expected exception when doing operation: " + ex.toString());
                continue;
            } else {
                fail("doOp: Got unexpected exception when doing operation. Policy = " + policy + " flags = " + OpFlags.description(flags), ex);
            }
        }
    }
    if (!exceptionOccurred && !operationOmitted && expectedResult != NO_EXCEPTION) {
        fail("Expected an exception while performing operation: " + op + " flags = " + OpFlags.description(flags));
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ArrayList(java.util.ArrayList) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Callable(java.util.concurrent.Callable) Struct(org.apache.geode.cache.query.Struct) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) InterestResultPolicy(org.apache.geode.cache.InterestResultPolicy) Entry(org.apache.geode.cache.Region.Entry) AbstractRegionEntry(org.apache.geode.internal.cache.AbstractRegionEntry) SelectResults(org.apache.geode.cache.query.SelectResults) ArrayList(java.util.ArrayList) List(java.util.List) CqQuery(org.apache.geode.cache.query.CqQuery) HashSet(java.util.HashSet) DynamicRegionFactory(org.apache.geode.cache.DynamicRegionFactory) CqException(org.apache.geode.cache.query.CqException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) CqException(org.apache.geode.cache.query.CqException) RegionDestroyedException(org.apache.geode.cache.RegionDestroyedException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) QueryInvocationTargetException(org.apache.geode.cache.query.QueryInvocationTargetException) AbstractRegionEntry(org.apache.geode.internal.cache.AbstractRegionEntry) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) QueryService(org.apache.geode.cache.query.QueryService) CqAttributes(org.apache.geode.cache.query.CqAttributes) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with DynamicRegionFactory

use of org.apache.geode.cache.DynamicRegionFactory in project geode by apache.

the class CacheCreation method sameAs.

/**
   * Returns whether or not this {@code CacheCreation} is equivalent to another {@code Cache}.
   */
public boolean sameAs(Cache other) {
    boolean sameConfig = other.getLockLease() == this.getLockLease() && other.getLockTimeout() == this.getLockTimeout() && other.getSearchTimeout() == this.getSearchTimeout() && other.getMessageSyncInterval() == this.getMessageSyncInterval() && other.getCopyOnRead() == this.getCopyOnRead() && other.isServer() == this.isServer();
    if (!sameConfig) {
        throw new RuntimeException(LocalizedStrings.CacheCreation_SAMECONFIG.toLocalizedString());
    } else {
        DynamicRegionFactory.Config drc1 = this.getDynamicRegionFactoryConfig();
        if (drc1 != null) {
            // we have a dynamic region factory
            DynamicRegionFactory.Config drc2 = null;
            if (other instanceof CacheCreation) {
                drc2 = ((CacheCreation) other).getDynamicRegionFactoryConfig();
            } else {
                drc2 = DynamicRegionFactory.get().getConfig();
            }
            if (drc2 == null) {
                return false;
            }
            if (!drc1.equals(drc2)) {
                return false;
            }
        } else {
            // we have no dynamic region factory; how about other?
            if (other instanceof CacheCreation) {
                if (((CacheCreation) other).getDynamicRegionFactoryConfig() != null) {
                    return false;
                }
            } else {
                // other must be real cache in which case we compare to DynamicRegionFactory
                if (DynamicRegionFactory.get().isOpen()) {
                    return false;
                }
            }
        }
        Collection<CacheServer> myBridges = this.getCacheServers();
        Collection<CacheServer> otherBridges = other.getCacheServers();
        if (myBridges.size() != otherBridges.size()) {
            throw new RuntimeException(LocalizedStrings.CacheCreation_CACHESERVERS_SIZE.toLocalizedString());
        }
        for (CacheServer myBridge1 : myBridges) {
            CacheServerCreation myBridge = (CacheServerCreation) myBridge1;
            boolean found = false;
            for (CacheServer otherBridge : otherBridges) {
                if (myBridge.sameAs(otherBridge)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                throw new RuntimeException(LocalizedStrings.CacheCreation_CACHE_SERVER_0_NOT_FOUND.toLocalizedString(myBridge));
            }
        }
        // compare connection pools
        Map<String, Pool> m1 = getPools();
        Map<String, Pool> m2 = other instanceof CacheCreation ? ((CacheCreation) other).getPools() : PoolManager.getAll();
        int m1Size = m1.size();
        // ignore any gateway instances
        for (Pool cp : m1.values()) {
            if (((PoolImpl) cp).isUsedByGateway()) {
                m1Size--;
            }
        }
        int m2Size = m2.size();
        // ignore any gateway instances
        for (Pool cp : m2.values()) {
            if (((PoolImpl) cp).isUsedByGateway()) {
                m2Size--;
            }
        }
        if (m2Size == 1) {
            // if it is just the DEFAULT pool then ignore it
            Pool p = (Pool) m2.values().iterator().next();
            if (p.getName().equals("DEFAULT")) {
                m2Size = 0;
            }
        }
        if (m1Size != m2Size) {
            throw new RuntimeException("pool sizes differ m1Size=" + m1Size + " m2Size=" + m2Size + " m1=" + m1.values() + " m2=" + m2.values());
        }
        if (m1Size > 0) {
            for (Pool pool : m1.values()) {
                PoolImpl poolImpl = (PoolImpl) pool;
                // ignore any gateway instances
                if (!poolImpl.isUsedByGateway()) {
                    poolImpl.sameAs(m2.get(poolImpl.getName()));
                }
            }
        }
        // compare disk stores
        for (DiskStore diskStore : this.diskStores.values()) {
            DiskStoreAttributesCreation dsac = (DiskStoreAttributesCreation) diskStore;
            String name = dsac.getName();
            DiskStore ds = other.findDiskStore(name);
            if (ds == null) {
                getLogger().fine("Disk store " + name + " not found.");
                throw new RuntimeException(LocalizedStrings.CacheCreation_DISKSTORE_NOTFOUND_0.toLocalizedString(name));
            } else {
                if (!dsac.sameAs(ds)) {
                    getLogger().fine("Attributes for disk store " + name + " do not match");
                    throw new RuntimeException(LocalizedStrings.CacheCreation_ATTRIBUTES_FOR_DISKSTORE_0_DO_NOT_MATCH.toLocalizedString(name));
                }
            }
        }
        Map<String, RegionAttributes<?, ?>> myNamedAttributes = this.listRegionAttributes();
        Map<String, RegionAttributes<Object, Object>> otherNamedAttributes = other.listRegionAttributes();
        if (myNamedAttributes.size() != otherNamedAttributes.size()) {
            throw new RuntimeException(LocalizedStrings.CacheCreation_NAMEDATTRIBUTES_SIZE.toLocalizedString());
        }
        for (Object object : myNamedAttributes.entrySet()) {
            Entry myEntry = (Entry) object;
            String myId = (String) myEntry.getKey();
            Assert.assertTrue(myEntry.getValue() instanceof RegionAttributesCreation, "Entry value is a " + myEntry.getValue().getClass().getName());
            RegionAttributesCreation myAttrs = (RegionAttributesCreation) myEntry.getValue();
            RegionAttributes<Object, Object> otherAttrs = other.getRegionAttributes(myId);
            if (otherAttrs == null) {
                getLogger().fine("No attributes for " + myId);
                throw new RuntimeException(LocalizedStrings.CacheCreation_NO_ATTRIBUTES_FOR_0.toLocalizedString(myId));
            } else {
                if (!myAttrs.sameAs(otherAttrs)) {
                    getLogger().fine("Attributes for " + myId + " do not match");
                    throw new RuntimeException(LocalizedStrings.CacheCreation_ATTRIBUTES_FOR_0_DO_NOT_MATCH.toLocalizedString(myId));
                }
            }
        }
        Collection<Region<?, ?>> myRoots = this.roots.values();
        Collection<Region<?, ?>> otherRoots = other.rootRegions();
        if (myRoots.size() != otherRoots.size()) {
            throw new RuntimeException(LocalizedStrings.CacheCreation_ROOTS_SIZE.toLocalizedString());
        }
        for (final Region<?, ?> myRoot : myRoots) {
            RegionCreation rootRegion = (RegionCreation) myRoot;
            Region<Object, Object> otherRegion = other.getRegion(rootRegion.getName());
            if (otherRegion == null) {
                throw new RuntimeException(LocalizedStrings.CacheCreation_NO_ROOT_0.toLocalizedString(rootRegion.getName()));
            } else if (!rootRegion.sameAs(otherRegion)) {
                throw new RuntimeException(LocalizedStrings.CacheCreation_REGIONS_DIFFER.toLocalizedString());
            }
        }
        // If both have a listener, make sure they are equal.
        if (getCacheTransactionManager() != null) {
            // Currently the GemFireCache always has a CacheTransactionManager,
            // whereas that is not true for CacheTransactionManagerCreation.
            List<TransactionListener> otherTxListeners = Arrays.asList(other.getCacheTransactionManager().getListeners());
            List<TransactionListener> thisTxListeners = Arrays.asList(getCacheTransactionManager().getListeners());
            if (!thisTxListeners.equals(otherTxListeners)) {
                throw new RuntimeException(LocalizedStrings.CacheCreation_TXLISTENER.toLocalizedString());
            }
        }
    }
    if (hasResourceManager()) {
        getResourceManager().sameAs(other.getResourceManager());
    }
    return true;
}
Also used : TransactionListener(org.apache.geode.cache.TransactionListener) RegionAttributes(org.apache.geode.cache.RegionAttributes) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) Entry(java.util.Map.Entry) CacheServer(org.apache.geode.cache.server.CacheServer) Pool(org.apache.geode.cache.client.Pool) DynamicRegionFactory(org.apache.geode.cache.DynamicRegionFactory) SimpleExtensionPoint(org.apache.geode.internal.cache.extension.SimpleExtensionPoint) ExtensionPoint(org.apache.geode.internal.cache.extension.ExtensionPoint) DiskStore(org.apache.geode.cache.DiskStore) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion)

Example 3 with DynamicRegionFactory

use of org.apache.geode.cache.DynamicRegionFactory in project geode by apache.

the class CacheXmlGenerator method generateDynamicRegionFactory.

/**
   * Generates XML for a DynamicRegionFactory.Config
   *
   * @since GemFire 4.3
   */
private void generateDynamicRegionFactory(Cache c) throws SAXException {
    if (this.version.compareTo(CacheXmlVersion.GEMFIRE_4_1) < 0) {
        return;
    }
    DynamicRegionFactory.Config cfg;
    if (c instanceof CacheCreation) {
        cfg = ((CacheCreation) c).getDynamicRegionFactoryConfig();
    } else {
        DynamicRegionFactory drf = DynamicRegionFactory.get();
        if (drf == null || drf.isClosed()) {
            return;
        }
        cfg = drf.getConfig();
    }
    if (cfg == null) {
        return;
    }
    AttributesImpl atts = new AttributesImpl();
    if (!cfg.getPersistBackup())
        atts.addAttribute("", "", DISABLE_PERSIST_BACKUP, "", "true");
    if (!cfg.getRegisterInterest())
        atts.addAttribute("", "", DISABLE_REGISTER_INTEREST, "", "true");
    if (cfg.getPoolName() != null) {
        atts.addAttribute("", "", POOL_NAME, "", cfg.getPoolName());
    }
    handler.startElement("", DYNAMIC_REGION_FACTORY, DYNAMIC_REGION_FACTORY, atts);
    {
        File dir = cfg.getDiskDir();
        if (dir != null) {
            handler.startElement("", DISK_DIR, DISK_DIR, EMPTY);
            String name = generateDefaults() ? dir.getAbsolutePath() : dir.getPath();
            handler.characters(name.toCharArray(), 0, name.length());
            handler.endElement("", DISK_DIR, DISK_DIR);
        }
    }
    handler.endElement("", DYNAMIC_REGION_FACTORY, DYNAMIC_REGION_FACTORY);
}
Also used : DiskWriteAttributesImpl(org.apache.geode.internal.cache.DiskWriteAttributesImpl) PartitionAttributesImpl(org.apache.geode.internal.cache.PartitionAttributesImpl) AttributesImpl(org.xml.sax.helpers.AttributesImpl) DynamicRegionFactory(org.apache.geode.cache.DynamicRegionFactory) File(java.io.File)

Aggregations

DynamicRegionFactory (org.apache.geode.cache.DynamicRegionFactory)3 Region (org.apache.geode.cache.Region)2 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 Callable (java.util.concurrent.Callable)1 DiskStore (org.apache.geode.cache.DiskStore)1 InterestResultPolicy (org.apache.geode.cache.InterestResultPolicy)1 Entry (org.apache.geode.cache.Region.Entry)1 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 RegionDestroyedException (org.apache.geode.cache.RegionDestroyedException)1 TransactionListener (org.apache.geode.cache.TransactionListener)1 Pool (org.apache.geode.cache.client.Pool)1 ServerConnectivityException (org.apache.geode.cache.client.ServerConnectivityException)1