Exemple #1
0
        public void DoRegisterInterests(string regionName, bool receiveValues)
        {
            IRegion <object, object> region = CacheHelper.GetRegion <object, object>(regionName);
            List <string>            keys   = new List <string>();

            foreach (string key in m_keysNonRegex)
            {
                keys.Add(key);
            }
            region.GetSubscriptionService().RegisterKeys(keys.ToArray(), false, false, receiveValues);
            region.GetSubscriptionService().RegisterRegex("key-regex.*", false, false, receiveValues);
        }
Exemple #2
0
        public void DoUnregisterInterests(string regionName)
        {
            List <string> keys = new List <string>();

            foreach (string key in m_keysNonRegex)
            {
                keys.Add(key);
            }
            IRegion <object, object> region = CacheHelper.GetRegion <object, object>(regionName);

            region.GetSubscriptionService().UnregisterKeys(keys.ToArray());
            region.GetSubscriptionService().UnregisterRegex("key-regex.*");
        }
Exemple #3
0
        public void StepNineInterestResultPolicyInv()
        {
            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[0]);

            region.GetSubscriptionService().UnregisterRegex(m_regex23);
            List <Object> keys = new List <Object>();

            keys.Add(m_keys[0]);
            keys.Add(m_keys[1]);
            keys.Add(m_keys[2]);
            region.GetSubscriptionService().RegisterKeys(keys);

            VerifyInvalidAll(m_regionNames[0], m_keys[0], m_keys[1], m_keys[2]);
        }
Exemple #4
0
 public void DoRegisterAllKeys()
 {
     FwkInfo("In DoRegisterAllKeys()");
     try
     {
         IRegion <TKey, TVal> region = GetRegion();
         FwkInfo("DoRegisterAllKeys() region name is {0}", region.Name);
         bool isDurable = GetBoolValue("isDurableReg");
         ResetKey("getInitialValues");
         bool isGetInitialValues = GetBoolValue("getInitialValues");
         bool checkReceiveVal    = GetBoolValue("checkReceiveVal");
         bool isReceiveValues    = true;
         if (checkReceiveVal)
         {
             ResetKey("receiveValue");
             isReceiveValues = GetBoolValue("receiveValue");
         }
         region.GetSubscriptionService().RegisterAllKeys(isDurable, null, isGetInitialValues, isReceiveValues);
     }
     catch (Exception ex)
     {
         FwkException("DoRegisterAllKeys() Caught Exception: {0}", ex);
     }
     FwkInfo("DoRegisterAllKeys() complete.");
 }
        void RegisterKeysPdx()
        {
            CacheHelper.DCache.TypeRegistry.RegisterPdxType(PdxTests.PdxTypes1.CreateDeserializable);
            CacheHelper.DCache.TypeRegistry.RegisterPdxType(PdxTests.PdxTypes8.CreateDeserializable);
            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[0]);

            region.GetSubscriptionService().RegisterAllKeys();
        }
Exemple #6
0
 void DoDeltaAD_C1_1()
 {
   DeltaTestAD val = new DeltaTestAD();
   IRegion<object, object> reg = CacheHelper.GetRegion<object, object>("DistRegionAck");
   reg.GetSubscriptionService().RegisterAllKeys();
   Util.Log("clientAD1 put");
   reg[1] = val;
   Util.Log("clientAD1 put done");
 }
Exemple #7
0
        public void InitDurableClient(int client, string locators, int redundancyLevel,
                                      string durableClientId, int durableTimeout)
        {
            // Create DurableListener for first time and use same afterward.
            DurableListener <object, object> checker = null;

            if (client == 1)
            {
                if (ThinClientDurableTests.m_checker1 == null)
                {
                    ThinClientDurableTests.m_checker1 = DurableListener <object, object> .Create();
                }
                checker = ThinClientDurableTests.m_checker1;
            }
            else // client == 2
            {
                if (ThinClientDurableTests.m_checker2 == null)
                {
                    ThinClientDurableTests.m_checker2 = DurableListener <object, object> .Create();
                }
                checker = ThinClientDurableTests.m_checker2;
            }
            CacheHelper.InitConfigForDurable_Pool(locators, redundancyLevel,
                                                  durableClientId, durableTimeout);
            CacheHelper.CreateTCRegion_Pool <object, object>(RegionNames[0], false, true, checker,
                                                             CacheHelper.Locators, "__TESTPOOL1_", true);

            CacheHelper.DCache.ReadyForEvents();
            IRegion <object, object> region1 = CacheHelper.GetVerifyRegion <object, object>(RegionNames[0]);

            region1.GetSubscriptionService().RegisterRegex(m_regexes[0], true);
            region1.GetSubscriptionService().RegisterRegex(m_regexes[1], false);
            //CacheableKey[] ldkeys = { new CacheableString(m_mixKeys[3]) };
            ICollection <object> lkeys = new List <object>();

            lkeys.Add((object)m_mixKeys[3]);
            region1.GetSubscriptionService().RegisterKeys(lkeys, true, false);

            ICollection <object> ldkeys = new List <object>();;

            ldkeys.Add((object)m_mixKeys[2]);
            region1.GetSubscriptionService().RegisterKeys(ldkeys, false, false);
        }
Exemple #8
0
        public void StepSevenInterestResultPolicyInv()
        {
            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[0]);

            region.GetSubscriptionService().RegisterRegex(m_regex23);

            VerifyInvalidAll(m_regionNames[0], m_keys[1], m_keys[2]);
            VerifyEntry(m_regionNames[0], m_keys[0], m_vals[0], true);
            VerifyEntry(m_regionNames[0], m_keys[3], m_vals[3], true);
        }
Exemple #9
0
        public void StepEightInterestResultPolicyInv()
        {
            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[1]);

            region.GetSubscriptionService().RegisterAllKeys();

            VerifyInvalidAll(m_regionNames[1], m_keys[0], m_keys[1],
                             m_keys[2], m_keys[3]);
            UpdateAllEntries(m_regionNames[0], true);
        }
Exemple #10
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");
        }
Exemple #11
0
        public void RegisterUnicodeKeys(string regionName)
        {
            IRegion <object, object> region = CacheHelper.GetVerifyRegion <object, object>(regionName);

            string[] keys = new string[m_numUnicodeStrings];
            for (int index = 0; index < m_numUnicodeStrings; ++index)
            {
                keys[m_numUnicodeStrings - index - 1] = GetUnicodeString(index);
            }
            region.GetSubscriptionService().RegisterKeys(keys);
        }
Exemple #12
0
        } // end [Test] DurableInterest

        #endregion

        #region Durable Failover Test


        public void InitDurableClientForFailover(int client, string locators,
                                                 int redundancyLevel, string durableClientId, int durableTimeout)
        {
            // we use "client" to either create a DurableListener or use the existing ones
            // if the clients are initialized for the second time
            DurableListener <object, object> checker = null;

            if (client == 1)
            {
                if (ThinClientDurableTests.m_checker1 == null)
                {
                    ThinClientDurableTests.m_checker1 = DurableListener <object, object> .Create();
                }
                checker = ThinClientDurableTests.m_checker1;
            }
            else // client == 2
            {
                if (ThinClientDurableTests.m_checker2 == null)
                {
                    ThinClientDurableTests.m_checker2 = DurableListener <object, object> .Create();
                }
                checker = ThinClientDurableTests.m_checker2;
            }
            CacheHelper.InitConfigForDurable_Pool(locators, redundancyLevel,
                                                  durableClientId, durableTimeout, 35000);
            CacheHelper.CreateTCRegion_Pool(RegionNames[0], false, true, checker,
                                            CacheHelper.Locators, "__TESTPOOL1_", true);
            CacheHelper.DCache.ReadyForEvents();
            IRegion <object, object> region1 = CacheHelper.GetVerifyRegion <object, object>(RegionNames[0]);

            try
            {
                region1.GetSubscriptionService().RegisterRegex(m_regexes[0], true);
                region1.GetSubscriptionService().RegisterRegex(m_regexes[1], false);
            }
            catch (Exception other)
            {
                Assert.Fail("RegisterKeys threw unexpected exception: {0}", other.Message);
            }
        }
Exemple #13
0
        } // end [Test] DurableAndNonDurableBasic

        #endregion

        #region Durable Intrest Test

        public void InitDurableClientRemoveInterest(int client, string locators,
                                                    int redundancyLevel, string durableClientId, int durableTimeout)
        {
            // Client Registered Durable Intrest on two keys. We need to unregister them all here.

            DurableListener <object, object> checker = null;

            if (client == 1)
            {
                if (ThinClientDurableTests.m_checker1 == null)
                {
                    ThinClientDurableTests.m_checker1 = DurableListener <object, object> .Create();
                }
                checker = ThinClientDurableTests.m_checker1;
            }
            else // client == 2
            {
                if (ThinClientDurableTests.m_checker2 == null)
                {
                    ThinClientDurableTests.m_checker2 = DurableListener <object, object> .Create();
                }
                checker = ThinClientDurableTests.m_checker2;
            }
            CacheHelper.InitConfigForDurable_Pool(locators, redundancyLevel,
                                                  durableClientId, durableTimeout);
            CacheHelper.CreateTCRegion_Pool(RegionNames[0], false, true, checker,
                                            CacheHelper.Locators, "__TESTPOOL1_", true);

            CacheHelper.DCache.ReadyForEvents();
            IRegion <object, object> region1 = CacheHelper.GetVerifyRegion <object, object>(RegionNames[0]);

            // Unregister Regex only durable
            region1.GetSubscriptionService().RegisterRegex(m_regexes[0], true);
            region1.GetSubscriptionService().UnregisterRegex(m_regexes[0]);

            // Unregister list only durable
            string[] ldkeys = new string[] { m_mixKeys[3] };
            region1.GetSubscriptionService().RegisterKeys(ldkeys, true, false);
            region1.GetSubscriptionService().UnregisterKeys(ldkeys);
        }
Exemple #14
0
        public void InitDupListeners()
        {
            IRegion <object, object> region1 = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[0]);
            IRegion <object, object> region2 = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[1]);

            region1.AttributesMutator.SetCacheListener(DupListener <object, object> .Create());
            region2.AttributesMutator.SetCacheListener(DupListener <object, object> .Create());

            Thread.Sleep(5000);

            region1.GetSubscriptionService().RegisterAllKeys();
            region2.GetSubscriptionService().RegisterAllKeys();
        }
 public void UnregisterRegexes(string regex0, string regex1)
 {
     if (regex0 != null)
     {
         IRegion <object, object> region0 = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[0]);
         region0.GetSubscriptionService().UnregisterRegex(regex0);
     }
     if (regex1 != null)
     {
         IRegion <object, object> region1 = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[1]);
         region1.GetSubscriptionService().UnregisterRegex(regex1);
     }
 }
Exemple #16
0
        public void InitDurableClientWithTwoPools(string locators,
                                                  int redundancyLevel, string durableClientId, int durableTimeout, int expectedQ0, int expectedQ1)
        {
            DurableListener <object, object> checker = null;

            CacheHelper.InitConfigForDurable_Pool2(locators, redundancyLevel,
                                                   durableClientId, durableTimeout, 35000, "__TESTPOOL1_");
            CacheHelper.CreateTCRegion_Pool(RegionNames[0], false, true, checker,
                                            CacheHelper.Locators, "__TESTPOOL1_", true);

            CacheHelper.InitConfigForDurable_Pool2(locators, redundancyLevel,
                                                   durableClientId, durableTimeout, 35000, "__TESTPOOL2_");
            CacheHelper.CreateTCRegion_Pool(RegionNames[1], false, true, checker,
                                            CacheHelper.Locators, "__TESTPOOL2_", true);

            IRegion <object, object> region0 = CacheHelper.GetVerifyRegion <object, object>(RegionNames[0]);
            IRegion <object, object> region1 = CacheHelper.GetVerifyRegion <object, object>(RegionNames[1]);

            try
            {
                region0.GetSubscriptionService().RegisterAllKeys(true);
                region1.GetSubscriptionService().RegisterAllKeys(true);
            }
            catch (Exception other)
            {
                Assert.Fail("RegisterAllKeys threw unexpected exception: {0}", other.Message);
            }

            Pool pool0 = PoolManager.Find(region0.Attributes.PoolName);
            int  pendingEventCount0 = pool0.PendingEventCount;

            Util.Log("pendingEventCount0 for pool = {0} {1} ", pendingEventCount0, region0.Attributes.PoolName);
            string msg = string.Format("Expected Value ={0}, Actual = {1}", expectedQ0, pendingEventCount0);

            Assert.AreEqual(expectedQ0, pendingEventCount0, msg);

            Pool pool1 = PoolManager.Find(region1.Attributes.PoolName);
            int  pendingEventCount1 = pool1.PendingEventCount;

            Util.Log("pendingEventCount1 for pool = {0} {1} ", pendingEventCount1, region1.Attributes.PoolName);
            string msg1 = string.Format("Expected Value ={0}, Actual = {1}", expectedQ1, pendingEventCount1);

            Assert.AreEqual(expectedQ1, pendingEventCount1, msg1);

            CacheHelper.DCache.ReadyForEvents();
            Thread.Sleep(10000);

            CacheHelper.DCache.Close(true);
        }
Exemple #17
0
        public void StepFourRegex3()
        {
            IRegion <object, object> region0 = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[0]);
            IRegion <object, object> region1 = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[1]);

            try
            {
                Util.Log("Registering empty regular expression.");
                region0.GetSubscriptionService().RegisterRegex(string.Empty);
                Assert.Fail("Did not get expected exception!");
            }
            catch (Exception ex)
            {
                Util.Log("Got expected exception {0}: {1}", ex.GetType(), ex.Message);
            }
            try
            {
                Util.Log("Registering null regular expression.");
                region1.GetSubscriptionService().RegisterRegex(null);
                Assert.Fail("Did not get expected exception!");
            }
            catch (Exception ex)
            {
                Util.Log("Got expected exception {0}: {1}", ex.GetType(), ex.Message);
            }
            try
            {
                Util.Log("Registering non-existent regular expression.");
                region1.GetSubscriptionService().UnregisterRegex("Non*Existent*Regex*");
                Assert.Fail("Did not get expected exception!");
            }
            catch (Exception ex)
            {
                Util.Log("Got expected exception {0}: {1}", ex.GetType(), ex.Message);
            }
        }
Exemple #18
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>());
    }
        public void UnregisterKeys(string key0, string key1)
        {
            IRegion <object, object> region0 = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[0]);
            IRegion <object, object> region1 = CacheHelper.GetVerifyRegion <object, object>(m_regionNames[1]);

            if (key0 != null)
            {
                List <Object> keys0 = new List <Object>();
                keys0.Add(key0);
                region0.GetSubscriptionService().UnregisterKeys(keys0);
            }
            if (key1 != null)
            {
                List <Object> keys1 = new List <Object>();
                keys1.Add(key1);
                region1.GetSubscriptionService().UnregisterKeys(keys1);
            }
        }
        public RequestReply(Cache cache)
        {
            this.cache = cache;
            if (this.cache.GetRegion <int, object>("request") == null)
            {
                RegionFactory         regionFactory1 = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
                IRegion <int, object> regionRequest  = regionFactory1.Create <int, object>("request");
            }

            if (this.cache.GetRegion <int, object>("reply") == null)
            {
                RegionFactory         regionFactory2 = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
                IRegion <int, object> regionReply    = regionFactory2.Create <int, object>("reply");

                regionReply.GetSubscriptionService().RegisterAllKeys();
                regionReply.AttributesMutator.SetCacheListener(new MyCacheListener(ref queue));
            }
        }
Exemple #21
0
        public void InitDurableClient(int client, string locators, string conflation)
        {
            // Create DurableListener for first time and use same afterward.
            ConflationListner <object, object> checker1 = null;
            ConflationListner <object, object> checker2 = null;
            string durableId = ThinClientConflationTests.DurableClientIds[client - 1];

            if (client == 1)
            {
                ThinClientConflationTests.m_listener1C1 = ConflationListner <object, object> .Create();

                ThinClientConflationTests.m_listener2C1 = ConflationListner <object, object> .Create();

                checker1 = ThinClientConflationTests.m_listener1C1;
                checker2 = ThinClientConflationTests.m_listener2C1;
            }
            else // client == 2
            {
                ThinClientConflationTests.m_listener1C2 = ConflationListner <object, object> .Create();

                ThinClientConflationTests.m_listener2C2 = ConflationListner <object, object> .Create();

                checker1 = ThinClientConflationTests.m_listener1C2;
                checker2 = ThinClientConflationTests.m_listener2C2;
            }
            CacheHelper.InitConfigForConflation_Pool(locators, durableId, conflation);
            CacheHelper.CreateTCRegion_Pool <object, object>(Regions[0], false, true, checker1,
                                                             CacheHelper.Locators, "__TESTPOOL1_", true);
            CacheHelper.CreateTCRegion_Pool <object, object>(Regions[1], false, true, checker2,
                                                             CacheHelper.Locators, "__TESTPOOL1_", true);

            //CacheHelper.DCache.ReadyForEvents();

            IRegion <object, object> region1 = CacheHelper.GetVerifyRegion <object, object>(Regions[0]);

            region1.GetSubscriptionService().RegisterAllKeys(true);
            IRegion <object, object> region2 = CacheHelper.GetVerifyRegion <object, object>(Regions[1]);

            region2.GetSubscriptionService().RegisterAllKeys(true);
        }
        static void Main(string[] args)
        {
            try
            {
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory().SetSubscriptionEnabled(true);
                Cache        cache        = cacheFactory.Create();
                Console.WriteLine("Created the Geode Cache");

                RegionFactory            regionFactory = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY);
                IRegion <string, string> region        = regionFactory.Create <string, string>("exampleRegion");
                region.GetSubscriptionService().RegisterAllKeys();
                Console.WriteLine("RegisterAllKeys to exampleRegion");

                QueryService <string, string>        qrySvc   = cache.GetQueryService <string, string>();
                CqAttributesFactory <string, string> cqFac    = new CqAttributesFactory <string, string>();
                ICqListener <string, string>         cqLstner = new MyCqListener <string, string>();
                cqFac.AddCqListener(cqLstner);
                CqAttributes <string, string> cqAttr  = cqFac.Create();
                CqQuery <string, string>      qry     = qrySvc.NewCq("MyCq", "select * from /exampleRegion p where p.toString = '1'", cqAttr, false);
                ICqResults <string>           results = qry.ExecuteWithInitialResults();
                Console.WriteLine("Execute CQ: Initial ResultSet returned {0} rows", results.Size);

                while (true)
                {
                    System.Threading.Thread.Sleep(5000);
                    string val1 = null;
                    string val2 = null;
                    region.TryGetValue("1", ref val1);
                    region.TryGetValue("2", ref val2);
                    Console.WriteLine("exampleRegion['1']: {0}", val1);
                    Console.WriteLine("exampleRegion['2']: {0}", val2);
                }
            }
            catch (GeodeException gfex)
            {
                Console.WriteLine("Geode Exception: {0}", gfex.Message);
            }
        }
Exemple #23
0
    void registerClassDeltaTestImpl()
    {
      try
      {
        CacheHelper.DCache.TypeRegistry.RegisterTypeGeneric(DeltaTestImpl.CreateDeserializable);
      }
      catch (IllegalStateException)
      {
        // ARB: ignore exception caused by type reregistration.
      }
      DeltaTestImpl.ResetDataCount();

      Thread.Sleep(2000);
      IRegion<object, object> reg = CacheHelper.GetRegion<object, object>("DistRegionAck");
      try
      {
        reg.GetSubscriptionService().RegisterRegex(".*");
      }
      catch (Exception)
      {
        // ARB: ignore regex exception for missing notification channel.
      }
    }
        static void Main(string[] args)
        {
            try
            {
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory();

                Cache cache = cacheFactory.SetSubscriptionEnabled(true).AddServer("localhost", 50505).AddServer("localhost", 40404).Create();

                Console.WriteLine("Created the Geode Cache");
                IRegion <string, string> region = cache.CreateRegionFactory(RegionShortcut.CACHING_PROXY).Create <string, string>("partition_region");
                Console.WriteLine("Created the Region");

                region.GetSubscriptionService().RegisterAllKeys();

                for (int i = 0; i < 34; i++)
                {
                    region["KEY--" + i] = "VALUE--" + i;
                }

                object[] routingObj = new object[17];
                int      j          = 0;
                for (int i = 0; i < 34; i++)
                {
                    if (i % 2 == 0)
                    {
                        continue;
                    }
                    routingObj[j] = "KEY--" + i;
                    j++;
                }
                Console.WriteLine("routingObj count= {0}.", routingObj.Length);

                bool args0 = true;
                //test data dependant function execution
                //test get function with result
                Execution <object> exc = FunctionService <object> .OnRegion <string, string>(region);

                IResultCollector <object> rc = exc.WithArgs <bool>(args0).WithFilter <object>(routingObj).Execute(getFuncName);
                ICollection <object>      executeFunctionResult = rc.GetResult();

                List <object> resultList = new List <object>();
                foreach (List <object> item in executeFunctionResult)
                {
                    foreach (object subitem in item)
                    {
                        resultList.Add(subitem);
                    }
                }

                Console.WriteLine("on region: result count= {0}.", resultList.Count);
                for (int i = 0; i < resultList.Count; i++)
                {
                    Console.WriteLine("on region:get:result[{0}]={1}.", i, (string)resultList[i]);
                }

                //test date independant fucntion execution on one server
                //test get function with result
                exc = FunctionService <object> .OnServer(cache);

                ArrayList args1 = new ArrayList();
                for (int i = 0; i < routingObj.Length; i++)
                {
                    Console.WriteLine("routingObj[{0}]={1}.", i, (string)routingObj[i]);
                    args1.Add(routingObj[i]);
                }
                rc = exc.WithArgs <ArrayList>(args1).Execute(getFuncIName);
                executeFunctionResult = rc.GetResult();
                Console.WriteLine("on one server: result count= {0}.", executeFunctionResult.Count);
                List <object> resultList1 = new List <object>();

                foreach (List <object> item in executeFunctionResult)
                {
                    foreach (object subitem in item)
                    {
                        resultList1.Add(subitem);
                    }
                }
                if (resultList1.Count != 17)
                {
                    Console.WriteLine("result count check failed on one server:get:");
                }
                for (int i = 0; i < resultList1.Count; i++)
                {
                    Console.WriteLine("on one server:get:result[{0}]={1}.", i, (string)resultList1[i]);
                }

                //test date independant fucntion execution on all servers
                //test get function with result
                exc = FunctionService <object> .OnServers(cache);

                rc = exc.WithArgs <ArrayList>(args1).Execute(getFuncIName);
                executeFunctionResult = rc.GetResult();
                Console.WriteLine("on all servers: result count= {0}.", executeFunctionResult.Count);

                List <object> resultList2 = new List <object>();

                foreach (List <object> item in executeFunctionResult)
                {
                    foreach (object subitem in item)
                    {
                        resultList2.Add(subitem);
                    }
                }

                if (resultList2.Count != 34)
                {
                    Console.WriteLine("result count check failed on all servers");
                }
                for (int i = 0; i < resultList2.Count; i++)
                {
                    Console.WriteLine("on all servers:result[{0}]={1}.", i, (string)resultList2[i]);
                }

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

                Console.WriteLine("Closed the Geode Cache");
            }
            // An exception should not occur
            catch (GeodeException gfex)
            {
                Console.WriteLine("ExecuteFunctions Geode Exception: {0}", gfex.Message);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                //Create CacheFactory using the user specified properties or from the gfcpp.properties file by default.
                Properties <string, string> prp = Properties <string, string> .Create <string, string>();

                prp.Insert("cache-xml-file", "XMLs/clientRegisterInterest.xml");
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory(prp);

                Console.WriteLine("Created CacheFactory");

                // Create a Geode Cache with the "clientRegisterInterest.xml" Cache XML file.
                Cache cache = cacheFactory.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 Region from the Cache");

                // Register and Unregister Interest on Region for All Keys.
                region.GetSubscriptionService().RegisterAllKeys();
                region.GetSubscriptionService().UnregisterAllKeys();

                Console.WriteLine("Called RegisterAllKeys() and UnregisterAllKeys()");

                // Register and Unregister Interest on Region for Some Keys.
                ICollection <string> keys = new List <string>();
                keys.Add("123");
                keys.Add("Key-123");

                region.GetSubscriptionService().RegisterKeys(keys);
                region.GetSubscriptionService().UnregisterKeys(keys);

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

                // Register and Unregister Interest on Region for Keys matching a Regular Expression.
                region.GetSubscriptionService().RegisterRegex("Keys-*");
                region.GetSubscriptionService().UnregisterRegex("Keys-*");

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

                //Register Interest on Region for All Keys with getInitialValues to populate the cache with values of all keys from the server.
                region.GetSubscriptionService().RegisterAllKeys(false, null, true); // Where the 3rd argument is getInitialValues.
                //Unregister Interest on Region for All Keys.
                region.GetSubscriptionService().UnregisterAllKeys();

                Console.WriteLine("Called RegisterAllKeys() and UnregisterAllKeys() with getInitialValues argument");

                //Register Interest on Region for Some Keys with getInitialValues.
                region.GetSubscriptionService().RegisterKeys(keys, false, true); // Where the 3rd argument is getInitialValues.

                //Unregister Interest on Region for Some Keys.
                region.GetSubscriptionService().UnregisterKeys(keys);

                Console.WriteLine("Called RegisterKeys() and UnregisterKeys() with getInitialValues argument");

                //Register and Unregister Interest on Region for Keys matching a Regular Expression with getInitialValues.
                region.GetSubscriptionService().RegisterRegex("Keys-*", false, null, true);
                region.GetSubscriptionService().UnregisterRegex("Keys-*");

                Console.WriteLine("Called RegisterRegex() and UnregisterRegex() with getInitialValues argument");

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

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