示例#1
0
        public void NewAPI()
        {
            // 1. Create a cache
            CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();

            cacheFactory.SetSubscriptionEnabled(true);
            Cache cache = cacheFactory.Create();


            GemStone.GemFire.Cache.PoolFactory poolFactory = GemStone.GemFire.Cache.PoolManager.CreateFactory();
            poolFactory.AddServer("localhost", 40404);
            poolFactory.SetSubscriptionEnabled(true);
            poolFactory.Create("examplePool");

            // 2. Create default region attributes using region factory
            RegionFactory regionFactory =
                cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);

            regionFactory.SetPoolName("examplePool");



            // 3. Create region
            Region region = regionFactory.Create("exampleregion");

            region.RegisterRegex("Keys-*", false, null, true);
        }
示例#2
0
        static void TestDistributedSystem(Cache cache, String hostname, int port, String poolName, String regionName)
        {
            //create pool factory to create the pool.
            PoolFactory fact = PoolManager.CreateFactory();

            //adding host(endpoint) in pool
            fact.AddServer(hostname, port);

            //enabling subscription on pool
            fact.SetSubscriptionEnabled(true);

            //creating pool with name "examplePool"
            fact.Create(poolName);

            RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);

            IRegion <string, string> region = regionFactory.SetPoolName(poolName).Create <string, string>(regionName);

            Console.WriteLine("Created a generic Region.");

            // Put an Entry (Key and Value pair) into the Region using the IDictionary interface.
            region["Key1"] = "Value1";

            Console.WriteLine("Put the first Entry into the Region");

            // Put another Entry into the Region.
            region["123"] = "123";

            Console.WriteLine("Put the second Entry into the Region");

            // Get Entries back out of the Region.
            string result1 = region["Key1"];

            Console.WriteLine("Obtained the first Entry from the Region");

            string result2 = region["123"];

            Console.WriteLine("Obtained the second Entry from the Region");

            // Invalidate an Entry in the Region.
            region.Invalidate("Key1");

            Console.WriteLine("Invalidated the first Entry in the Region");

            // Destroy an Entry in the Region using the IDictionary interface.
            region.Remove("123");

            Console.WriteLine("Destroyed the second Entry in the Region");
        }
示例#3
0
        static void Main(string[] args)
        {
            try
            {
                // Create CacheFactory using the settings from the gfcpp.properties file by default.
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();

                Console.WriteLine("Created CacheFactory");

                // Create a Geode Cache.
                Cache cache = cacheFactory.SetSubscriptionEnabled(true).Create();

                Console.WriteLine("Created the Geode Cache");

                //Create Poolfactory with endpoint and then create pool using poolfactory.
                PoolFactory pfact = PoolManager.CreateFactory();
                Pool        pptr  = pfact.AddServer("localhost", 40404).Create("examplePool");

                RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);

                Console.WriteLine("Created the Regionfactory");

                // Create the example Region programmatically.
                IRegion <string, string> region = regionFactory.SetPoolName("examplePool").Create <string, string>("exampleRegion");

                Console.WriteLine("Created the Region Programmatically");

                // Put an Entry (Key and Value pair) into the Region using the direct/shortcut method.
                region["Key1"] = "Value1";

                Console.WriteLine("Put the first Entry into the Region");

                // Put an Entry into the Region by manually creating a Key and a Value pair.
                string key   = "key-123";
                string value = "val-123";
                region[key] = value;

                Console.WriteLine("Put the second Entry into the Region");

                // Get Entries back out of the Region.
                string result1 = region["Key1"];

                Console.WriteLine("Obtained the first Entry from the Region");

                string result2 = region[key];

                Console.WriteLine("Obtained the second Entry from the Region");

                // Invalidate an Entry in the Region.
                region.Invalidate("Key1");

                Console.WriteLine("Invalidated the first Entry in the Region");

                // Destroy an Entry in the Region.
                region.Remove(key);

                Console.WriteLine("Destroyed the second Entry in the Region");

                // Close the Geode Cache.
                cache.Close();

                Console.WriteLine("Closed the Geode Cache");
            }
            // An exception should not occur
            catch (GeodeException gfex)
            {
                Console.WriteLine("PoolWithEndpoints Geode Exception: {0}", gfex.Message);
            }
        }