예제 #1
0
 public DeltaExample(DeltaExample copy)
 {
     m_field1 = copy.m_field1;
     m_field2 = copy.m_field2;
     m_field3 = copy.m_field3;
     reset();
 }
예제 #2
0
        static void Main(string[] args)
        {
            try
            {
                // Create a Geode Cache through XMLs/clientDelta.xml
                Properties <string, string> prop = Properties <string, string> .Create <string, string>();

                prop.Insert("cache-xml-file", "XMLs/clientDelta.xml");
                CacheFactory cacheFactory = CacheFactory.CreateCacheFactory(prop);
                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, DeltaExample> region = cache.GetRegion <string, DeltaExample>("exampleRegion");

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

                Serializable.RegisterTypeGeneric(DeltaExample.create);

                //Creating Delta Object.
                DeltaExample ptr = new DeltaExample(10, 15, 20);

                //Put the delta object. This will send the complete object to the server.
                region["Key1"] = ptr;

                Console.WriteLine("Completed put for a delta object");


                //Changing state of delta object.
                ptr.setField1(9);

                //Put delta object again. Since delta flag is set true it will calculate
                //Delta and send only Delta to the server.
                region["Key1"] = ptr;
                Console.WriteLine("Completed put with delta");

                //Locally invalidating the key.
                region.GetLocalView().Invalidate("Key1");
                //Fetching the value from server.
                DeltaExample retVal = (DeltaExample)region["Key1"];

                //Verification
                if (retVal.getField1() != 9)
                {
                    throw new GeodeException("First field should have been 9");
                }
                if (retVal.getField2() != 15)
                {
                    throw new GeodeException("Second field should have been 15");
                }
                if (retVal.getField3() != 20)
                {
                    throw new GeodeException("Third field should have been 20");
                }

                Console.WriteLine("Delta has been successfully applied at server");

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

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