Summary: Customizing object behaviour using space metadata attributes.
OverviewIn general, every object can be stored in the space - it does not have to inherit from a base class, implement an interface, or have any attributes decorating it. It doesn't even have to be Serializable, although it is recommended as a design practice, to keep in-line with .NET standards. The only requirement is to have a parameterless constructor. However, in many cases this generic approach is not enough. For example, you may want to exclude a specific field from being stored in the space, or specify that a certain property should be indexed for faster matching performance. In such cases (and others), you can use a set of attributes to customize the object's behaviour in the space. If you don't want to (or can't) use XAP.NET attributes in your classes code, you can create an xml file that defines those behaviours, commonly called gs.xml.
Including/Excluding Content from the SpaceBy default, all public members (fields and properties) in a class are stored in the space, whereas non-public members are ignored. Since classes are usually designed with private/protected fields and public properties wrapping them, in most cases the default behaviour is also the desired one. To change this behaviour for a specific class, apply a [SpaceClass] attribute on that class, and use IncludeProperties and/or IncludeFields to specify which members should be included in the space. Both IncludeProperties and IncludeFields are an IncludeMembers enumeration, which can receive the following values:
Example 1 – The default behaviourpublic class Person {...}
This is actually equivalent to the following declaration: [SpaceClass(IncludeFields=IncludeMembers.Public, IncludeProperties=IncludeMembers.Public)]
public class Person {...}
Example 2 – To ignore all properties and store all the fields, including private ones[SpaceClass(IncludeFields=IncludeMembers.All, IncludeProperties=IncludeMembers.None)]
public class Person {...}
To change the behaviour of a specific field/property, apply a [SpaceProperty] to include it, or a [SpaceExclude] to exclude it. These settings override the class-level settings. Example 3 – Storing all the Person properties except the Password propertypublic class Person { [SpaceExclude] public string Password {...} } IndexingIf a property is commonly used in space queries, you can instruct the space to index that property for improved read performance. To do this, use the [SpaceProperty] attribute, and specify Index=SpaceIndexType.Basic. public class Person { [SpaceIndex(Type=SpaceIndexType.Basic)] public string UserID {...} }
Unique ConstraintsWhen an object is stored in the space, the space generates a unique identifier and stores it along with that object. The unique identifier is commonly referred to as a Space ID or UID. In many cases, it's useful to have the object's space ID or to control it. Some examples:
There are two modes of SpaceID that are supported:
The default is AutoGenerate=false. Note that only one property in a class can be marked as a SpaceID property.
RoutingWhen working with a clustered space, one of the properties in a class is used to determine the routing behaviour of that class within the cluster (i.e. how instances of that class are partitioned across the cluster's nodes). The routing property is determined according to the following rules:
Note that only one property in a class can be marked as a routing property.
VersioningThe space can keep track of an object's version (i.e. how many times it was written/updated in the space), and provide optimistic concurrency using that version information. For that end, the space needs to store the object's version in some property in the object. To specify that a property should be used for versioning, mark it with a [SpaceVersion] attribute. If no property is marked as a space version, the space does not store version information for that class. Note that only one property in a class can be marked as a version property, and it must be of type int. NullValueWhen a class contains a field or a property of not a nullable type, (for instance a primitive such as int or a struct such as DateTime), it is recommended to specify a null value for it that will be used when querying the space for that class. The NullValue attribute instructs the space to ignore this field when performing matching or partial update, when the content of the field in the template equals the defined NullValue.
To specify a null value, the field or property should be marked with the [SpaceProperty(NullValue = ?)] attribute: Example #1 - Null value on a primitive int public class Person { [SpaceProperty(NullValue = -1)] public int Age {...} } Example #2 - Null value on DateTime public class Person { [SpaceProperty(NullValue = "1900-01-01T12:00:00")] public DateTime BornDate {...} } MappingBy default, the name of the class in the space is the fully-qualified class name (i.e. including namespace), and the properties/fields names in the space equal to the .NET name. In some cases, usually in interoperability scenarios, you may need to map your .NET class name and properties to different names in the space. You can do that using the AliasName property on [SpaceClass] and [SpaceProperty]. For example, the following .NET Person class contains mapping to an equivalent Java Person class: namespace MyCompany.MyProject { [SpaceClass(AliasName="com.mycompany.myproject.Person")] public class Person { [SpaceProperty(AliasName="firstName")] public String FirstName {...} } } For more information, see GigaSpaces.NET - Interoperability With Non .NET Applications.
PersistencyThe space can be attached to an external data source and persist its classes through it. A certain class can be specified if it should be persisted or not. To do this, use the [SpaceClass(Persist=true)] or [SpaceClass(Persist=false)] class level attribute. [SpaceClass(Persist=false)] public class Person {...} The default is [SpaceClass(Persist=true)]. ReplicationSome cluster toplogies have replication defined, which means that some or all of the data is replicated between the spaces. In this case, it can be specified whether each class should be replicated or not, by using the [SpaceClass(Replicate=true)] or [SpaceClass(Replicate=false)] class level attribute. [SpaceClass(Replicate=false)] public class Person {...} The default is [SpaceClass(Replicate=true)]. FIFOA class can be marked to operate in FIFO mode, which means that all the insert, removal and notification of this class should be done in First-in-First-out mode. It can be specified whether each class should operate in FIFO mode or not, by using the [SpaceClass(Fifo=true)] or [SpaceClass(Fifo=false)] class level attribute. [SpaceClass(Fifo=true)] public class Person {...} The default is [SpaceClass(Fifo=false)]. For more information on FIFO implementation, see FIFO Support and FIFO Grouping . |
![]() |
GigaSpaces.com - Legal Notice - 3rd Party Licenses - Site Map - API Docs - Forum - Downloads - Blog - White Papers - Contact Tech Writing - Gen. by Atlassian Confluence |