http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableObject.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableObject.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableObject.cs new file mode 100644 index 0000000..1cedf37 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableObject.cs @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Portable +{ + /// <summary> + /// Wrapper for serialized portable objects. + /// </summary> + public interface IPortableObject + { + /// <summary>Gets portable object type ID.</summary> + /// <returns>Type ID.</returns> + int TypeId(); + + /// <summary> + /// Gets object metadata. + /// </summary> + /// <returns>Metadata.</returns> + IPortableMetadata Metadata(); + + /// <summary>Gets field value.</summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Field value.</returns> + TF Field<TF>(string fieldName); + + /// <summary>Gets fully deserialized instance of portable object.</summary> + /// <returns>Fully deserialized instance of portable object.</returns> + T Deserialize<T>(); + } +}
http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableRawReader.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableRawReader.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableRawReader.cs new file mode 100644 index 0000000..ee2520d --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableRawReader.cs @@ -0,0 +1,264 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Portable +{ + using System; + using System.Collections; + using System.Collections.Generic; + + /// <summary> + /// Raw reader for portable objects. + /// </summary> + public interface IPortableRawReader + { + /// <summary> + /// Read byte value. + /// </summary> + /// <returns>Byte value.</returns> + byte ReadByte(); + + /// <summary> + /// Read byte array. + /// </summary> + /// <returns>Byte array.</returns> + byte[] ReadByteArray(); + + /// <summary> + /// Read char value. + /// </summary> + /// <returns>Char value.</returns> + char ReadChar(); + + /// <summary> + /// Read char array. + /// </summary> + /// <returns>Char array.</returns> + char[] ReadCharArray(); + + /// <summary> + /// Read short value. + /// </summary> + /// <returns>Short value.</returns> + short ReadShort(); + + /// <summary> + /// Read short array. + /// </summary> + /// <returns>Short array.</returns> + short[] ReadShortArray(); + + /// <summary> + /// Read int value. + /// </summary> + /// <returns>Int value.</returns> + int ReadInt(); + + /// <summary> + /// Read int array. + /// </summary> + /// <returns>Int array.</returns> + int[] ReadIntArray(); + + /// <summary> + /// Read long value. + /// </summary> + /// <returns>Long value.</returns> + long ReadLong(); + + /// <summary> + /// Read long array. + /// </summary> + /// <returns>Long array.</returns> + long[] ReadLongArray(); + + /// <summary> + /// Read boolean value. + /// </summary> + /// <returns>Boolean value.</returns> + bool ReadBoolean(); + + /// <summary> + /// Read boolean array. + /// </summary> + /// <returns>Boolean array.</returns> + bool[] ReadBooleanArray(); + + /// <summary> + /// Read float value. + /// </summary> + /// <returns>Float value.</returns> + float ReadFloat(); + + /// <summary> + /// Read float array. + /// </summary> + /// <returns>Float array.</returns> + float[] ReadFloatArray(); + + /// <summary> + /// Read double value. + /// </summary> + /// <returns>Double value.</returns> + double ReadDouble(); + + /// <summary> + /// Read double array. + /// </summary> + /// <returns>Double array.</returns> + double[] ReadDoubleArray(); + + /// <summary> + /// Read decimal value. + /// </summary> + /// <returns>Decimal value.</returns> + decimal ReadDecimal(); + + /// <summary> + /// Read decimal array. + /// </summary> + /// <returns>Decimal array.</returns> + decimal[] ReadDecimalArray(); + + /// <summary> + /// Read date value in UTC form. Shortcut for <c>ReadDate(false)</c>. + /// </summary> + /// <returns>Date value.</returns> + DateTime? ReadDate(); + + /// <summary> + /// Read date value. + /// </summary> + /// <param name="local">Whether to read date in local (<c>true</c>) or UTC (<c>false</c>) form.</param> + /// <returns></returns> + DateTime? ReadDate(bool local); + + /// <summary> + /// Read date array in UTC form. Shortcut for <c>ReadDateArray(false)</c>. + /// </summary> + /// <returns>Date array.</returns> + DateTime?[] ReadDateArray(); + + /// <summary> + /// Read date array. + /// </summary> + /// <param name="local">Whether to read date array in local (<c>true</c>) or UTC (<c>false</c>) form.</param> + /// <returns>Date array.</returns> + DateTime?[] ReadDateArray(bool local); + + /// <summary> + /// Read string value. + /// </summary> + /// <returns>String value.</returns> + string ReadString(); + + /// <summary> + /// Read string array. + /// </summary> + /// <returns>String array.</returns> + string[] ReadStringArray(); + + /// <summary> + /// Read GUID value. + /// </summary> + /// <returns>GUID value.</returns> + Guid? ReadGuid(); + + /// <summary> + /// Read GUID array. + /// </summary> + /// <returns>GUID array.</returns> + Guid?[] ReadGuidArray(); + + /// <summary> + /// Read enum value. + /// </summary> + /// <returns>Enum value.</returns> + T ReadEnum<T>(); + + /// <summary> + /// Read enum array. + /// </summary> + /// <returns>Enum array.</returns> + T[] ReadEnumArray<T>(); + + /// <summary> + /// Read object. + /// </summary> + /// <returns>Object.</returns> + T ReadObject<T>(); + + /// <summary> + /// Read object array. + /// </summary> + /// <returns>Object array.</returns> + T[] ReadObjectArray<T>(); + + /// <summary> + /// Read collection. + /// </summary> + /// <returns>Collection.</returns> + ICollection ReadCollection(); + + /// <summary> + /// Read collection. + /// </summary> + /// <param name="factory">Factory.</param> + /// <param name="adder">Adder.</param> + /// <returns>Collection.</returns> + ICollection ReadCollection(PortableCollectionFactory factory, PortableCollectionAdder adder); + + /// <summary> + /// Read generic collection. + /// </summary> + /// <returns>Collection.</returns> + ICollection<T> ReadGenericCollection<T>(); + + /// <summary> + /// Read generic collection. + /// </summary> + /// <param name="factory">Factory.</param> + /// <returns>Collection.</returns> + ICollection<T> ReadGenericCollection<T>(PortableGenericCollectionFactory<T> factory); + + /// <summary> + /// Read dictionary. + /// </summary> + /// <returns>Dictionary.</returns> + IDictionary ReadDictionary(); + + /// <summary> + /// Read dictionary. + /// </summary> + /// <param name="factory">Factory.</param> + /// <returns>Dictionary.</returns> + IDictionary ReadDictionary(PortableDictionaryFactory factory); + + /// <summary> + /// Read generic dictionary. + /// </summary> + /// <returns>Dictionary.</returns> + IDictionary<TK, TV> ReadGenericDictionary<TK, TV>(); + + /// <summary> + /// Read generic dictionary. + /// </summary> + /// <param name="factory">Factory.</param> + /// <returns>Dictionary.</returns> + IDictionary<TK, TV> ReadGenericDictionary<TK, TV>(PortableGenericDictionaryFactory<TK, TV> factory); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableRawWriter.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableRawWriter.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableRawWriter.cs new file mode 100644 index 0000000..eacfde3 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableRawWriter.cs @@ -0,0 +1,221 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Portable +{ + using System; + using System.Collections; + using System.Collections.Generic; + + /// <summary> + /// Raw writer for portable objects. + /// </summary> + public interface IPortableRawWriter + { + /// <summary> + /// Write byte value. + /// </summary> + /// <param name="val">Byte value.</param> + void WriteByte(byte val); + + /// <summary> + /// Write byte array. + /// </summary> + /// <param name="val">Byte array.</param> + void WriteByteArray(byte[] val); + + /// <summary> + /// Write char value. + /// </summary> + /// <param name="val">Char value.</param> + void WriteChar(char val); + + /// <summary> + /// Write char array. + /// </summary> + /// <param name="val">Char array.</param> + void WriteCharArray(char[] val); + + /// <summary> + /// Write short value. + /// </summary> + /// <param name="val">Short value.</param> + void WriteShort(short val); + + /// <summary> + /// Write short array. + /// </summary> + /// <param name="val">Short array.</param> + void WriteShortArray(short[] val); + + /// <summary> + /// Write int value. + /// </summary> + /// <param name="val">Int value.</param> + void WriteInt(int val); + + /// <summary> + /// Write int array. + /// </summary> + /// <param name="val">Int array.</param> + void WriteIntArray(int[] val); + + /// <summary> + /// Write long value. + /// </summary> + /// <param name="val">Long value.</param> + void WriteLong(long val); + + /// <summary> + /// Write long array. + /// </summary> + /// <param name="val">Long array.</param> + void WriteLongArray(long[] val); + + /// <summary> + /// Write boolean value. + /// </summary> + /// <param name="val">Boolean value.</param> + void WriteBoolean(bool val); + + /// <summary> + /// Write boolean array. + /// </summary> + /// <param name="val">Boolean array.</param> + void WriteBooleanArray(bool[] val); + + /// <summary> + /// Write float value. + /// </summary> + /// <param name="val">Float value.</param> + void WriteFloat(float val); + + /// <summary> + /// Write float array. + /// </summary> + /// <param name="val">Float array.</param> + void WriteFloatArray(float[] val); + + /// <summary> + /// Write double value. + /// </summary> + /// <param name="val">Double value.</param> + void WriteDouble(double val); + + /// <summary> + /// Write double array. + /// </summary> + /// <param name="val">Double array.</param> + void WriteDoubleArray(double[] val); + + /// <summary> + /// Write decimal value. + /// </summary> + /// <param name="val">Decimal value.</param> + void WriteDecimal(decimal val); + + /// <summary> + /// Write decimal array. + /// </summary> + /// <param name="val">Decimal array.</param> + void WriteDecimalArray(decimal[] val); + + /// <summary> + /// Write date value. + /// </summary> + /// <param name="val">Date value.</param> + void WriteDate(DateTime? val); + + /// <summary> + /// Write date array. + /// </summary> + /// <param name="val">Date array.</param> + void WriteDateArray(DateTime?[] val); + + /// <summary> + /// Write string value. + /// </summary> + /// <param name="val">String value.</param> + void WriteString(string val); + + /// <summary> + /// Write string array. + /// </summary> + /// <param name="val">String array.</param> + void WriteStringArray(string[] val); + + /// <summary> + /// Write GUID value. + /// </summary> + /// <param name="val">GUID value.</param> + void WriteGuid(Guid? val); + + /// <summary> + /// Write GUID array. + /// </summary> + /// <param name="val">GUID array.</param> + void WriteGuidArray(Guid?[] val); + + /// <summary> + /// Write enum value. + /// </summary> + /// <param name="val">Enum value.</param> + void WriteEnum<T>(T val); + + /// <summary> + /// Write enum array. + /// </summary> + /// <param name="val">Enum array.</param> + void WriteEnumArray<T>(T[] val); + + /// <summary> + /// Write object value. + /// </summary> + /// <param name="val">Object value.</param> + void WriteObject<T>(T val); + + /// <summary> + /// Write object array. + /// </summary> + /// <param name="val">Object array.</param> + void WriteObjectArray<T>(T[] val); + + /// <summary> + /// Write collection. + /// </summary> + /// <param name="val">Collection.</param> + void WriteCollection(ICollection val); + + /// <summary> + /// Write generic collection. + /// </summary> + /// <param name="val">Collection.</param> + void WriteGenericCollection<T>(ICollection<T> val); + + /// <summary> + /// Write dictionary. + /// </summary> + /// <param name="val">Dictionary.</param> + void WriteDictionary(IDictionary val); + + /// <summary> + /// Write generic dictionary. + /// </summary> + /// <param name="val">Dictionary.</param> + void WriteGenericDictionary<TK, TV>(IDictionary<TK, TV> val); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableReader.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableReader.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableReader.cs new file mode 100644 index 0000000..71bd4f2 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableReader.cs @@ -0,0 +1,340 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Portable +{ + using System; + using System.Collections; + using System.Collections.Generic; + + /// <summary> + /// Delegate for collection creation. + /// </summary> + /// <param name="size">Collection size.</param> + /// <returns>Collection.</returns> + public delegate ICollection PortableCollectionFactory(int size); + + /// <summary> + /// Delegate for adding element to collection. + /// </summary> + /// <param name="col">Collection.</param> + /// <param name="elem">Element to add.</param> + public delegate void PortableCollectionAdder(ICollection col, object elem); + + /// <summary> + /// Delegate for generic collection creation. + /// </summary> + /// <param name="size">Collection size.</param> + /// <returns>Collection.</returns> + public delegate ICollection<T> PortableGenericCollectionFactory<T>(int size); + + /// <summary> + /// Delegate for dictionary creation. + /// </summary> + /// <param name="size">Dictionary size.</param> + /// <returns>Dictionary.</returns> + public delegate IDictionary PortableDictionaryFactory(int size); + + /// <summary> + /// Delegate for generic collection creation. + /// </summary> + /// <param name="size">Collection size.</param> + /// <returns>Collection.</returns> + public delegate IDictionary<TK, TV> PortableGenericDictionaryFactory<TK, TV>(int size); + + /// <summary> + /// Reader for portable objects. + /// </summary> + public interface IPortableReader + { + /// <summary> + /// Read named byte value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Byte value.</returns> + byte ReadByte(string fieldName); + + /// <summary> + /// Read named byte array. + /// </summary> + /// <returns>Byte array.</returns> + byte[] ReadByteArray(string fieldName); + + /// <summary> + /// Read named char value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Char value.</returns> + char ReadChar(string fieldName); + + /// <summary> + /// Read named char array. + /// </summary> + /// <returns>Char array.</returns> + char[] ReadCharArray(string fieldName); + + /// <summary> + /// Read named short value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Short value.</returns> + short ReadShort(string fieldName); + + /// <summary> + /// Read named short array. + /// </summary> + /// <returns>Short array.</returns> + short[] ReadShortArray(string fieldName); + + /// <summary> + /// Read named int value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Int value.</returns> + int ReadInt(string fieldName); + + /// <summary> + /// Read named int array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Int array.</returns> + int[] ReadIntArray(string fieldName); + + /// <summary> + /// Read named long value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Long value.</returns> + long ReadLong(string fieldName); + + /// <summary> + /// Read named long array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Long array.</returns> + long[] ReadLongArray(string fieldName); + + /// <summary> + /// Read named boolean value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Boolean value.</returns> + bool ReadBoolean(string fieldName); + + /// <summary> + /// Read named boolean array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Boolean array.</returns> + bool[] ReadBooleanArray(string fieldName); + + /// <summary> + /// Read named float value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Float value.</returns> + float ReadFloat(string fieldName); + + /// <summary> + /// Read named float array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Float array.</returns> + float[] ReadFloatArray(string fieldName); + + /// <summary> + /// Read named double value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Double value.</returns> + double ReadDouble(string fieldName); + + /// <summary> + /// Read named double array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Double array.</returns> + double[] ReadDoubleArray(string fieldName); + + /// <summary> + /// Read named decimal value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Decimal value.</returns> + decimal ReadDecimal(string fieldName); + + /// <summary> + /// Read named decimal array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Decimal array.</returns> + decimal[] ReadDecimalArray(string fieldName); + + /// <summary> + /// Read named date value in UTC form. Shortcut for <c>ReadDate(fieldName, false)</c>. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Date value.</returns> + DateTime? ReadDate(string fieldName); + + /// <summary> + /// Read named date value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="local">Whether to read date in local (<c>true</c>) or UTC (<c>false</c>) form.</param> + /// <returns>Date vaule.</returns> + DateTime? ReadDate(string fieldName, bool local); + + /// <summary> + /// Read named date array in UTC form. Shortcut for <c>ReadDateArray(fieldName, false)</c>. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Date array.</returns> + DateTime?[] ReadDateArray(string fieldName); + + /// <summary> + /// Read named date array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="local">Whether to read date in local (<c>true</c>) or UTC (<c>false</c>) form.</param> + /// <returns>Date array.</returns> + DateTime?[] ReadDateArray(string fieldName, bool local); + + /// <summary> + /// Read named string value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>String value.</returns> + string ReadString(string fieldName); + + /// <summary> + /// Read named string array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>String array.</returns> + string[] ReadStringArray(string fieldName); + + /// <summary> + /// Read named GUID value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>GUID value.</returns> + Guid? ReadGuid(string fieldName); + + /// <summary> + /// Read named GUID array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>GUID array.</returns> + Guid?[] ReadGuidArray(string fieldName); + + /// <summary> + /// Read named enum value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Enum value.</returns> + T ReadEnum<T>(string fieldName); + + /// <summary> + /// Read named enum array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Enum array.</returns> + T[] ReadEnumArray<T>(string fieldName); + + /// <summary> + /// Read named object. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Object.</returns> + T ReadObject<T>(string fieldName); + + /// <summary> + /// Read named object array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Object array.</returns> + T[] ReadObjectArray<T>(string fieldName); + + /// <summary> + /// Read named collection. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Collection.</returns> + ICollection ReadCollection(string fieldName); + + /// <summary> + /// Read named collection. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="factory">Factory.</param> + /// <param name="adder">Adder.</param> + /// <returns>Collection.</returns> + ICollection ReadCollection(string fieldName, PortableCollectionFactory factory, PortableCollectionAdder adder); + + /// <summary> + /// Read named generic collection. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Collection.</returns> + ICollection<T> ReadGenericCollection<T>(string fieldName); + + /// <summary> + /// Read named generic collection. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="factory">Factory.</param> + /// <returns>Collection.</returns> + ICollection<T> ReadGenericCollection<T>(string fieldName, PortableGenericCollectionFactory<T> factory); + + /// <summary> + /// Read named dictionary. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Dictionary.</returns> + IDictionary ReadDictionary(string fieldName); + + /// <summary> + /// Read named dictionary. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="factory">Factory.</param> + /// <returns>Dictionary.</returns> + IDictionary ReadDictionary(string fieldName, PortableDictionaryFactory factory); + + /// <summary> + /// Read named generic dictionary. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <returns>Dictionary.</returns> + IDictionary<TK, TV> ReadGenericDictionary<TK, TV>(string fieldName); + + /// <summary> + /// Read named generic dictionary. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="factory">Factory.</param> + /// <returns>Dictionary.</returns> + IDictionary<TK, TV> ReadGenericDictionary<TK, TV>(string fieldName, PortableGenericDictionaryFactory<TK, TV> factory); + + /// <summary> + /// Get raw reader. + /// </summary> + /// <returns>Raw reader.</returns> + IPortableRawReader RawReader(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableSerializer.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableSerializer.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableSerializer.cs new file mode 100644 index 0000000..ac40dd7 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableSerializer.cs @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Portable +{ + /// <summary> + /// Portable serializer. + /// </summary> + public interface IPortableSerializer + { + /// <summary> + /// Write portalbe object. + /// </summary> + /// <param name="obj">Object.</param> + /// <param name="writer">Poratble writer.</param> + void WritePortable(object obj, IPortableWriter writer); + + /// <summary> + /// Read portable object. + /// </summary> + /// <param name="obj">Instantiated empty object.</param> + /// <param name="reader">Poratble reader.</param> + void ReadPortable(object obj, IPortableReader reader); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableWriter.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableWriter.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableWriter.cs new file mode 100644 index 0000000..8df2d50 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortableWriter.cs @@ -0,0 +1,259 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Portable +{ + using System; + using System.Collections; + using System.Collections.Generic; + + /// <summary> + /// Writer for portable objects. + /// </summary> + public interface IPortableWriter + { + /// <summary> + /// Write named byte value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Byte value.</param> + void WriteByte(string fieldName, byte val); + + /// <summary> + /// Write named byte array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Byte array.</param> + void WriteByteArray(string fieldName, byte[] val); + + /// <summary> + /// Write named char value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Char value.</param> + void WriteChar(string fieldName, char val); + + /// <summary> + /// Write named char array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Char array.</param> + void WriteCharArray(string fieldName, char[] val); + + /// <summary> + /// Write named short value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Short value.</param> + void WriteShort(string fieldName, short val); + + /// <summary> + /// Write named short array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Short array.</param> + void WriteShortArray(string fieldName, short[] val); + + /// <summary> + /// Write named int value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Int value.</param> + void WriteInt(string fieldName, int val); + + /// <summary> + /// Write named int array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Int array.</param> + void WriteIntArray(string fieldName, int[] val); + + /// <summary> + /// Write named long value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Long value.</param> + void WriteLong(string fieldName, long val); + + /// <summary> + /// Write named long array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Long array.</param> + void WriteLongArray(string fieldName, long[] val); + + /// <summary> + /// Write named boolean value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Boolean value.</param> + void WriteBoolean(string fieldName, bool val); + + /// <summary> + /// Write named boolean array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Boolean array.</param> + void WriteBooleanArray(string fieldName, bool[] val); + + /// <summary> + /// Write named float value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Float value.</param> + void WriteFloat(string fieldName, float val); + + /// <summary> + /// Write named float array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Float array.</param> + void WriteFloatArray(string fieldName, float[] val); + + /// <summary> + /// Write named double value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Double value.</param> + void WriteDouble(string fieldName, double val); + + /// <summary> + /// Write named double array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Double array.</param> + void WriteDoubleArray(string fieldName, double[] val); + + /// <summary> + /// Write named decimal value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Decimal value.</param> + void WriteDecimal(string fieldName, decimal val); + + /// <summary> + /// Write named decimal array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Decimal array.</param> + void WriteDecimalArray(string fieldName, decimal[] val); + + /// <summary> + /// Write named date value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Date value.</param> + void WriteDate(string fieldName, DateTime? val); + + /// <summary> + /// Write named date array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Date array.</param> + void WriteDateArray(string fieldName, DateTime?[] val); + + /// <summary> + /// Write named string value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">String value.</param> + void WriteString(string fieldName, string val); + + /// <summary> + /// Write named string array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">String array.</param> + void WriteStringArray(string fieldName, string[] val); + + /// <summary> + /// Write named GUID value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">GUID value.</param> + void WriteGuid(string fieldName, Guid? val); + + /// <summary> + /// Write named GUID array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">GUID array.</param> + void WriteGuidArray(string fieldName, Guid?[] val); + + /// <summary> + /// Write named enum value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Enum value.</param> + void WriteEnum<T>(string fieldName, T val); + + /// <summary> + /// Write named enum array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Enum array.</param> + void WriteEnumArray<T>(string fieldName, T[] val); + + /// <summary> + /// Write named object value. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Object value.</param> + void WriteObject<T>(string fieldName, T val); + + /// <summary> + /// Write named object array. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Object array.</param> + void WriteObjectArray<T>(string fieldName, T[] val); + + /// <summary> + /// Write named collection. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Collection.</param> + void WriteCollection(string fieldName, ICollection val); + + /// <summary> + /// Write named generic collection. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Collection.</param> + void WriteGenericCollection<T>(string fieldName, ICollection<T> val); + + /// <summary> + /// Write named dictionary. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Dictionary.</param> + void WriteDictionary(string fieldName, IDictionary val); + + /// <summary> + /// Write named generic dictionary. + /// </summary> + /// <param name="fieldName">Field name.</param> + /// <param name="val">Dictionary.</param> + void WriteGenericDictionary<TK, TV>(string fieldName, IDictionary<TK, TV> val); + + /// <summary> + /// Get raw writer. + /// </summary> + /// <returns>Raw writer.</returns> + IPortableRawWriter RawWriter(); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortables.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortables.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortables.cs new file mode 100644 index 0000000..905eda1 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/IPortables.cs @@ -0,0 +1,120 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Portable +{ + using System; + using System.Collections.Generic; + + /// <summary> + /// Defines portable objects functionality. With portable objects you are able to: + /// <list type="bullet"> + /// <item> + /// <description>Seamlessly interoperate between Java, .NET, and C++.</description> + /// </item> + /// <item> + /// <description>Make any object portable with zero code change to your existing code.</description> + /// </item> + /// <item> + /// <description>Nest portable objects within each other.</description> + /// </item> + /// <item> + /// <description>Automatically handle <c>circular</c> or <c>null</c> references.</description> + /// </item> + /// <item> + /// <description>Automatically convert collections and maps between Java, .NET, and C++.</description> + /// </item> + /// <item> + /// <description>Optionally avoid deserialization of objects on the server side.</description> + /// </item> + /// <item> + /// <description>Avoid need to have concrete class definitions on the server side.</description> + /// </item> + /// <item> + /// <description>Dynamically change structure of the classes without having to restart the cluster.</description> + /// </item> + /// <item> + /// <description>Index into portable objects for querying purposes.</description> + /// </item> + /// </list> + /// </summary> + public interface IPortables + { + /// <summary> + /// Converts provided object to portable form. + /// <para /> + /// Note that object's type needs to be configured in <see cref="PortableConfiguration"/>. + /// </summary> + /// <param name="obj">Object to convert.</param> + /// <returns>Converted object.</returns> + T ToPortable<T>(object obj); + + /// <summary> + /// Create builder for the given portable object type. Note that this + /// type must be specified in <see cref="PortableConfiguration"/>. + /// </summary> + /// <param name="type"></param> + /// <returns>Builder.</returns> + IPortableBuilder Builder(Type type); + + /// <summary> + /// Create builder for the given portable object type name. Note that this + /// type name must be specified in <see cref="PortableConfiguration"/>. + /// </summary> + /// <param name="typeName">Type name.</param> + /// <returns>Builder.</returns> + IPortableBuilder Builder(string typeName); + + /// <summary> + /// Create builder over existing portable object. + /// </summary> + /// <param name="obj"></param> + /// <returns>Builder.</returns> + IPortableBuilder Builder(IPortableObject obj); + + /// <summary> + /// Gets type id for the given type name. + /// </summary> + /// <param name="typeName">Type name.</param> + /// <returns>Type id.</returns> + int GetTypeId(string typeName); + + /// <summary> + /// Gets metadata for all known types. + /// </summary> + /// <returns>Metadata.</returns> + ICollection<IPortableMetadata> GetMetadata(); + + /// <summary> + /// Gets metadata for specified type id. + /// </summary> + /// <returns>Metadata.</returns> + IPortableMetadata GetMetadata(int typeId); + + /// <summary> + /// Gets metadata for specified type name. + /// </summary> + /// <returns>Metadata.</returns> + IPortableMetadata GetMetadata(string typeName); + + /// <summary> + /// Gets metadata for specified type. + /// </summary> + /// <returns>Metadata.</returns> + IPortableMetadata GetMetadata(Type type); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableConfiguration.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableConfiguration.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableConfiguration.cs new file mode 100644 index 0000000..39878c2 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableConfiguration.cs @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Portable +{ + using System.Collections.Generic; + + /// <summary> + /// Portable type configuration. + /// </summary> + public class PortableConfiguration + { + /// <summary> + /// Constructor. + /// </summary> + public PortableConfiguration() + { + DefaultMetadataEnabled = true; + DefaultKeepDeserialized = true; + } + + /// <summary> + /// Copying constructor. + /// </summary> + /// <param name="cfg">Configuration to copy.</param> + public PortableConfiguration(PortableConfiguration cfg) + { + DefaultIdMapper = cfg.DefaultIdMapper; + DefaultNameMapper = cfg.DefaultNameMapper; + DefaultMetadataEnabled = cfg.DefaultMetadataEnabled; + DefaultKeepDeserialized = cfg.DefaultKeepDeserialized; + DefaultSerializer = cfg.DefaultSerializer; + + Types = cfg.Types != null ? new List<string>(cfg.Types) : null; + + if (cfg.TypeConfigurations != null) + { + TypeConfigurations = new List<PortableTypeConfiguration>(cfg.TypeConfigurations.Count); + + foreach (PortableTypeConfiguration typeCfg in cfg.TypeConfigurations) + TypeConfigurations.Add(new PortableTypeConfiguration(typeCfg)); + } + } + + /// <summary> + /// Type configurations. + /// </summary> + public ICollection<PortableTypeConfiguration> TypeConfigurations + { + get; + set; + } + + /// <summary> + /// Portable types. Shorthand for creating PortableTypeConfiguration. + /// </summary> + public ICollection<string> Types + { + get; + set; + } + + /// <summary> + /// Default name mapper. + /// </summary> + public IPortableNameMapper DefaultNameMapper + { + get; + set; + } + + /// <summary> + /// Default ID mapper. + /// </summary> + public IPortableIdMapper DefaultIdMapper + { + get; + set; + } + + /// <summary> + /// Default serializer. + /// </summary> + public IPortableSerializer DefaultSerializer + { + get; + set; + } + + /// <summary> + /// Default metadata enabled flag. Defaults to true. + /// </summary> + public bool DefaultMetadataEnabled + { + get; + set; + } + + /// <summary> + /// Default keep deserialized flag. + /// </summary> + public bool DefaultKeepDeserialized + { + get; + set; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableException.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableException.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableException.cs new file mode 100644 index 0000000..95edbc0 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableException.cs @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Portable +{ + using System; + using System.Runtime.Serialization; + using Apache.Ignite.Core.Common; + + /// <summary> + /// Indicates an error during portable marshalling. + /// </summary> + [Serializable] + public class PortableException : IgniteException + { + /// <summary> + /// Constructs an exception. + /// </summary> + public PortableException() + { + // No-op. + } + + /// <summary> + /// Initializes a new instance of the <see cref="PortableException"/> class. + /// </summary> + /// <param name="message">The message that describes the error.</param> + public PortableException(string message) + : base(message) { + } + + /// <summary> + /// Initializes a new instance of the <see cref="PortableException"/> class. + /// </summary> + /// <param name="message">The message.</param> + /// <param name="cause">The cause.</param> + public PortableException(string message, Exception cause) + : base(message, cause) { + } + + /// <summary> + /// Constructs an exception. + /// </summary> + /// <param name="info">Serialization info.</param> + /// <param name="ctx">Streaming context.</param> + protected PortableException(SerializationInfo info, StreamingContext ctx) + : base(info, ctx) { + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableTypeConfiguration.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableTypeConfiguration.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableTypeConfiguration.cs new file mode 100644 index 0000000..bbbd4a8 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableTypeConfiguration.cs @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Portable +{ + using System; + + /// <summary> + /// Portable type configuration. + /// </summary> + public class PortableTypeConfiguration + { + /// <summary> + /// Constructor. + /// </summary> + public PortableTypeConfiguration() + { + // No-op. + } + + /// <summary> + /// Constructor. + /// </summary> + /// <param name="typeName">Type name.</param> + public PortableTypeConfiguration(string typeName) + { + TypeName = typeName; + } + + /// <summary> + /// Constructor. + /// </summary> + /// <param name="type">Type.</param> + public PortableTypeConfiguration(Type type) + { + TypeName = type.FullName; + } + + /// <summary> + /// Copying constructor. + /// </summary> + /// <param name="cfg">Configuration to copy.</param> + public PortableTypeConfiguration(PortableTypeConfiguration cfg) + { + AffinityKeyFieldName = cfg.AffinityKeyFieldName; + AssemblyName = cfg.AssemblyName; + IdMapper = cfg.IdMapper; + NameMapper = cfg.NameMapper; + Serializer = cfg.Serializer; + TypeName = cfg.TypeName; + MetadataEnabled = cfg.MetadataEnabled; + KeepDeserialized = cfg.KeepDeserialized; + } + + /// <summary> + /// Assembly name. + /// </summary> + public string AssemblyName + { + get; + set; + } + + /// <summary> + /// Fully qualified type name. + /// </summary> + public string TypeName + { + get; + set; + } + + /// <summary> + /// Name mapper for the given type. + /// </summary> + public IPortableNameMapper NameMapper + { + get; + set; + } + + /// <summary> + /// ID mapper for the given type. When it is necessary to resolve class (field) ID, then + /// this property will be checked first. If not set, then PortableClassIdAttribute + /// (PortableFieldIdAttribute) will be checked in class through reflection. If required + /// attribute is not set, then ID will be hash code of the class (field) simple name in lower case. + /// </summary> + public IPortableIdMapper IdMapper + { + get; + set; + } + + /// <summary> + /// Serializer for the given type. If not provided and class implements IPortable + /// then its custom logic will be used. If not provided and class doesn't implement IPortable + /// then all fields of the class except of those with [NotSerialized] attribute will be serialized + ///with help of reflection. + /// </summary> + public IPortableSerializer Serializer + { + get; + set; + } + + /// <summary> + /// Affinity key field name. + /// </summary> + public string AffinityKeyFieldName + { + get; + set; + } + + /// <summary> + /// Metadata enabled flag. If set to non-null value, overrides default value set in + /// PortableConfiguration. + /// </summary> + public bool? MetadataEnabled + { + get; + set; + } + + /// <summary> + /// Keep deserialized flag. If set to non-null value, overrides default value set in + /// PortableConfiguration. + /// </summary> + public bool? KeepDeserialized + { + get; + set; + } + + /// <summary> + /// Returns a string that represents the current object. + /// </summary> + /// <returns> + /// A string that represents the current object. + /// </returns> + override public string ToString() + { + return typeof(PortableTypeConfiguration).Name + " [TypeName=" + TypeName + + ", NameMapper=" + NameMapper + ", IdMapper=" + IdMapper + ", Serializer=" + Serializer + + ", AffinityKeyFieldName=" + AffinityKeyFieldName + ']'; + } + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableTypeNames.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableTypeNames.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableTypeNames.cs new file mode 100644 index 0000000..ed792c3 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Portable/PortableTypeNames.cs @@ -0,0 +1,115 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Portable +{ + /// <summary> + /// Portable type name constants. + /// </summary> + public static class PortableTypeNames + { + /** Type name: boolean. */ + public const string TypeNameBool = "boolean"; + + /** Type name: byte. */ + public const string TypeNameByte = "byte"; + + /** Type name: short. */ + public const string TypeNameShort = "short"; + + /** Type name: char. */ + public const string TypeNameChar = "char"; + + /** Type name: int. */ + public const string TypeNameInt = "int"; + + /** Type name: long. */ + public const string TypeNameLong = "long"; + + /** Type name: float. */ + public const string TypeNameFloat = "float"; + + /** Type name: double. */ + public const string TypeNameDouble = "double"; + + /** Type name: decimal. */ + public const string TypeNameDecimal = "decimal"; + + /** Type name: String. */ + public const string TypeNameString = "String"; + + /** Type name: UUID. */ + public const string TypeNameGuid = "UUID"; + + /** Type name: Date. */ + public const string TypeNameDate = "Date"; + + /** Type name: Enum. */ + public const string TypeNameEnum = "Enum"; + + /** Type name: Object. */ + public const string TypeNameObject = "Object"; + + /** Type name: boolean array. */ + public const string TypeNameArrayBool = "boolean[]"; + + /** Type name: byte array. */ + public const string TypeNameArrayByte = "byte[]"; + + /** Type name: short array. */ + public const string TypeNameArrayShort = "short[]"; + + /** Type name: char array. */ + public const string TypeNameArrayChar = "char[]"; + + /** Type name: int array. */ + public const string TypeNameArrayInt = "int[]"; + + /** Type name: long array. */ + public const string TypeNameArrayLong = "long[]"; + + /** Type name: float array. */ + public const string TypeNameArrayFloat = "float[]"; + + /** Type name: double array. */ + public const string TypeNameArrayDouble = "double[]"; + + /** Type name: decimal array. */ + public const string TypeNameArrayDecimal = "decimal[]"; + + /** Type name: String array. */ + public const string TypeNameArrayString = "String[]"; + + /** Type name: UUID array. */ + public const string TypeNameArrayGuid = "UUID[]"; + + /** Type name: Date array. */ + public const string TypeNameArrayDate = "Date[]"; + + /** Type name: Enum array. */ + public const string TypeNameArrayEnum = "Enum[]"; + + /** Type name: Object array. */ + public const string TypeNameArrayObject = "Object[]"; + + /** Type name: Collection. */ + public const string TypeNameCollection = "Collection"; + + /** Type name: Map. */ + public const string TypeNameMap = "Map"; + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Resource/InstanceResourceAttribute.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Resource/InstanceResourceAttribute.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Resource/InstanceResourceAttribute.cs new file mode 100644 index 0000000..8b34c10 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Resource/InstanceResourceAttribute.cs @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Resource +{ + using System; + using Apache.Ignite.Core.Compute; + using Apache.Ignite.Core.Impl.Compute; + + /// <summary> + /// Attribute which injects <see cref="IIgnite"/> instance. Can be defined inside + /// implementors of <see cref="IComputeTask{A,T,TR}"/> and <see cref="IComputeJob"/> interfaces. + /// Can be applied to non-static fields, properties and methods returning <c>void</c> and + /// accepting a single parameter. + /// </summary> + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Property)] + public sealed class InstanceResourceAttribute : Attribute + { + // No-op. + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Resource/StoreSessionResourceAttribute.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Resource/StoreSessionResourceAttribute.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Resource/StoreSessionResourceAttribute.cs new file mode 100644 index 0000000..624c71d --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Resource/StoreSessionResourceAttribute.cs @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Resource +{ + using System; + using Apache.Ignite.Core.Cache.Store; + + /// <summary> + /// Annotates a field or a setter method for injection of current <see cref="ICacheStoreSession"/> + /// instance. It can be injected into <see cref="ICacheStore"/>. + /// </summary> + [AttributeUsage(AttributeTargets.Field | AttributeTargets.Method | AttributeTargets.Property)] + public sealed class StoreSessionResourceAttribute : Attribute + { + // No-op. + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IService.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IService.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IService.cs new file mode 100644 index 0000000..3668221 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IService.cs @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Services +{ + /// <summary> + /// Represents Ignite-managed service. + /// </summary> + public interface IService + { + /// <summary> + /// Initializes this instance before execution. + /// </summary> + /// <param name="context">Service execution context.</param> + void Init(IServiceContext context); + + /// <summary> + /// Starts execution of this service. This method is automatically invoked whenever an instance of the service + /// is deployed on a Ignite node. Note that service is considered deployed even after it exits the Execute + /// method and can be cancelled (or undeployed) only by calling any of the Cancel methods on + /// <see cref="IServices"/> API. Also note that service is not required to exit from Execute method until + /// Cancel method was called. + /// </summary> + /// <param name="context">Service execution context.</param> + void Execute(IServiceContext context); + + /// <summary> + /// Cancels this instance. + /// <para/> + /// Note that Ignite cannot guarantee that the service exits from <see cref="IService.Execute"/> + /// method whenever <see cref="IService.Cancel"/> is called. It is up to the user to + /// make sure that the service code properly reacts to cancellations. + /// </summary> + /// <param name="context">Service execution context.</param> + void Cancel(IServiceContext context); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServiceContext.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServiceContext.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServiceContext.cs new file mode 100644 index 0000000..50c3f14 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServiceContext.cs @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Services +{ + using System; + + /// <summary> + /// Represents service execution context. + /// </summary> + public interface IServiceContext + { + /// <summary> + /// Gets service name. + /// </summary> + /// <returns> + /// Service name. + /// </returns> + string Name { get; } + + /// <summary> + /// Gets service execution ID. Execution ID is guaranteed to be unique across all service deployments. + /// </summary> + /// <returns> + /// Service execution ID. + /// </returns> + Guid ExecutionId { get; } + + /// <summary> + /// Get flag indicating whether service has been cancelled or not. + /// </summary> + /// <returns> + /// Flag indicating whether service has been cancelled or not. + /// </returns> + bool IsCancelled { get; } + + /// <summary> + /// Gets cache name used for key-to-node affinity calculation. + /// This parameter is optional and is set only when key-affinity service was deployed. + /// </summary> + /// <returns> + /// Cache name, possibly null. + /// </returns> + string CacheName { get; } + + /// <summary> + /// Gets affinity key used for key-to-node affinity calculation. + /// This parameter is optional and is set only when key-affinity service was deployed. + /// </summary> + /// <value> + /// Affinity key, possibly null. + /// </value> + object AffinityKey { get; } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServiceDescriptor.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServiceDescriptor.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServiceDescriptor.cs new file mode 100644 index 0000000..96bad4f --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServiceDescriptor.cs @@ -0,0 +1,96 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Services +{ + using System; + using System.Collections.Generic; + + /// <summary> + /// Service deployment descriptor. + /// </summary> + public interface IServiceDescriptor + { + /// <summary> + /// Gets service name. + /// </summary> + /// <returns> + /// Service name. + /// </returns> + string Name { get; } + + /// <summary> + /// Gets the service type. + /// </summary> + /// <value> + /// Service type. + /// </value> + Type Type { get; } + + /// <summary> + /// Gets maximum allowed total number of deployed services in the grid, 0 for unlimited. + /// </summary> + /// <returns> + /// Maximum allowed total number of deployed services in the grid, 0 for unlimited. + /// </returns> + int TotalCount { get; } + + /// <summary> + /// Gets maximum allowed number of deployed services on each node, 0 for unlimited. + /// </summary> + /// <returns> + /// Maximum allowed total number of deployed services on each node, 0 for unlimited. + /// </returns> + int MaxPerNodeCount { get; } + + /// <summary> + /// Gets cache name used for key-to-node affinity calculation. + /// This parameter is optional and is set only when key-affinity service was deployed. + /// </summary> + /// <returns> + /// Cache name, possibly null. + /// </returns> + string CacheName { get; } + + /// <summary> + /// Gets affinity key used for key-to-node affinity calculation. + /// This parameter is optional and is set only when key-affinity service was deployed. + /// </summary> + /// <value> + /// Affinity key, possibly null. + /// </value> + object AffinityKey { get; } + + /// <summary> + /// Gets affinity key used for key-to-node affinity calculation. + /// This parameter is optional and is set only when key-affinity service was deployed. + /// </summary> + /// <returns> + /// Affinity key, possibly null. + /// </returns> + Guid OriginNodeId { get; } + + /// <summary> + /// Gets service deployment topology snapshot. Service topology snapshot is represented + /// by number of service instances deployed on a node mapped to node ID. + /// </summary> + /// <value> + /// Map of number of service instances per node ID. + /// </value> + IDictionary<Guid, int> TopologySnapshot { get; } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/ignite/blob/5cec202c/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServices.cs ---------------------------------------------------------------------- diff --git a/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServices.cs b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServices.cs new file mode 100644 index 0000000..fff25c3 --- /dev/null +++ b/modules/platform/src/main/dotnet/Apache.Ignite.Core/Services/IServices.cs @@ -0,0 +1,181 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +namespace Apache.Ignite.Core.Services +{ + using System.Collections.Generic; + using Apache.Ignite.Core.Cluster; + using Apache.Ignite.Core.Common; + + /// <summary> + /// Defines functionality to deploy distributed services in the Ignite. + /// </summary> + public interface IServices : IAsyncSupport<IServices> + { + /// <summary> + /// Gets the cluster group to which this instance belongs. + /// </summary> + /// <value> + /// The cluster group to which this instance belongs. + /// </value> + IClusterGroup ClusterGroup { get; } + + /// <summary> + /// Deploys a cluster-wide singleton service. Ignite guarantees that there is always + /// one instance of the service in the cluster. In case if Ignite node on which the service + /// was deployed crashes or stops, Ignite will automatically redeploy it on another node. + /// However, if the node on which the service is deployed remains in topology, then the + /// service will always be deployed on that node only, regardless of topology changes. + /// <para /> + /// Note that in case of topology changes, due to network delays, there may be a temporary situation + /// when a singleton service instance will be active on more than one node (e.g. crash detection delay). + /// </summary> + /// <param name="name">Service name.</param> + /// <param name="service">Service instance.</param> + [AsyncSupported] + void DeployClusterSingleton(string name, IService service); + + /// <summary> + /// Deploys a per-node singleton service. Ignite guarantees that there is always + /// one instance of the service running on each node. Whenever new nodes are started + /// within the underlying cluster group, Ignite will automatically deploy one instance of + /// the service on every new node. + /// </summary> + /// <param name="name">Service name.</param> + /// <param name="service">Service instance.</param> + [AsyncSupported] + void DeployNodeSingleton(string name, IService service); + + /// <summary> + /// Deploys one instance of this service on the primary node for a given affinity key. + /// Whenever topology changes and primary node assignment changes, Ignite will always + /// make sure that the service is undeployed on the previous primary node and deployed + /// on the new primary node. + /// <para /> + /// Note that in case of topology changes, due to network delays, there may be a temporary situation + /// when a service instance will be active on more than one node (e.g. crash detection delay). + /// </summary> + /// <param name="name">Service name.</param> + /// <param name="service">Service instance.</param> + /// <param name="cacheName">Name of the cache on which affinity for key should be calculated, null for + /// default cache.</param> + /// <param name="affinityKey">Affinity cache key.</param> + [AsyncSupported] + void DeployKeyAffinitySingleton<TK>(string name, IService service, string cacheName, TK affinityKey); + + /// <summary> + /// Deploys multiple instances of the service on the grid. Ignite will deploy a + /// maximum amount of services equal to <paramref name="totalCount" /> parameter making sure that + /// there are no more than <paramref name="maxPerNodeCount" /> service instances running + /// on each node. Whenever topology changes, Ignite will automatically rebalance + /// the deployed services within cluster to make sure that each node will end up with + /// about equal number of deployed instances whenever possible. + /// </summary> + /// <param name="name">Service name.</param> + /// <param name="service">Service instance.</param> + /// <param name="totalCount">Maximum number of deployed services in the grid, 0 for unlimited.</param> + /// <param name="maxPerNodeCount">Maximum number of deployed services on each node, 0 for unlimited.</param> + [AsyncSupported] + void DeployMultiple(string name, IService service, int totalCount, int maxPerNodeCount); + + /// <summary> + /// Deploys instances of the service in the Ignite according to provided configuration. + /// </summary> + /// <param name="configuration">Service configuration.</param> + [AsyncSupported] + void Deploy(ServiceConfiguration configuration); + + /// <summary> + /// Cancels service deployment. If a service with specified name was deployed on the grid, + /// then <see cref="IService.Cancel"/> method will be called on it. + /// <para/> + /// Note that Ignite cannot guarantee that the service exits from <see cref="IService.Execute"/> + /// method whenever <see cref="IService.Cancel"/> is called. It is up to the user to + /// make sure that the service code properly reacts to cancellations. + /// </summary> + /// <param name="name">Name of the service to cancel.</param> + [AsyncSupported] + void Cancel(string name); + + /// <summary> + /// Cancels all deployed services. + /// <para/> + /// Note that depending on user logic, it may still take extra time for a service to + /// finish execution, even after it was cancelled. + /// </summary> + [AsyncSupported] + void CancelAll(); + + /// <summary> + /// Gets metadata about all deployed services. + /// </summary> + /// <returns>Metadata about all deployed services.</returns> + ICollection<IServiceDescriptor> GetServiceDescriptors(); + + /// <summary> + /// Gets deployed service with specified name. + /// </summary> + /// <typeparam name="T">Service type.</typeparam> + /// <param name="name">Service name.</param> + /// <returns>Deployed service with specified name.</returns> + T GetService<T>(string name); + + /// <summary> + /// Gets all deployed services with specified name. + /// </summary> + /// <typeparam name="T">Service type.</typeparam> + /// <param name="name">Service name.</param> + /// <returns>All deployed services with specified name.</returns> + ICollection<T> GetServices<T>(string name); + + /// <summary> + /// Gets a remote handle on the service. If service is available locally, + /// then local instance is returned, otherwise, a remote proxy is dynamically + /// created and provided for the specified service. + /// </summary> + /// <typeparam name="T">Service type.</typeparam> + /// <param name="name">Service name.</param> + /// <returns>Either proxy over remote service or local service if it is deployed locally.</returns> + T GetServiceProxy<T>(string name) where T : class; + + /// <summary> + /// Gets a remote handle on the service. If service is available locally, + /// then local instance is returned, otherwise, a remote proxy is dynamically + /// created and provided for the specified service. + /// </summary> + /// <typeparam name="T">Service type.</typeparam> + /// <param name="name">Service name.</param> + /// <param name="sticky">Whether or not Ignite should always contact the same remote + /// service or try to load-balance between services.</param> + /// <returns>Either proxy over remote service or local service if it is deployed locally.</returns> + T GetServiceProxy<T>(string name, bool sticky) where T : class; + + /// <summary> + /// Returns an instance with portable mode enabled. + /// Service method results will be kept in portable form. + /// </summary> + /// <returns>Instance with portable mode enabled.</returns> + IServices WithKeepPortable(); + + /// <summary> + /// Returns an instance with server-side portable mode enabled. + /// Service method arguments will be kept in portable form. + /// </summary> + /// <returns>Instance with server-side portable mode enabled.</returns> + IServices WithServerKeepPortable(); + } +} \ No newline at end of file
