Ejemplo n.º 1
0
        private void SetCacheWriter(string regionName, ICacheWriter <string, string> writer)
        {
            GIRegion region = CacheHelper.GetVerifyRegion <string, string>(regionName);
            AttributesMutator <string, string> attrMutator = region.AttributesMutator;

            attrMutator.SetCacheWriter(writer);
        }
        public void CreateRegion(string locators, bool caching,
                                 bool listener, bool writer)
        {
            Util.Log(" in CreateRegion " + listener + " : " + writer);
            if (listener)
            {
                m_listener = new TallyListener <object, object>();
            }
            else
            {
                m_listener = null;
            }
            IRegion <object, object> region = null;

            region = CacheHelper.CreateTCRegion_Pool <object, object>(RegionName, true, caching,
                                                                      m_listener, locators, "__TESTPOOL1_", true);

            if (writer)
            {
                m_writer = new TallyWriter <object, object>();
            }
            else
            {
                m_writer = null;
            }
            Util.Log("region created  ");
            AttributesMutator <object, object> at = region.AttributesMutator;

            at.SetCacheWriter(m_writer);
        }
Ejemplo n.º 3
0
        public void CreateRegion(string locators,
                                 bool caching, bool listener, bool writer)
        {
            if (listener)
            {
                m_listener = new TallyListener <int, object>();
            }
            else
            {
                m_listener = null;
            }
            GIRegion region = null;

            region = CacheHelper.CreateTCRegion_Pool <int, object>(RegionName, true, caching,
                                                                   m_listener, locators, "__TESTPOOL1_", true);
            if (listener)
            {
                m_listener.SetCallBackArg(key0);
            }

            if (writer)
            {
                m_writer = new TallyWriter <int, object>();
            }
            else
            {
                m_writer = null;
            }
            if (writer)
            {
                AttributesMutator <int, object> at = region.AttributesMutator;
                at.SetCacheWriter(m_writer);
                m_writer.SetCallBackArg(key0);
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            try
            {
                // Create a Geode Cache.
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();

                Cache cache = cacheFactory.Set("cache-xml-file", "XMLs/clientLoaderListenerWriter.xml")
                              .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 <string, string> region = cache.GetRegion <string, string>("/exampleRegion");

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

                // Plugin the SimpleCacheLoader, SimpleCacheListener and SimpleCacheWrite to the Region.
                AttributesMutator <string, string> attrMutator = region.AttributesMutator;
                attrMutator.SetCacheLoader(new SimpleCacheLoader <string, string>());
                attrMutator.SetCacheListener(new SimpleCacheListener <string, string>());
                attrMutator.SetCacheWriter(new SimpleCacheWriter <string, string>());

                Console.WriteLine("Attached the simple generic plugins on the Region");

                // The following operations should cause the plugins to print the events.

                // Put 3 Entries into the Region using the IDictionary interface.
                region["Key1"] = "Value1";
                region["Key2"] = "Value2";
                region["Key3"] = "Value3";

                Console.WriteLine("Put 3 Entries into the Region");

                // Update Key3.
                region["Key3"] = "Value3-Updated";

                // Destroy Key3 using the IDictionary interface.
                region.Remove("Key3");

                // Invalidate Key2.
                region.Invalidate("Key2");

                string value = null;

                try
                {
                    // Get a new Key.
                    value = region["Key4"];
                }
                catch (KeyNotFoundException knfex)
                {
                    Console.WriteLine("Got expected KeyNotFoundException: {0}", knfex.Message);
                }

                try
                {
                    // Get a destroyed Key.
                    value = region["Key3"];
                }
                catch (KeyNotFoundException knfex)
                {
                    Console.WriteLine("Got expected KeyNotFoundException: {0}", knfex.Message);
                }

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

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