/// <summary> /// Writes the instance. /// </summary> internal static void Write(IBinaryRawWriter writer, IAffinityFunction fun) { if (fun == null) { writer.WriteByte(TypeCodeNull); return; } var p = fun as AffinityFunctionBase; if (p != null) { writer.WriteByte(p is FairAffinityFunction ? TypeCodeFair : TypeCodeRendezvous); writer.WriteInt(p.Partitions); writer.WriteBoolean(p.ExcludeNeighbors); } else { writer.WriteByte(TypeCodeUser); if (!fun.GetType().IsSerializable) { throw new IgniteException("AffinityFunction should be serializable."); } writer.WriteObject(fun); writer.WriteInt(fun.Partitions); // partition count is written once and can not be changed. } }
/// <summary> /// Writes the user function. /// </summary> private static void WriteUserFunc(IBinaryRawWriter writer, IAffinityFunction func, object funcOverride) { if (funcOverride != null) { writer.WriteObject(funcOverride); return; } writer.WriteObject(func); }
/// <summary> /// Asserts that two configurations have the same properties. /// </summary> private static void AssertConfigsAreEqual(IAffinityFunction x, IAffinityFunction y) { if (x == null) { Assert.IsNull(y); return; } var px = (AffinityFunctionBase)x; var py = (AffinityFunctionBase)y; Assert.AreEqual(px.GetType(), py.GetType()); Assert.AreEqual(px.Partitions, py.Partitions); Assert.AreEqual(px.ExcludeNeighbors, py.ExcludeNeighbors); }
/// <summary> /// Writes the user function. /// </summary> private static void WriteUserFunc(IBinaryRawWriter writer, IAffinityFunction func, object funcOverride) { if (funcOverride != null) { writer.WriteObject(funcOverride); return; } if (func != null && !func.GetType().IsSerializable) { throw new IgniteException("AffinityFunction should be serializable."); } writer.WriteObject(func); }
/// <summary> /// Asserts that two configurations have the same properties. /// </summary> private static void AssertConfigsAreEqual(IAffinityFunction x, IAffinityFunction y) { if (x == null) { Assert.IsNull(y); return; } var px = (RendezvousAffinityFunction)x; var py = (RendezvousAffinityFunction)y; Assert.AreEqual(px.GetType(), py.GetType()); Assert.AreEqual(px.Partitions, py.Partitions); Assert.AreEqual(px.ExcludeNeighbors, py.ExcludeNeighbors); AssertConfigsAreEqual(px.AffinityBackupFilter, py.AffinityBackupFilter); }
/// <summary> /// Writes the instance. /// </summary> internal static void Write(IBinaryRawWriter writer, IAffinityFunction fun, object userFuncOverride = null) { Debug.Assert(writer != null); if (fun == null) { writer.WriteByte(TypeCodeNull); return; } // 1) Type code // 2) Partitions // 3) ExcludeNeighbors // 4) Override flags // 5) User object var p = fun as RendezvousAffinityFunction; if (p != null) { writer.WriteByte(TypeCodeRendezvous); writer.WriteInt(p.Partitions); writer.WriteBoolean(p.ExcludeNeighbors); var overrideFlags = GetOverrideFlags(p.GetType()); writer.WriteByte((byte)overrideFlags); // Do not write user func if there is nothing overridden WriteUserFunc(writer, overrideFlags != UserOverrides.None ? fun : null, userFuncOverride); WriteBackupFilter(writer, p); } else { writer.WriteByte(TypeCodeUser); writer.WriteInt(fun.Partitions); writer.WriteBoolean(false); // Exclude neighbors writer.WriteByte((byte)UserOverrides.All); WriteUserFunc(writer, fun, userFuncOverride); } }
/// <summary> /// Writes the instance. /// </summary> internal static void Write(IBinaryRawWriter writer, IAffinityFunction fun, object userFuncOverride = null) { Debug.Assert(writer != null); if (fun == null) { writer.WriteByte(TypeCodeNull); return; } // 1) Type code // 2) Partitions // 3) ExcludeNeighbors // 4) Override flags // 5) User object var p = fun as AffinityFunctionBase; if (p != null) { writer.WriteByte(p is FairAffinityFunction ? TypeCodeFair : TypeCodeRendezvous); writer.WriteInt(p.Partitions); writer.WriteBoolean(p.ExcludeNeighbors); var overrideFlags = GetOverrideFlags(p.GetType()); writer.WriteByte((byte) overrideFlags); // Do not write user func if there is nothing overridden WriteUserFunc(writer, overrideFlags != UserOverrides.None ? fun : null, userFuncOverride); } else { writer.WriteByte(TypeCodeUser); writer.WriteInt(fun.Partitions); writer.WriteBoolean(false); // Exclude neighbors writer.WriteByte((byte) UserOverrides.All); WriteUserFunc(writer, fun, userFuncOverride); } }
/// <summary> /// Sets the base function. /// </summary> /// <param name="baseFunc">The base function.</param> internal void SetBaseFunction(IAffinityFunction baseFunc) { _baseFunction = baseFunc; }
/// <summary> /// Writes the instance. /// </summary> internal static void Write(IBinaryRawWriter writer, IAffinityFunction fun) { if (fun == null) { writer.WriteByte(TypeCodeNull); return; } var p = fun as AffinityFunctionBase; if (p != null) { ValidateAffinityFunctionType(p.GetType()); writer.WriteByte(p is FairAffinityFunction ? TypeCodeFair : TypeCodeRendezvous); writer.WriteInt(p.Partitions); writer.WriteBoolean(p.ExcludeNeighbors); } else { writer.WriteByte(TypeCodeUser); if (!fun.GetType().IsSerializable) throw new IgniteException("AffinityFunction should be serializable."); writer.WriteObject(fun); writer.WriteInt(fun.Partitions); // partition count is written once and can not be changed. } }
/// <summary> /// Writes the user function. /// </summary> private static void WriteUserFunc(IBinaryRawWriter writer, IAffinityFunction func, object funcOverride) { if (funcOverride != null) { writer.WriteObject(funcOverride); return; } if (func != null && !func.GetType().IsSerializable) throw new IgniteException("AffinityFunction should be serializable."); writer.WriteObject(func); }