Search in sources :

Example 1 with InternalClientCache

use of org.apache.geode.cache.client.internal.InternalClientCache in project geode by apache.

the class RegionAttributesCreation method inheritAttributes.

void inheritAttributes(Cache cache, boolean setDefaultPool) {
    if (this.refid == null) {
        // No attributes to inherit
        if (setDefaultPool && this.requiresPoolName && !hasPoolName()) {
            String defaultPoolName = null;
            if (cache instanceof GemFireCacheImpl) {
                InternalClientCache gfc = (InternalClientCache) cache;
                if (gfc.getDefaultPool() != null) {
                    defaultPoolName = gfc.getDefaultPool().getName();
                }
            } else if (cache instanceof ClientCacheCreation) {
                ClientCacheCreation ccc = (ClientCacheCreation) cache;
                defaultPoolName = ccc.getDefaultPoolName();
            }
            if (defaultPoolName != null) {
                setPoolName(defaultPoolName);
            }
        }
        return;
    }
    RegionAttributes parent = cache.getRegionAttributes(this.refid);
    if (parent == null) {
        throw new IllegalStateException(LocalizedStrings.RegionAttributesCreation_CANNOT_REFERENCE_NONEXISTING_REGION_ATTRIBUTES_NAMED_0.toLocalizedString(this.refid));
    }
    final boolean parentIsUserSpecified = parent instanceof UserSpecifiedRegionAttributes;
    final UserSpecifiedRegionAttributes parentWithHas;
    if (parentIsUserSpecified) {
        parentWithHas = (UserSpecifiedRegionAttributes) parent;
    } else {
        parentWithHas = null;
    }
    if (parentWithHas != null) {
        if (setDefaultPool && parentWithHas.requiresPoolName) {
            this.requiresPoolName = true;
            if (!hasPoolName()) {
                String defaultPoolName = null;
                if (cache instanceof GemFireCacheImpl) {
                    InternalClientCache gfc = (InternalClientCache) cache;
                    if (gfc.getDefaultPool() != null) {
                        defaultPoolName = gfc.getDefaultPool().getName();
                    }
                } else if (cache instanceof ClientCacheCreation) {
                    ClientCacheCreation ccc = (ClientCacheCreation) cache;
                    defaultPoolName = ccc.getDefaultPoolName();
                }
                if (defaultPoolName != null) {
                    setPoolName(defaultPoolName);
                }
            }
        }
    }
    // Inherit attributes that are not overridden
    if (!hasCacheListeners()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasCacheListeners()) {
                initCacheListeners(parent.getCacheListeners());
            }
        } else {
            initCacheListeners(parent.getCacheListeners());
        }
    }
    if (!hasGatewaySenderId()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasGatewaySenderId()) {
                initGatewaySenders(parent.getGatewaySenderIds());
            }
        } else {
            initGatewaySenders(parent.getGatewaySenderIds());
        }
    }
    if (!hasAsyncEventListeners()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasAsyncEventListeners()) {
                initAsyncEventQueues(parent.getAsyncEventQueueIds());
            }
        } else {
            initAsyncEventQueues(parent.getAsyncEventQueueIds());
        }
    }
    if (!hasCacheLoader()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasCacheLoader()) {
                setCacheLoader(parent.getCacheLoader());
            }
        } else {
            setCacheLoader(parent.getCacheLoader());
        }
    }
    if (!hasCacheWriter()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasCacheWriter()) {
                setCacheWriter(parent.getCacheWriter());
            }
        } else {
            setCacheWriter(parent.getCacheWriter());
        }
    }
    if (!hasEntryIdleTimeout()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasEntryIdleTimeout()) {
                setEntryIdleTimeout(parent.getEntryIdleTimeout());
            }
        } else {
            setEntryIdleTimeout(parent.getEntryIdleTimeout());
        }
    }
    if (!hasCustomEntryIdleTimeout()) {
        setCustomEntryIdleTimeout(parent.getCustomEntryIdleTimeout());
    }
    if (!hasEntryTimeToLive()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasEntryTimeToLive()) {
                setEntryTimeToLive(parent.getEntryTimeToLive());
            }
        } else {
            setEntryTimeToLive(parent.getEntryTimeToLive());
        }
    }
    if (!hasCustomEntryTimeToLive()) {
        setCustomEntryTimeToLive(parent.getCustomEntryTimeToLive());
    }
    if (!hasInitialCapacity()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasInitialCapacity()) {
                setInitialCapacity(parent.getInitialCapacity());
            }
        } else {
            setInitialCapacity(parent.getInitialCapacity());
        }
    }
    if (!hasKeyConstraint()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasKeyConstraint()) {
                setKeyConstraint(parent.getKeyConstraint());
            }
        } else {
            setKeyConstraint(parent.getKeyConstraint());
        }
    }
    if (!hasValueConstraint()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasValueConstraint()) {
                setValueConstraint(parent.getValueConstraint());
            }
        } else {
            setValueConstraint(parent.getValueConstraint());
        }
    }
    if (!hasLoadFactor()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasLoadFactor()) {
                setLoadFactor(parent.getLoadFactor());
            }
        } else {
            setLoadFactor(parent.getLoadFactor());
        }
    }
    if (!hasRegionIdleTimeout()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasRegionIdleTimeout()) {
                setRegionIdleTimeout(parent.getRegionIdleTimeout());
            }
        } else {
            setRegionIdleTimeout(parent.getRegionIdleTimeout());
        }
    }
    if (!hasRegionTimeToLive()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasRegionTimeToLive()) {
                setRegionTimeToLive(parent.getRegionTimeToLive());
            }
        } else {
            setRegionTimeToLive(parent.getRegionTimeToLive());
        }
    }
    if (!hasScope()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasScope()) {
                setScope(parent.getScope());
            }
        } else {
            setScope(parent.getScope());
        }
    }
    if (!hasStatisticsEnabled()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasStatisticsEnabled()) {
                setStatisticsEnabled(parent.getStatisticsEnabled());
            }
        } else {
            setStatisticsEnabled(parent.getStatisticsEnabled());
        }
    }
    if (!hasIgnoreJTA()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasIgnoreJTA()) {
                setIgnoreJTA(parent.getIgnoreJTA());
            }
        } else {
            setIgnoreJTA(parent.getIgnoreJTA());
        }
    }
    if (!hasIsLockGrantor()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasIsLockGrantor()) {
                setLockGrantor(parent.isLockGrantor());
            }
        } else {
            setLockGrantor(parent.isLockGrantor());
        }
    }
    if (!hasConcurrencyLevel()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasConcurrencyLevel()) {
                setConcurrencyLevel(parent.getConcurrencyLevel());
            }
        } else {
            setConcurrencyLevel(parent.getConcurrencyLevel());
        }
    }
    if (!hasConcurrencyChecksEnabled()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasConcurrencyChecksEnabled()) {
                setConcurrencyChecksEnabled(parent.getConcurrencyChecksEnabled());
            }
        } else {
            setConcurrencyChecksEnabled(parent.getConcurrencyChecksEnabled());
        }
    }
    if (!hasEarlyAck()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasEarlyAck()) {
                setEarlyAck(parent.getEarlyAck());
            }
        } else {
            setEarlyAck(parent.getEarlyAck());
        }
    }
    if (!this.hasEnableSubscriptionConflation()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasEnableSubscriptionConflation()) {
                setEnableSubscriptionConflation(parent.getEnableSubscriptionConflation());
            }
        } else {
            setEnableSubscriptionConflation(parent.getEnableSubscriptionConflation());
        }
    }
    if (!hasPublisher()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasPublisher()) {
                setPublisher(parent.getPublisher());
            }
        } else {
            setPublisher(parent.getPublisher());
        }
    }
    if (!hasEnableAsyncConflation()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasEnableAsyncConflation()) {
                setEnableAsyncConflation(parent.getEnableAsyncConflation());
            }
        } else {
            setEnableAsyncConflation(parent.getEnableAsyncConflation());
        }
    }
    if (!hasMulticastEnabled()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasMulticastEnabled()) {
                setMulticastEnabled(parent.getMulticastEnabled());
            }
        } else {
            setMulticastEnabled(parent.getMulticastEnabled());
        }
    }
    if (!hasDiskWriteAttributes()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasDiskWriteAttributes()) {
                setDiskWriteAttributes(parent.getDiskWriteAttributes());
            }
        } else {
            setDiskWriteAttributes(parent.getDiskWriteAttributes());
        }
    }
    if (!hasDiskDirs()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasDiskDirs()) {
                setDiskDirs(parent.getDiskDirs());
            }
        } else {
            setDiskDirs(parent.getDiskDirs());
        }
    }
    if (!hasIndexMaintenanceSynchronous()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasIndexMaintenanceSynchronous()) {
                setIndexMaintenanceSynchronous(parent.getIndexMaintenanceSynchronous());
            }
        } else {
            setIndexMaintenanceSynchronous(parent.getIndexMaintenanceSynchronous());
        }
    }
    if (!hasPartitionAttributes()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasPartitionAttributes()) {
                setPartitionAttributes(parent.getPartitionAttributes());
            }
        } else {
            setPartitionAttributes(parent.getPartitionAttributes());
        }
    }
    if (!hasSubscriptionAttributes()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasSubscriptionAttributes()) {
                setSubscriptionAttributes(parent.getSubscriptionAttributes());
            }
        } else {
            setSubscriptionAttributes(parent.getSubscriptionAttributes());
        }
    }
    if (!hasDataPolicy()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasDataPolicy()) {
                setDataPolicy(parent.getDataPolicy());
            }
        } else {
            setDataPolicy(parent.getDataPolicy());
        }
    }
    if (!hasEvictionAttributes()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasEvictionAttributes()) {
                setEvictionAttributes(parent.getEvictionAttributes());
            }
        } else {
            setEvictionAttributes(parent.getEvictionAttributes());
        }
    }
    if (!hasPoolName()) {
        setPoolName(parent.getPoolName());
    }
    if (!hasDiskStoreName()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasDiskStoreName()) {
                setDiskStoreName(parent.getDiskStoreName());
            }
        } else {
            setDiskStoreName(parent.getDiskStoreName());
        }
    }
    if (!hasDiskSynchronous()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasDiskSynchronous()) {
                setDiskSynchronous(parent.isDiskSynchronous());
            }
        } else {
            setDiskSynchronous(parent.isDiskSynchronous());
        }
    }
    if (!hasCompressor()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasCompressor()) {
                setCompressor(parent.getCompressor());
            }
        } else {
            setCompressor(parent.getCompressor());
        }
    }
    if (!hasConcurrencyChecksEnabled()) {
        if (parentIsUserSpecified) {
            if (parentWithHas.hasConcurrencyChecksEnabled()) {
                setConcurrencyChecksEnabled(parent.getConcurrencyChecksEnabled());
            }
        } else {
            setConcurrencyChecksEnabled(parent.getConcurrencyChecksEnabled());
        }
    }
    if (!hasMulticastEnabled()) {
        // bug #38836 - inherit multicast setting
        if (parentIsUserSpecified) {
            if (parentWithHas.hasMulticastEnabled()) {
                setMulticastEnabled(parent.getMulticastEnabled());
            }
        } else {
            setMulticastEnabled(parent.getMulticastEnabled());
        }
    }
}
Also used : UserSpecifiedRegionAttributes(org.apache.geode.internal.cache.UserSpecifiedRegionAttributes) InternalClientCache(org.apache.geode.cache.client.internal.InternalClientCache) RegionAttributes(org.apache.geode.cache.RegionAttributes) UserSpecifiedRegionAttributes(org.apache.geode.internal.cache.UserSpecifiedRegionAttributes) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl)

Example 2 with InternalClientCache

use of org.apache.geode.cache.client.internal.InternalClientCache in project geode by apache.

the class JUnit4CacheTestCase method getClientCache.

/**
   * Creates a client cache from the factory if one does not already exist.
   *
   * @since GemFire 6.5
   */
public final InternalClientCache getClientCache(final ClientCacheFactory factory) {
    synchronized (JUnit4CacheTestCase.class) {
        final GemFireCacheImpl gemFireCache = GemFireCacheImpl.getInstance();
        if (gemFireCache != null && !gemFireCache.isClosed() && gemFireCache.getCancelCriterion().isCancelInProgress()) {
            Wait.waitForCriterion(new // TODO: replace with Awaitility
            WaitCriterion() {

                @Override
                public boolean done() {
                    return gemFireCache.isClosed();
                }

                @Override
                public String description() {
                    return "waiting for cache to close";
                }
            }, 30 * 1000, 300, true);
        }
        if (cache == null || cache.isClosed()) {
            cache = null;
            disconnectFromDS();
            cache = (InternalCache) factory.create();
        }
        if (cache != null) {
            IgnoredException.addIgnoredException("java.net.ConnectException");
        }
        return (InternalClientCache) cache;
    }
}
Also used : InternalClientCache(org.apache.geode.cache.client.internal.InternalClientCache) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl)

Example 3 with InternalClientCache

use of org.apache.geode.cache.client.internal.InternalClientCache in project geode by apache.

the class ClientCacheFactory method basicCreate.

private ClientCache basicCreate() {
    synchronized (ClientCacheFactory.class) {
        InternalClientCache instance = GemFireCacheImpl.getInstance();
        {
            String propValue = this.dsProps.getProperty(MCAST_PORT);
            if (propValue != null) {
                int mcastPort = Integer.parseInt(propValue);
                if (mcastPort != 0) {
                    throw new IllegalStateException("On a client cache the mcast-port must be set to 0 or not set. It was set to " + mcastPort);
                }
            }
        }
        {
            String propValue = this.dsProps.getProperty(LOCATORS);
            if (propValue != null && !propValue.isEmpty()) {
                throw new IllegalStateException("On a client cache the locators property must be set to an empty string or not set. It was set to \"" + propValue + "\".");
            }
        }
        this.dsProps.setProperty(MCAST_PORT, "0");
        this.dsProps.setProperty(LOCATORS, "");
        DistributedSystem system = DistributedSystem.connect(this.dsProps);
        if (instance != null && !instance.isClosed()) {
            // this is ok; just make sure it is a client cache
            if (!instance.isClient()) {
                throw new IllegalStateException("A client cache can not be created because a non-client cache already exists.");
            }
            // check if pool is compatible
            Pool pool = instance.determineDefaultPool(this.pf);
            if (pool == null) {
                if (instance.getDefaultPool() != null) {
                    throw new IllegalStateException("Existing cache's default pool was not compatible");
                }
            }
            // Check if cache configuration matches.
            cacheConfig.validateCacheConfig(instance);
            return instance;
        } else {
            return GemFireCacheImpl.createClient(system, this.pf, cacheConfig);
        }
    }
}
Also used : InternalClientCache(org.apache.geode.cache.client.internal.InternalClientCache) DistributedSystem(org.apache.geode.distributed.DistributedSystem)

Aggregations

InternalClientCache (org.apache.geode.cache.client.internal.InternalClientCache)3 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)2 RegionAttributes (org.apache.geode.cache.RegionAttributes)1 DistributedSystem (org.apache.geode.distributed.DistributedSystem)1 UserSpecifiedRegionAttributes (org.apache.geode.internal.cache.UserSpecifiedRegionAttributes)1