protected override Region LookupFallback(Cache cacheObject, string regionName) { AttributesFactory attributesFactory = (attributes != null ? new AttributesFactory(attributes) : new AttributesFactory()); if (endpoints != null) { attributesFactory.SetEndpoints(endpoints); } if (poolName != null) { attributesFactory.SetPoolName(poolName); } SetCallbacks(attributesFactory); SetDistributionProperties(attributesFactory); PostProcessAttributes(attributesFactory); Region reg = cacheObject.CreateRegion(regionName, attributesFactory.CreateRegionAttributes()); log.Info("Created new cache region [" + regionName + "]"); return(reg); }
public void AfterPropertiesSet() { if (cachingEnabled != null) { attributesFactory.SetCachingEnabled(cachingEnabled.Value); } if (clientNotificationEnabled != null) { attributesFactory.SetClientNotificationEnabled(clientNotificationEnabled.Value); } if (lruEntriesLimit != null) { attributesFactory.SetLruEntriesLimit(lruEntriesLimit.Value); } if (cloningEnabled != null) { attributesFactory.SetCloningEnabled(cloningEnabled.Value); } SetStorageProperties(attributesFactory); SetExpirationProperties(attributesFactory); gemfireRegionAttributes = attributesFactory.CreateRegionAttributes(); }
public void CreateRegion(string name, bool enableNotification, bool cloningEnabled) { Apache.Geode.Client.RegionAttributes <object, object> attrs; AttributesFactory <object, object> attrFac = new AttributesFactory <object, object>(); attrFac.SetCacheListener(new SimpleCacheListener <object, object>()); attrFac.SetCloningEnabled(cloningEnabled); attrs = attrFac.CreateRegionAttributes(); CacheHelper.CreateRegion <object, object>(name, attrs); }
public void CreateRegionWithTallyLoader(ScopeType scope) { AttributesFactory af = new AttributesFactory(); af.SetCacheLoader(m_ldr); af.SetScope(scope); af.SetCachingEnabled(true); m_region = CacheHelper.CreateRegion(TestRegion, af.CreateRegionAttributes()); }
public void CreateRegionWithTallyWriter(ScopeType scope) { AttributesFactory af = new AttributesFactory(); af.SetCacheWriter(m_lwr); af.SetScope(scope); af.SetCachingEnabled(true); m_netWriteRegion = CacheHelper.CreateRegion(TestRegionWrite, af.CreateRegionAttributes()); }
private Region CreateRegion() { DistributedSystem dsys = DistributedSystem.Connect("exampleregion"); Cache cache = CacheFactory.Create("exampleregion", dsys); AttributesFactory attributesFactory = new AttributesFactory(); attributesFactory.SetScope(ScopeType.Local); attributesFactory.SetCachingEnabled(true); RegionAttributes regionAttributes = attributesFactory.CreateRegionAttributes(); return cache.CreateRegion("exampleregion", regionAttributes); }
private Region CreateRegion() { DistributedSystem dsys = DistributedSystem.Connect("exampleregion"); Cache cache = CacheFactory.Create("exampleregion", dsys); AttributesFactory attributesFactory = new AttributesFactory(); attributesFactory.SetScope(ScopeType.Local); attributesFactory.SetCachingEnabled(true); RegionAttributes regionAttributes = attributesFactory.CreateRegionAttributes(); return(cache.CreateRegion("exampleregion", regionAttributes)); }
public void RegionThreeLoadEntries(int num) { AttributesFactory af = new AttributesFactory(); af.SetScope(ScopeType.Local); af.SetCacheLoader(m_ldr); m_region = CacheHelper.CreateRegion(TestRegion, af.CreateRegionAttributes()); m_ldr.Reset(); Thread.Sleep(100); DoGets(m_region, num); Assert.AreEqual(num, m_ldr.Loads); IGFSerializable[] arr = m_region.GetKeys(); Assert.AreEqual(num, arr.Length); }
public void RegionLookup() { Cache cache = (Cache) ctx["gemfire-cache"]; AttributesFactory attributesFactory = new AttributesFactory(); attributesFactory.SetScope(ScopeType.Local); attributesFactory.SetCachingEnabled(true); RegionAttributes regionAttributes = attributesFactory.CreateRegionAttributes(); Region existing = cache.CreateRegion("existing", regionAttributes); Assert.IsTrue(ctx.ContainsObject("lookup")); RegionLookupFactoryObject regionLookupFactoryObject = (RegionLookupFactoryObject)ctx.GetObject("&lookup"); Assert.AreEqual("existing", TestUtils.ReadField<string>("name", regionLookupFactoryObject)); //TODO SGFNET-20: existing is not registered as an alias with lookup/. //Assert.AreEqual(ctx.GetObject("existing"), ctx.GetObject("lookup")); }
public void Hello() { DistributedSystem dsys = DistributedSystem.Connect("exampledstest"); Cache cache = CacheFactory.Create("exampledscache", dsys); AttributesFactory af = new AttributesFactory(); af.SetClientNotificationEnabled(true); af.SetEndpoints("localhost:40404"); RegionAttributes rAttrib = af.CreateRegionAttributes(); Region region = cache.CreateRegion("exampledsregion", rAttrib); region.RegisterAllKeys(); cache.Close(); }
public void SampleUsage() { // 1. Connect to system Console.WriteLine("{0}Connecting to GemFire", Environment.NewLine); DistributedSystem dsys = DistributedSystem.Connect("exampleregion"); // 2. Create a cache Cache cache = CacheFactory.Create("exampleregion", dsys); // 3. Create default region attributes AttributesFactory af = new AttributesFactory(); RegionAttributes rAttrib = af.CreateRegionAttributes(); // 4. Create region Region region = cache.CreateRegion("exampleregion", rAttrib); }
public void Foo() { // 1. Connect to system Console.WriteLine("{0}Connecting to GemFire", Environment.NewLine); DistributedSystem dsys = DistributedSystem.Connect("exampleregion"); // 2. Create a cache Cache cache = CacheFactory.Create("exampleregion", dsys); // 3. Create default region attributes AttributesFactory af = new AttributesFactory(); RegionAttributes rAttrib = af.CreateRegionAttributes(); // 4. Create region Region region = cache.CreateRegion("exampleregion", rAttrib); }
public void RegionLookup() { Cache cache = (Cache)ctx["gemfire-cache"]; AttributesFactory attributesFactory = new AttributesFactory(); attributesFactory.SetScope(ScopeType.Local); attributesFactory.SetCachingEnabled(true); RegionAttributes regionAttributes = attributesFactory.CreateRegionAttributes(); Region existing = cache.CreateRegion("existing", regionAttributes); Assert.IsTrue(ctx.ContainsObject("lookup")); RegionLookupFactoryObject regionLookupFactoryObject = (RegionLookupFactoryObject)ctx.GetObject("&lookup"); Assert.AreEqual("existing", TestUtils.ReadField <string>("name", regionLookupFactoryObject)); //TODO SGFNET-20: existing is not registered as an alias with lookup/. //Assert.AreEqual(ctx.GetObject("existing"), ctx.GetObject("lookup")); }
public void StepTwoCallbacks() { AttributesFactory <string, string> af = new AttributesFactory <string, string>(); GIRegion region = CacheHelper.CreateRegion <string, string>(PeerRegionName, af.CreateRegionAttributes()); CreateEntry(RegionNames[0], m_keys[1], m_vals[1]); CreateEntry(RegionNames[1], m_keys[3], m_vals[3]); SetCacheLoader(RegionNames[0], new ThinClientTallyLoader()); SetCacheLoader(RegionNames[1], new ThinClientTallyLoader()); Assert.IsNotNull(GetEntry(RegionNames[0], m_keys[0]), "Found null value in region0."); Assert.IsNotNull(GetEntry(RegionNames[1], m_keys[0]), "Found null value in region1."); }
private IRegion <object, object> CreateSubRegion(IRegion <object, object> region, string subRegionName, string libraryName, string factoryFunctionName) { AttributesFactory <object, object> attrsFact = new AttributesFactory <object, object>(region.Attributes); Properties <string, string> sqliteProperties = new Properties <string, string>(); sqliteProperties.Insert("PageSize", "65536"); sqliteProperties.Insert("MaxPageCount", "512000000"); String sqlite_dir = "SqLiteDir" + Process.GetCurrentProcess().Id.ToString(); sqliteProperties.Insert("PersistenceDirectory", sqlite_dir); attrsFact.SetPersistenceManager(libraryName, factoryFunctionName, sqliteProperties); IRegion <object, object> subRegion = region.CreateSubRegion(subRegionName, attrsFact.CreateRegionAttributes()); Assert.IsNotNull(subRegion, "Expected region to be non null"); Assert.IsTrue(File.Exists(GetSqLiteFileName(sqlite_dir, subRegionName)), "Persistence file is not present"); DoNput(subRegion, 50); DoNget(subRegion, 50); return(subRegion); }
public void StepOneCallbacks() { m_reg1Listener1 = new TallyListener <string, string>(); m_reg2Listener1 = new TallyListener <string, string>(); m_reg1Loader1 = new ThinClientTallyLoader(); m_reg2Loader1 = new ThinClientTallyLoader(); m_reg1Writer1 = new TallyWriter <string, string>(); m_reg2Writer1 = new TallyWriter <string, string>(); SetCacheListener(RegionNames[0], m_reg1Listener1); SetCacheLoader(RegionNames[0], m_reg1Loader1); SetCacheWriter(RegionNames[0], m_reg1Writer1); SetCacheListener(RegionNames[1], m_reg2Listener1); SetCacheLoader(RegionNames[1], m_reg2Loader1); SetCacheWriter(RegionNames[1], m_reg2Writer1); RegisterKeys(); m_reg3Listener1 = new TallyListener <string, string>(); //m_reg3Loader1 = new TallyLoader<string, string>(); m_reg3Loader1 = new ThinClientTallyLoader(); m_reg3Writer1 = new TallyWriter <string, string>(); AttributesFactory <string, string> af = new AttributesFactory <string, string>(); GIRegion region = CacheHelper.CreateRegion <string, string>(PeerRegionName, af.CreateRegionAttributes()); SetCacheListener(PeerRegionName, m_reg3Listener1); SetCacheLoader(PeerRegionName, m_reg3Loader1); SetCacheWriter(PeerRegionName, m_reg3Writer1); // Call the loader and writer Assert.IsNotNull(GetEntry(RegionNames[0], m_keys[0]), "Found null value."); Assert.IsNotNull(GetEntry(RegionNames[1], m_keys[0]), "Found null value."); Assert.IsNotNull(GetEntry(PeerRegionName, m_keys[0]), "Found null value."); CreateEntry(PeerRegionName, m_keys[1], m_vals[1]); }
public void RegisterRegexInterest() { // 1. Connect to system Console.WriteLine("{0}Connecting to GemFire", Environment.NewLine); DistributedSystem dsys = DistributedSystem.Connect("empty"); // 2. Create a cache Cache cache = CacheFactory.Create("Cache", dsys); // 2.5 Create Pool //PoolFactory fact = PoolManager.CreateFactory(); //fact.AddServer("localhost", 40404); //fact.SetSubscriptionEnabled(true); //fact.Create("examplePool"); // 3. Create default region attributes AttributesFactory af = new AttributesFactory(); af.SetClientNotificationEnabled(true); //af.SetPoolName("examplePool"); af.SetEndpoints("localhost:40404"); RegionAttributes rAttrib = af.CreateRegionAttributes(); // 4. Create region Region region = cache.CreateRegion("empty", rAttrib); Thread.Sleep(1000); region.RegisterRegex("Keys-*", false, null, false); //RegionFactory regionFact = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY); //Region region = regionFact.Create("exampleregion"); //region.RegisterRegex(".*", false, new System.Collections.Generic.List<ICacheableKey>()); }
public static void Main() { DistributedSystem MyDistributedSystem = null; Cache MyCache = null; string sKey = null; CacheableString sValue = null; try { Console.WriteLine("* Connecting to the distributed system and creating the cache."); /* Properties can be passed to GemFire through two different mechanisms: the * Properties object as is done below or the gemfire.properties file. The * settings passed in a Properties object take precedence over any settings * in a file. This way the end-user cannot bypass any required settings. * * Using a gemfire.properties file can be useful when you want to change the * behavior of certain settings without doing a new build, test, and deploy cycle. * * See gemfire.properties for details on some of the other settings used in this * project. * * For details on all of the possible settings and their respective values * that can be specified in this configuration file, see chapter 5, * "System Configuration", in the "System Administrator's Guide". This is * installed in the docs\pdf folder under the GemFire installation folder * (e.g., C:\Program Files\Gemfire5\docs\pdf\SystemAdmin.pdf). */ Properties DistributedSystemProperties = new Properties(); DistributedSystemProperties.Insert("name", "CacheClient"); /* Specify the file whose contents are used to initialize the cache when it is created. * * An XML file isn't needed at all because everything can be specified in code--much * as the "license-file" property is. However, it provides a convenient way * to isolate common settings that can be updated without a build/test/deploy cycle. */ DistributedSystemProperties.Insert("cache-xml-file", "HierarchicalClient.xml"); /* Define where the license file is located. It is very useful to do this in * code vs. the gemfire.properties file, because it allows you to access the * license used by the GemFire installation (as pointed to by the GEMFIRE * environment variable). */ DistributedSystemProperties.Insert("license-file", "../../gfCppLicense.zip"); DistributedSystemProperties.Insert("log-file", "./csharpclient.log"); DistributedSystemProperties.Insert("log-level", "finest"); /* Override the mcast-port setting so the client runs "standalone". * The client and server must run in separate distributed systems. */ //DistributedSystemProperties.Insert("mcast-port", "0"); // Connect to the GemFire distributed system. MyDistributedSystem = DistributedSystem.Connect("LocalDS", DistributedSystemProperties); /*////////////////////////////////////////////////////////////////////////////// * * Create the cache. * * //////////////////////////////////////////////////////////////////////////////*/ // Create the cache. This causes the cache-xml-file to be parsed. MyCache = CacheFactory.Create("localCache", MyDistributedSystem); /*////////////////////////////////////////////////////////////////////////////// * * Create the region. * * //////////////////////////////////////////////////////////////////////////////*/ // Prepare the attributes needed to create a sub-region. AttributesFactory MyAttributesFactory = new AttributesFactory(); /* The "scope" determines how changes to the local cache are "broadcast" * to like-named regions in other caches. * * For native clients DistributedAck and DistributedNoAck work * identically. */ MyAttributesFactory.SetScope(ScopeType.DistributedAck); /* Endpoints is a comma delimited list of logical names, hostnames, and ports of * "server" caches with which to connect. The endpoints parameter follows this syntax: * * logicalName1=host1:port1, . . . ,logicalNameN=hostN:portN */ MyAttributesFactory.SetEndpoints("localhost:40404"); MyAttributesFactory.SetClientNotificationEnabled(true); /* Because of implementation details, it is best not to cache data in a root-level * region. There is nothing special about the name "root", it is just a good naming * convention. * * Get the "root" region from the cache and create a sub-region under it for the * data. */ Region MyExampleRegion = MyCache.GetRegion("root").CreateSubRegion( "exampleRegion", MyAttributesFactory.CreateRegionAttributes()); Console.WriteLine(String.Format("{0}* Region, {1}, was created in the cache.", Environment.NewLine, MyExampleRegion.FullPath)); Console.WriteLine("* Getting three values from the Hierarchical Server."); // Retrieve several values from the cache. for (int nCount = 0; nCount < 4; nCount++) { sKey = string.Format("Key{0}", nCount); Console.WriteLine(String.Format("* Requesting object: {0}{1}", sKey, Environment.NewLine)); /* Request the object from the cache. Because it doesn't exist in the local * cache, it will be passed to the server. Because the server doesn't have * it, the request will be passed to SimpleCacheLoader.Load(). The entry * returned is a string. */ sValue = MyExampleRegion.Get(sKey) as CacheableString; Console.WriteLine(String.Format("* Retrieved object: ({0})", sValue.ToString())); } Console.WriteLine("* If you look at the Cache Server's console, you can see the CacheListener notifications that happened in response to the gets."); Console.WriteLine("{0}---[ Press <Enter> to continue. ]---", Environment.NewLine); Console.ReadLine(); /*////////////////////////////////////////////////////////////////////////////// * * Exercise the serialization and deserialization methods. * * //////////////////////////////////////////////////////////////////////////////*/ // Demonstrate the process needed to manually deserialize the object from the cache. Console.WriteLine(string.Format("* Manually deserializing the object for Key0: ({0})", MyExampleRegion.Get("Key0"))); // Demonstrate the static FromCache method in the CachedItem class and modify the object. Console.WriteLine("* Using the FromCache() method and modifying the object for Key0"); // Get the item. //sValue = (CacheableString)MyExampleRegion.Get("Key0"); sValue = MyExampleRegion.Get("Key0") as CacheableString; Console.WriteLine(string.Format("* Original value: ({0})", sValue.ToString())); /* This modifies the object associated with Key0 and uses CacheSerializer * to perform manual serialization. */ String cachedItem = "PDA"; MyExampleRegion.Put("Key0", cachedItem); // Reread the object from the cache. sValue = (CacheableString)MyExampleRegion.Get("Key0"); Console.WriteLine(string.Format("* Retrieved updated object: {0}", sValue)); Console.WriteLine("* Invalidating the data for Key2"); /* Invalidating a cached item causes the object to be removed, but the * key remains in the cache. If it is subsequently requested it will * be retrieved using a CacheLoader if possible. */ MyExampleRegion.Invalidate("Key2"); Console.WriteLine("* Requesting Key2 after the invalidation."); // Request the invalidated item. sValue = (CacheableString)MyExampleRegion.Get("Key2"); Console.WriteLine(string.Format("* Retrieved object: {0}", sValue)); Console.WriteLine("* Destroying Key3"); // Destroying a cached item removes both the object and the key. MyExampleRegion.Destroy("Key3"); Console.WriteLine("{0}---[ Press <Enter> to End the Application ]---", Environment.NewLine); Console.ReadLine(); } catch (Exception ThrownException) { Console.Error.WriteLine(ThrownException.Message); Console.Error.WriteLine(ThrownException.StackTrace); Console.Error.WriteLine("---[ Press <Enter> to End the Application ]---"); Console.ReadLine(); } finally { /* While there are not any ramifications of terminating without closing the cache * and disconnecting from the distributed system, it is considered a best practice * to do so. */ try { Console.WriteLine("Closing the cache and disconnecting.{0}", Environment.NewLine); } catch { /* Ignore any exceptions */ } try { /* Close the cache. This terminates the cache and releases all the resources. * Generally speaking, after a cache is closed, any further method calls on * it or region object will throw an exception. */ MyCache.Close(); } catch { /* Ignore any exceptions */ } try { /* Disconnect from the distributed system. */ MyDistributedSystem = null; } catch { /* Ignore any exceptions */ } } }