Summary: Writing objects to the space
OverviewObjects are written to the space using the ISpaceProxy.Write method. A write operation inserts a copy of the given object to the space, hence, any changes made to the object after the write operation do not affect the object in the space. Writing a Single ObjectWhen writing your objects to the space, construct the object as usual, and use the ISpaceProxy.Write operation through a proxy to the space: The Person object: class Person { private string _userId; private string _name; [SpaceID] public string UserId { get { return _userId; } set { _userId = value; } } public string Name { get { return _name; } set { _name = value; } } public Person() { } } Person kermit = new Person(); kermit.UserId = "011-1111111"; kermit.Name = "Kermit the frog"; //Starts an embedded space and creates a proxy to the space ISpaceProxy proxy = SpaceProxyProviderFactory.Instance.FindSpace("/./mySpace"); //Write the object to the space proxy.Write(kermit);
Writing Multiple ObjectsSometimes it is required to write multiple objects at once. For instance, when the proxy is to a remote space on a different machine or a different process. Instead of sending each object separately on the network, and suffering from high latency, a batch of objects can be sent together in a single operation using the ISpaceProxy.WriteMultiple operation. When writing multiple objects to the space, construct an array of your objects, and use the ISpaceProxy.WriteMultiple operation through a proxy to the space. Person kermit = new Person(); kermit.UserId = "011-1111111"; kermit.Name = "Kermit the frog"; Person missPiggy = new Person(); missPiggy.UserId = "022-2222222"; missPiggy.Name = "Miss Piggy"; Person[] persons = new Person[]{kermit, missPiggy}; //Write the objects to the space proxy.WriteMultiple(persons); Updating Existing Objects in the SpaceWhen objects that exist in the space need to be updated, the ISpaceProxy.Update or ISpaceProxy.UpdateMultiple operation should be used similiar to the corresponding write operation: Person kermit = new Person(); kermit.UserId = "011-1111111"; kermit.Name = "Kermit the frog"; proxy.Write(kermit); ... //Updating the name of the already existing kermit object in space kermit.Name = "Kermit the green frog"; proxy.Update(kermit); |
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |