Platform Interoperability
GigaSpaces supports easy and efficient communication and access across projects that include a combination of Java, .NET and C++ platforms, while also maintaining the benefits of the GigaSpaces scale-out application server.
Designing Interoperable Classes
using GigaSpaces.Core.Metadata;
namespace MyCompany.MyProject.Entities
{
[SpaceClass(AliasName="com.mycompany.myproject.entities.Person")]
public class Person
{
private string _name;
[SpaceProperty(AliasName="name")]
public string Name
{
get { return this._name; }
set { this._name = value; }
}
}
}
package com.mycompany.myproject.entities;
public class Person
{
private String name;
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
}
}
Guidelines and Restrictions
Follow these guidelines and restrictions in this section to enable platform interoperability.
Class Name
The full class name (including package\namespace) in all platforms should be identical.
Java packages use a different naming convention than .NET namespaces, therefore it is recommended to use the SpaceClass(AliasName="")
feature to map a .NET class to the respective Java class.
Properties and Fields
The properties/fields stored in the Space Where GigaSpaces data is stored. It is the logical cache that holds data objects in memory and might also hold them in layered in tiering. Data is hosted from multiple SoRs, consolidated as a unified data model. on all platforms should be identical.
In Java, only properties are serialized into the Space. In .NET, both fields and properties are serialized, so you can mix and match them.
Java properties start with a lowercase letter, whereas .NET properties usually start with an uppercase letter. It is therefore recommended to use the SpaceProperty(AliasName="")
feature to map a property/field name from .NET to Java.
Types
Only the types listed in the table below are supported. If one of your fields uses a different type, you can use the class only in a homogeneous environment. Arrays of these types are also supported.
You can also use .NET enumerations, which are treated as their underlying .NET type. Java enums are not supported.
If your class contains a field whose type is not in the table, you can use SpaceExclude
to exclude it from the Space.
Some of the types have different characteristics in .NET and Java (signed\unsigned, nullable\not nullable, precision, etc.). This can lead to runtime exceptions (for example, trying to store null
in a .NET structure) or unexpected results (for example, copying values between signed and unsigned fields).
Supported Types for Matching and Interoperability
The following types are supported by the Space for matching and interoperability.
CLS | C# | VB.NET | Java | Description |
---|---|---|---|---|
System.Byte | byte | Byte | byte | 8-bit integer.1 |
Nullable<Byte> | byte? | Nullable(Of Byte) | java.lang.Byte | Nullable wrapper for byte.1 |
System.Int16 | short | Short | short | 16-bit integer. |
Nullable<Int16> | short? | Nullable(Of Short) | java.lang.Short | Nullable wrapper for short. |
System.Int32 | int | Integer | int | 32-bit integer. |
Nullable<Int32> | int? | Nullable(Of Integer) | java.lang.Integer | Nullable wrapper for int. |
System.Int64 | long | Long | long | 64-bit integer. |
Nullable<Int64> | long? | Nullable(Of Long) | java.lang.Long | Nullable wrapper for long. |
System.Single | float | Single | float | Single-precision floating-point number (32 bits). |
Nullable<Single> | float? | Nullable(Of Single) | java.lang.Float | Nullable wrapper for float. |
System.Double | double | Double | double | Double-precision floating-point number (64 bits). |
Nullable<Double> | double? | Nullable(Of Double) | java.lang.Double | Nullable wrapper for double. |
System.Boolean | bool | Boolean | boolean | Boolean value (true/false). |
Nullable<Boolean> | bool? | Nullable(Of Boolean) | java.lang.Boolean | Nullable wrapper for boolean. |
System.Char | char | Char | char | A Unicode character (16 bits). |
Nullable<Char> | char? | Nullable(Of Char) | java.lang.Character | Nullable wrapper for char. |
System.String | string | String | java.lang.String | An immutable, fixed-length string of Unicode characters. |
System.DateTime Nullable<DateTime> | DateTime DateTime? | DateTime Nullable(Of DateTime) | java.util.Date | An instant in time, typically expressed as a date and time of day.2,3 |
System.Decimal Nullable<Decimal> | decimal decimal? | Decimal Nullable(Of Decimal) | java.math.BigDecimal | A decimal number, used for high-precision calculations.2,4 |
System.Guid Nullable<Guid> | Guid Guid? | Guid Nullable(Of Guid) | java.util.UUID | A 128-bit integer representing a unique identifier.2 |
System.Object | object | Object | java.lang.Object | Any object |
- In .NET a
byte
is unsigned, whereas in Java abyte
is signed. - These types can be either nullable or not nullable in .NET, whereas in Java they are always nullable.
- In .NET a
DateTime
is measured in ticks (=100 nanoseconds) since 1/1/0001, whereas in Java aDate
is a measured in milliseconds since 1/1/1970. - The types
Decimal
(.NET) andBigDecimal
(Java) have different precision and range (see .NET and Java documentation for more details). In addition, be aware that serialization/deserialization of these types is relatively slow, compared to other numeric types. As a rule of thumb, these types should not be used, unless the precision/range of other numeric types is not satisfactory.
Java 8's LocalDate
, LocalTime
, and LocalDateTime
are currently not interoperable with the .NET DateTime class.
Array and Collection Support
The following collections are mapped for interoperability.
.NET | Java | Description |
---|---|---|
T[] | E[] | Fixed-size arrays of elements. |
System.Collections.Generic.List<T> System.Collections.ArrayList System.Collections.Specialized.StringCollection |
java.util.ArrayList | Ordered list of elements. |
System.Collections.Generic.Dictionary<K,V>
System.Collections.HashTable System.Collections.Specialized.HybridDictionarySystem.Collections.Specialized.ListDictionary |
java.util.HashMap | Collection of key-value pairs. |
System.Collections.Specialized.OrderedDictionary | java.util.LinkedHashMap | Ordered collection of key-value pairs. |
System.Collections.Generic.SortedDictionary<K,V> | java.util.TreeMap | Sorted collection of key-value pairs. |
System.Collections.Specialized.NameValueCollection System.Collections.Specialized.StringDictionary | java.util.Properties | Collection of key-value string pairs.1 |
- In Java, the
Properties
type allows the user to store keys and values that are not strings.