예제 #1
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);
            }
        }
예제 #2
0
        private void SetCacheLoader(string regionName, ICacheLoader <string, string> loader)
        {
            GIRegion region = CacheHelper.GetVerifyRegion <string, string>(regionName);
            AttributesMutator <string, string> attrMutator = region.AttributesMutator;

            attrMutator.SetCacheLoader(loader);
        }
        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);
        }
예제 #4
0
        public void RunDurableClient()
        {
            // Create durable client's properties using api.
            Properties <string, string> durableProp = Properties <string, string> .Create <string, string>();

            durableProp.Insert("durable-client-id", "DurableClientId");
            durableProp.Insert("durable-timeout", "300");

            // Create a Geode Cache programmatically.
            CacheFactory cacheFactory = CacheFactory.CreateCacheFactory(durableProp);

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

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

            // Create the example Region programmatically.
            RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);

            IRegion <string, string> region = regionFactory.Create <string, string>("exampleRegion");

            Console.WriteLine("Created the generic Region programmatically.");

            // Plugin the CacheListener with afterRegionLive. "afterRegionLive()"  will be called
            // after all the queued events are recieved by client
            AttributesMutator <string, string> attrMutator = region.AttributesMutator;

            attrMutator.SetCacheListener(new DurableCacheListener <string, string>());

            Console.WriteLine("DurableCacheListener set to region.");

            // For durable Clients, Register Intrest can be durable or non durable ( default ),
            // Unregister Interest APIs remain same.

            string [] keys = new string[] { "Key-1" };
            region.GetSubscriptionService().RegisterKeys(keys, true, true);

            Console.WriteLine("Called Register Interest for Key-1 with isDurable as true");

            //Send ready for Event message to Server( only for Durable Clients ).
            //Server will send queued events to client after recieving this.
            cache.ReadyForEvents();

            Console.WriteLine("Sent ReadyForEvents message to server");

            //wait for some time to recieve events
            System.Threading.Thread.Sleep(1000);

            // Close the Geode Cache with keepalive = true.  Server will queue events for
            // durable registered keys and will deliver all events when client will reconnect
            // within timeout period and send "readyForEvents()"
            cache.Close(true);

            Console.WriteLine("Closed the Geode Cache with keepalive as true");
        }
예제 #5
0
    void registerClassCl2()
    {
      try
      {
        CacheHelper.DCache.TypeRegistry.RegisterTypeGeneric(DeltaEx.create);
      }
      catch (IllegalStateException)
      {
        //do nothing
      }
      IRegion<object, object> reg = CacheHelper.GetRegion<object, object>("DistRegionAck");

      reg.GetSubscriptionService().RegisterRegex(".*");
      AttributesMutator<object, object> attrMutator = reg.AttributesMutator;
      attrMutator.SetCacheListener(new SimpleCacheListener<object, object>());
    }
예제 #6
0
        private static void SetRegion(Region region)
        {
            m_region = region;
            RegionAttributes attrs = m_region.Attributes;

            if (attrs.ClientNotificationEnabled)
            {
                m_region.RegisterAllKeys();
            }
            // Add cache listener callback to region
            if (attrs.CacheListener == null)
            {
                ExampleCacheListenerCallback listenerCallback =
                    new ExampleCacheListenerCallback();
                AttributesMutator mutator = m_region.GetAttributesMutator();
                mutator.SetCacheListener(listenerCallback);
            }
        }
예제 #7
0
        static void Main(string[] args)
        {
            try
            {
                // Create a Geode Cache Programmatically.
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();
                Cache        cache        = cacheFactory.SetSubscriptionEnabled(true)
                                            .Create();

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

                RegionFactory regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
                // Create the example Region programmatically.
                IRegion <string, string> region = regionFactory
                                                  .SetEntryIdleTimeout(ExpirationAction.Destroy, 10)
                                                  .Create <string, string>("exampleRegion");

                Console.WriteLine("Created the Region with generics support programmatically.");

                // Plugin the SimpleCacheListener to the Region.
                AttributesMutator <string, string> attrMutator = region.AttributesMutator;
                attrMutator.SetCacheListener(new SimpleCacheListener <string, string>());

                Console.WriteLine("Set the generic SimpleCacheListener on the Region");

                // 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");

                // Get the Entry Idle Timeout specified in the Cache XML file.
                int entryIdleTimeout = region.Attributes.EntryIdleTimeout;

                Console.WriteLine("Got Entry Idle Timeout as {0} seconds", entryIdleTimeout);

                // Wait for half the Entry Idle Timeout duration.
                Thread.Sleep(entryIdleTimeout * 1000 / 2);

                // Get the number of Keys remaining in the Region, should be all 3.
                ICollection <string> keys = region.GetLocalView().Keys;

                Console.WriteLine("Got {0} keys before the Entry Idle Timeout duration elapsed", keys.Count);

                // Get 2 of the 3 Entries from the Region to "reset" their Idle Timeouts.
                string value1 = region["Key1"];
                string value2 = region["Key2"];

                Console.WriteLine("The SimpleCacheListener should next report the expiration action");

                // Wait for the entire Entry Idle Timeout duration.
                Thread.Sleep(entryIdleTimeout * 1000);

                // Get the number of Keys remaining in the Region, should be 0 now.
                keys = region.GetLocalView().Keys;

                Console.WriteLine("Got {0} keys after the Entry Idle Timeout duration elapsed", keys.Count);

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

                Console.WriteLine("Closed the Geode Cache");
            }
            // An exception should not occur
            catch (GeodeException gfex)
            {
                Console.WriteLine("DataExpiration Geode Exception: {0}", gfex.Message);
            }
        }
예제 #8
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);
            }
        }