public static Apache.Geode.Client.Cache getCache()
        {
            const string PwD_PASS_PROP = "SSL-KEYSTORE-PASSWORD";

            String password = Environment.GetEnvironmentVariable(PwD_PASS_PROP);

            if (password == null)
            {
                Console.WriteLine("ERROR:" + PwD_PASS_PROP + " environment variable required");
                Environment.Exit(-1);
            }

            // Environment.GetEnvironmentVariable(PwD_PASS_PROP);
            string locatorHost = Environment.GetEnvironmentVariable("LOCATOR_HOST");

            if (locatorHost == null)
            {
                Console.WriteLine("ERROR:LOCATOR_HOST environment variable required");
                Environment.Exit(-1);
            }

            Apache.Geode.Client.Properties <string, string> cacheProps = new Apache.Geode.Client.Properties <string, string>();

            cacheProps.Insert("log-level", "error");
            cacheProps.Insert("ssl-enabled", "true");

            cacheProps.Insert("ssl-truststore", @"Z:\Projects\LifeSciences\Humana\dev\DigitalIT\NET\geode-NET-client-TwoWaySSL\cert\ca.cert.pem");
            cacheProps.Insert("ssl-keystore", @"Z:\Projects\LifeSciences\Humana\dev\DigitalIT\NET\geode-NET-client-TwoWaySSL\cert\client.pem");
            cacheProps.Insert("ssl-keystore-password", "secretpassword");

            if (!File.Exists(cacheProps.Find("ssl-keystore")))
            {
                Console.WriteLine("ssl-keystore  does not exists");
                Environment.Exit(-1);
            }

            if (!File.Exists(cacheProps.Find("ssl-truststore")))
            {
                Console.WriteLine("ssl-truststore  does not exists");
                Environment.Exit(-1);
            }

            Apache.Geode.Client.CacheFactory factory = Apache.Geode.Client.CacheFactory.CreateCacheFactory(cacheProps);
            factory.AddLocator(locatorHost, 10000);
            Apache.Geode.Client.Cache cache = factory.Create();

            return(cache);
        }        //-------------------------------------------------------
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                // Create a Geode Cache.
                Apache.Geode.Client.CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();

                Cache cache = cacheFactory.Set("cache-xml-file", "XMLs/clientHACache.xml")
                              .AddServer("localhost", 40404)
                              .AddServer("localhost", 40405)
                              .SetSubscriptionRedundancy(1)
                              .SetSubscriptionEnabled(true)
                              .Create();

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

                // Get the example Region from the Cache which is declared in the Cache XML file.
                IRegion <object, int> region = cache.GetRegion <object, int>("/exampleRegion");

                Console.WriteLine("Obtained the generic Region from the Cache");

                // Register and Unregister Interest on Region for Some Keys.
                object [] keys = new object[] { 123, "Key-123" };
                region.GetSubscriptionService().RegisterKeys(keys);
                region.GetSubscriptionService().RegisterRegex("Keys.*");

                Console.WriteLine("Called RegisterKeys() and RegisterRegex()");

                region[123]       = 1;
                region["Key-123"] = 2;

                Console.WriteLine("Called put() on Region");

                Console.WriteLine("Waiting for updates on keys");
                Thread.Sleep(10000);

                int count = 0;

                //try to get the entries for keys destroyed by server.
                try
                {
                    int value1 = region[123];
                    Console.WriteLine("UNEXPECTED: First get should not have succeeded");
                }
                catch (KeyNotFoundException) {
                    Console.WriteLine("gfex.Message: Verified that key1 has been destroyed");
                    count++;
                }

                try
                {
                    int value2 = region["Key-123"];
                    Console.WriteLine("UNEXPECTED: Second get should not have succeeded");
                }
                catch (KeyNotFoundException)
                {
                    Console.WriteLine("gfex.Message: Verified that key2 has been destroyed");
                    count++;
                }

                if (count == 2)
                {
                    Console.WriteLine("Verified all updates");
                }
                else
                {
                    Console.WriteLine("Could not verify all updates");
                }

                region.GetSubscriptionService().UnregisterKeys(keys);
                region.GetSubscriptionService().UnregisterRegex("Keys.*");

                Console.WriteLine("Unregistered keys");

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

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