private void ConnectToCloudCache()
        {
            JObject vcapJson = JObject.Parse(Environment.GetEnvironmentVariable("VCAP_SERVICES"));

            Cache cache = new CacheFactory()
                          .SetAuthInitialize(
                new UsernamePassword(
                    (string)vcapJson.SelectToken(Constants.jsonPathUsername),
                    (string)vcapJson.SelectToken(Constants.jsonPathPassword)))
                          .Create();

            cache.TypeRegistry.PdxSerializer = new ReflectionBasedAutoSerializer();

            PoolFactory pool = cache.GetPoolFactory();

            foreach (string locator in vcapJson.SelectToken(Constants.jsonPathLocators).Select(s => (string)s).ToArray())
            {
                string[] hostPort = locator.Split('[', ']');
                pool.AddLocator(hostPort[0], Int32.Parse(hostPort[1]));
            }
            pool.Create("pool");

            region = cache.CreateRegionFactory(RegionShortcut.PROXY)
                     .SetPoolName("pool")
                     .Create <string, Book>("owinexample");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var cache = new CacheFactory()
                        .Set("log-level", "none").Create();

            var poolFactory = cache.GetPoolFactory()
                              .AddLocator("localhost", 10334);

            Console.WriteLine("Created cache");

            poolFactory.Create("pool");

            var regionFactory = cache.CreateRegionFactory(RegionShortcut.PROXY)
                                .SetPoolName("pool");
            var region = regionFactory.Create <string, int>("exampleRegion");

            Console.WriteLine("Created region 'exampleRegion'");

            var retries = 5;

            while (retries-- > 0)
            {
                try
                {
                    cache.CacheTransactionManager.Begin();
                    foreach (var key in keys)
                    {
                        var value = getValueFromExternalSystem();
                        region.Put(key, value);
                    }
                    cache.CacheTransactionManager.Commit();
                    Console.WriteLine("Committed transaction - exiting");
                    break;
                } catch
                {
                    cache.CacheTransactionManager.Rollback();
                    Console.WriteLine("Rolled back transaction - retrying({0})", retries);
                }
            }
        }
        private void ConnectToCloudCache()
        {
            JObject vcapJson = JObject.Parse(Environment.GetEnvironmentVariable("VCAP_SERVICES"));

            /**
             * JObject vcapJson = new JObject
             * {
             *  { "locators", "192.168.12.52[55221]" },
             *  { "username", "cluster_operator_57Z2ueingjHQrgwIAB389w" },
             *  { "password", "CTl9gZJlIoS0m2BUdWpQ" }
             * };
             **/

            Cache cache = new CacheFactory()
                          .Set("log-level", "debug")
                          .Set("log-file", "pccpad.log")
                          .SetAuthInitialize(
                new UsernamePassword(
                    (string)vcapJson.SelectToken(Constants.jsonPathUsername),
                    (string)vcapJson.SelectToken(Constants.jsonPathPassword)))
                          .Create();

            cache.TypeRegistry.PdxSerializer = new ReflectionBasedAutoSerializer();

            PoolFactory pool = cache.GetPoolFactory();

            foreach (string locator in vcapJson.SelectToken(Constants.jsonPathLocators).Select(s => (string)s).ToArray())
            {
                string[] hostPort = locator.Split('[', ']');
                pool.AddLocator(hostPort[0], Int32.Parse(hostPort[1]));
            }
            globalpool = pool.Create("pool");

            region = cache.CreateRegionFactory(RegionShortcut.PROXY)
                     .SetPoolName("pool")
                     .Create <int, Customer>("customer");
        }