/** * Choose a random DiskStore and set it in the attributes factory. * * @param baseAttr The region attributes we start with (without a DiskStore set) * @param attrFac The attributes factory to set the DiskStore in. * @param diskStoreNames A List of potential DiskStore names to choose from. * @param rand The random number generator used while creating regions and attributes. */ public static void setRandomDiskStore( RegionAttributes baseAttr, AttributesFactory attrFac, List<String> diskStoreNames, GsRandom rand) { if ((baseAttr.getDiskStoreName() != null) && (baseAttr .getDiskStoreName() .equals("notUsed"))) { // disk store should be chosen randomly // setting the diskStoreName to unused is a signal that we do need a disk store and to choose // randomly String diskStoreName = diskStoreNames.get(rand.nextInt(1, diskStoreNames.size() - 1)); if (diskStoreName.equals("unused")) { throw new TestException("Error in test, diskStoreName is " + diskStoreName); } Log.getLogWriter().info("Test is setting diskStoreName to " + diskStoreName); attrFac.setDiskStoreName(diskStoreName); } }
/** * Create the DiskStore if the RegionAttributes specifies it. * * @param attr The RegionAttributes that could specify a DiskStore. * @return A String description of the DiskStore, useful for logging. */ public static String createDiskStore(RegionAttributes attr) { String diskDirsStr = ""; Log.getLogWriter().info("DiskStore name in attributes is " + attr.getDiskStoreName()); if ((attr.getDiskStoreName() != null) && (!attr.getDiskStoreName().equals("notUsed"))) { Log.getLogWriter().info("Creating diskStore " + attr.getDiskStoreName()); DiskStoreFactory dsFactory = DiskStoreHelper.getDiskStoreFactory(attr.getDiskStoreName()); dsFactory.create(attr.getDiskStoreName()); File[] diskDirs = CacheHelper.getCache().findDiskStore(attr.getDiskStoreName()).getDiskDirs(); for (File diskDir : diskDirs) { diskDirsStr = diskDirsStr + diskDir.getName() + " "; } diskDirsStr = " with disk dirs " + diskDirsStr; } return "disk store name is " + attr.getDiskStoreName() + " " + diskDirsStr; }
public RegionAttributesInfo(RegionAttributes<?, ?> ra) { cloningEnabled = ra.getCloningEnabled(); concurrencyChecksEnabled = ra.getConcurrencyChecksEnabled(); concurrencyLevel = ra.getConcurrencyLevel(); dataPolicy = ra.getDataPolicy(); diskStoreName = ra.getDiskStoreName(); enableAsyncConflation = ra.getEnableAsyncConflation(); enableGateway = ra.getEnableGateway(); enableSubscriptionConflation = ra.getEnableSubscriptionConflation(); gatewayHubId = ra.getGatewayHubId(); ignoreJTA = ra.getIgnoreJTA(); indexMaintenanceSynchronous = ra.getIndexMaintenanceSynchronous(); initialCapacity = ra.getInitialCapacity(); loadFactor = ra.getLoadFactor(); multicastEnabled = ra.getMulticastEnabled(); poolName = ra.getPoolName(); scope = ra.getScope(); statisticsEnabled = ra.getStatisticsEnabled(); entryTimeToLive = ra.getEntryTimeToLive().getTimeout(); isLockGrantor = ra.isLockGrantor(); entryIdleTimeout = ra.getEntryIdleTimeout().getTimeout(); regionIdleTimeout = ra.getRegionIdleTimeout().getTimeout(); regionTimeToLive = ra.getRegionTimeToLive().getTimeout(); Compressor compressor = ra.getCompressor(); if (compressor != null) { compressorClassName = compressor.getClass().getCanonicalName(); } ExpirationAction expAction = ra.getEntryIdleTimeout().getAction(); if (expAction != null) { entryIdleTimeoutAction = expAction.toString(); } expAction = ra.getEntryTimeToLive().getAction(); if (expAction != null) { entryTimeToLiveAction = expAction.toString(); } expAction = ra.getRegionTimeToLive().getAction(); if (expAction != null) { regionTimeToLiveAction = expAction.toString(); } expAction = ra.getRegionIdleTimeout().getAction(); if (expAction != null) { regionIdleTimeoutAction = expAction.toString(); } // Collecting information about all the CacheListeners, CacheWriters, CacheLoaders CacheListener<?, ?>[] cacheListeners = ra.getCacheListeners(); // TODO: The cacheListeners should be added one by one by delimited by a "\n" if (cacheListeners.length > 0) { cacheListenerClassNames = new ArrayList<String>(); for (CacheListener<?, ?> cacheListener : cacheListeners) { cacheListenerClassNames.add(cacheListener.getClass().getCanonicalName()); } Collections.sort(cacheListenerClassNames); } // CacheLoader CacheLoader<?, ?> cacheLoader = ra.getCacheLoader(); if (cacheLoader != null) { cacheLoaderClassName = cacheLoader.getClass().getCanonicalName(); } // CacheWriter CacheWriter<?, ?> cacheWriter = ra.getCacheWriter(); if (cacheWriter != null) { cacheWriterClassName = cacheWriter.getClass().getCanonicalName(); } // Setting the Partition Attributes and Eviction Attributes PartitionAttributes<?, ?> partitionAttributes = ra.getPartitionAttributes(); EvictionAttributes evictionAttributes = ra.getEvictionAttributes(); if (partitionAttributes != null) partitionAttributesInfo = new PartitionAttributesInfo(partitionAttributes); if (evictionAttributes != null) { evictionAttributesInfo = new EvictionAttributesInfo(evictionAttributes); } }
@Override protected Region<K, V> lookupFallback(GemFireCache cache, String regionName) throws Exception { Assert.isTrue(cache instanceof ClientCache, "Unable to create regions from " + cache); ClientCache c = (ClientCache) cache; // first look at shortcut ClientRegionShortcut s = null; if (shortcut == null) { if (dataPolicy != null) { if (DataPolicy.EMPTY.equals(dataPolicy)) { s = ClientRegionShortcut.PROXY; } else if (DataPolicy.PERSISTENT_REPLICATE.equals(dataPolicy)) { s = ClientRegionShortcut.LOCAL_PERSISTENT; } } s = ClientRegionShortcut.LOCAL; } else { s = shortcut; } ClientRegionFactory<K, V> factory = c.createClientRegionFactory(s); // map the attributes onto the client if (attributes != null) { CacheListener<K, V>[] listeners = attributes.getCacheListeners(); if (!ObjectUtils.isEmpty(listeners)) { for (CacheListener<K, V> listener : listeners) { factory.addCacheListener(listener); } } factory.setCloningEnabled(attributes.getCloningEnabled()); factory.setConcurrencyLevel(attributes.getConcurrencyLevel()); factory.setCustomEntryIdleTimeout(attributes.getCustomEntryIdleTimeout()); factory.setCustomEntryTimeToLive(attributes.getCustomEntryTimeToLive()); factory.setDiskStoreName(attributes.getDiskStoreName()); factory.setDiskSynchronous(attributes.isDiskSynchronous()); factory.setEntryIdleTimeout(attributes.getEntryIdleTimeout()); factory.setEntryTimeToLive(attributes.getEntryTimeToLive()); factory.setEvictionAttributes(attributes.getEvictionAttributes()); factory.setInitialCapacity(attributes.getInitialCapacity()); factory.setKeyConstraint(attributes.getKeyConstraint()); factory.setLoadFactor(attributes.getLoadFactor()); factory.setPoolName(attributes.getPoolName()); factory.setRegionIdleTimeout(attributes.getRegionIdleTimeout()); factory.setRegionTimeToLive(attributes.getRegionTimeToLive()); factory.setStatisticsEnabled(attributes.getStatisticsEnabled()); factory.setValueConstraint(attributes.getValueConstraint()); } if (!ObjectUtils.isEmpty(cacheListeners)) { for (CacheListener<K, V> listener : cacheListeners) { factory.addCacheListener(listener); } } if (StringUtils.hasText(poolName)) { // try to eagerly initialize the pool name, if defined as a bean if (beanFactory.isTypeMatch(poolName, Pool.class)) { if (log.isDebugEnabled()) { log.debug( "Found bean definition for pool '" + poolName + "'. Eagerly initializing it..."); } beanFactory.getBean(poolName, Pool.class); } factory.setPoolName(poolName); } Region<K, V> reg = factory.create(regionName); log.info("Created new cache region [" + regionName + "]"); if (snapshot != null) { reg.loadSnapshot(snapshot.getInputStream()); } return reg; }