/// <summary> /// Writes this instance to the specified writer. /// </summary> /// <param name="writer">The writer.</param> internal void Write(IBinaryRawWriter writer) { writer.WriteInt((int)AtomicityMode); writer.WriteInt((int)AtomicWriteOrderMode); writer.WriteInt(Backups); writer.WriteInt((int)CacheMode); writer.WriteBoolean(CopyOnRead); writer.WriteBoolean(EagerTtl); writer.WriteBoolean(EnableSwap); writer.WriteBoolean(EvictSynchronized); writer.WriteInt(EvictSynchronizedConcurrencyLevel); writer.WriteInt(EvictSynchronizedKeyBufferSize); writer.WriteLong((long)EvictSynchronizedTimeout.TotalMilliseconds); writer.WriteBoolean(Invalidate); writer.WriteBoolean(KeepBinaryInStore); writer.WriteBoolean(LoadPreviousValue); writer.WriteLong((long)LockTimeout.TotalMilliseconds); writer.WriteLong((long)LongQueryWarningTimeout.TotalMilliseconds); writer.WriteInt(MaxConcurrentAsyncOperations); writer.WriteFloat(MaxEvictionOverflowRatio); writer.WriteInt((int)MemoryMode); writer.WriteString(Name); writer.WriteLong(OffHeapMaxMemory); writer.WriteBoolean(ReadFromBackup); writer.WriteInt(RebalanceBatchSize); writer.WriteLong((long)RebalanceDelay.TotalMilliseconds); writer.WriteInt((int)RebalanceMode); writer.WriteLong((long)RebalanceThrottle.TotalMilliseconds); writer.WriteLong((long)RebalanceTimeout.TotalMilliseconds); writer.WriteBoolean(SqlEscapeAll); writer.WriteInt(SqlOnheapRowCacheSize); writer.WriteInt(StartSize); writer.WriteInt(WriteBehindBatchSize); writer.WriteBoolean(WriteBehindEnabled); writer.WriteLong((long)WriteBehindFlushFrequency.TotalMilliseconds); writer.WriteInt(WriteBehindFlushSize); writer.WriteInt(WriteBehindFlushThreadCount); writer.WriteInt((int)WriteSynchronizationMode); writer.WriteBoolean(ReadThrough); writer.WriteBoolean(WriteThrough); writer.WriteBoolean(EnableStatistics); writer.WriteObject(CacheStoreFactory); if (QueryEntities != null) { writer.WriteInt(QueryEntities.Count); foreach (var entity in QueryEntities) { if (entity == null) { throw new InvalidOperationException("Invalid cache configuration: QueryEntity can't be null."); } entity.Write(writer); } } else { writer.WriteInt(0); } if (NearConfiguration != null) { writer.WriteBoolean(true); NearConfiguration.Write(writer); } else { writer.WriteBoolean(false); } EvictionPolicyBase.Write(writer, EvictionPolicy); AffinityFunctionSerializer.Write(writer, AffinityFunction); ExpiryPolicySerializer.WritePolicyFactory(writer, ExpiryPolicyFactory); if (PluginConfigurations != null) { writer.WriteInt(PluginConfigurations.Count); foreach (var cachePlugin in PluginConfigurations) { if (cachePlugin == null) { throw new InvalidOperationException("Invalid cache configuration: " + "ICachePluginConfiguration can't be null."); } if (cachePlugin.CachePluginConfigurationClosureFactoryId != null) { writer.WriteBoolean(true); writer.WriteInt(cachePlugin.CachePluginConfigurationClosureFactoryId.Value); cachePlugin.WriteBinary(writer); } else { if (!cachePlugin.GetType().IsSerializable) { throw new InvalidOperationException("Invalid cache configuration: " + "ICachePluginConfiguration should be Serializable."); } writer.WriteBoolean(false); writer.WriteObject(cachePlugin); } } } else { writer.WriteInt(0); } }
/// <summary> /// Writes this instance to the specified writer. /// </summary> /// <param name="writer">The writer.</param> internal void Write(BinaryWriter writer) { // Make sure system marshaller is used. Debug.Assert(writer.Marshaller == BinaryUtils.Marshaller); writer.WriteInt((int)AtomicityMode); writer.WriteInt(Backups); writer.WriteInt((int)CacheMode); writer.WriteBoolean(CopyOnRead); writer.WriteBoolean(EagerTtl); writer.WriteBoolean(Invalidate); writer.WriteBoolean(KeepBinaryInStore); writer.WriteBoolean(LoadPreviousValue); writer.WriteLong((long)LockTimeout.TotalMilliseconds); #pragma warning disable 618 writer.WriteLong((long)LongQueryWarningTimeout.TotalMilliseconds); #pragma warning restore 618 writer.WriteInt(MaxConcurrentAsyncOperations); writer.WriteString(Name); writer.WriteBoolean(ReadFromBackup); writer.WriteInt(RebalanceBatchSize); writer.WriteLong((long)RebalanceDelay.TotalMilliseconds); writer.WriteInt((int)RebalanceMode); writer.WriteLong((long)RebalanceThrottle.TotalMilliseconds); writer.WriteLong((long)RebalanceTimeout.TotalMilliseconds); writer.WriteBoolean(SqlEscapeAll); writer.WriteInt(WriteBehindBatchSize); writer.WriteBoolean(WriteBehindEnabled); writer.WriteLong((long)WriteBehindFlushFrequency.TotalMilliseconds); writer.WriteInt(WriteBehindFlushSize); writer.WriteInt(WriteBehindFlushThreadCount); writer.WriteBoolean(WriteBehindCoalescing); writer.WriteInt((int)WriteSynchronizationMode); writer.WriteBoolean(ReadThrough); writer.WriteBoolean(WriteThrough); writer.WriteBoolean(EnableStatistics); writer.WriteString(DataRegionName); writer.WriteInt((int)PartitionLossPolicy); writer.WriteString(GroupName); writer.WriteObject(CacheStoreFactory); writer.WriteInt(SqlIndexMaxInlineSize); writer.WriteBoolean(OnheapCacheEnabled); writer.WriteInt(StoreConcurrentLoadAllThreshold); writer.WriteInt(RebalanceOrder); writer.WriteLong(RebalanceBatchesPrefetchCount); writer.WriteInt(MaxQueryIteratorsCount); writer.WriteInt(QueryDetailMetricsSize); writer.WriteInt(QueryParallelism); writer.WriteString(SqlSchema); writer.WriteCollectionRaw(QueryEntities); if (NearConfiguration != null) { writer.WriteBoolean(true); NearConfiguration.Write(writer); } else { writer.WriteBoolean(false); } EvictionPolicyBase.Write(writer, EvictionPolicy); AffinityFunctionSerializer.Write(writer, AffinityFunction); ExpiryPolicySerializer.WritePolicyFactory(writer, ExpiryPolicyFactory); writer.WriteCollectionRaw(KeyConfiguration); if (PluginConfigurations != null) { writer.WriteInt(PluginConfigurations.Count); foreach (var cachePlugin in PluginConfigurations) { if (cachePlugin == null) { throw new InvalidOperationException("Invalid cache configuration: " + "ICachePluginConfiguration can't be null."); } if (cachePlugin.CachePluginConfigurationClosureFactoryId != null) { writer.WriteBoolean(true); writer.WriteInt(cachePlugin.CachePluginConfigurationClosureFactoryId.Value); int pos = writer.Stream.Position; writer.WriteInt(0); // Reserve size. cachePlugin.WriteBinary(writer); writer.Stream.WriteInt(pos, writer.Stream.Position - pos - 4); // Write size. } else { writer.WriteBoolean(false); writer.WriteObject(cachePlugin); } } } else { writer.WriteInt(0); } }
/// <summary> /// Writes the specified config. /// </summary> public static void Write(IBinaryStream stream, CacheClientConfiguration cfg, ClientFeatures features, bool skipCodes = false) { Debug.Assert(stream != null); Debug.Assert(cfg != null); // Configuration should be written with a system marshaller. var writer = BinaryUtils.Marshaller.StartMarshal(stream); var pos = writer.Stream.Position; writer.WriteInt(0); // Reserve for length. if (!skipCodes) { writer.WriteShort(PropertyCount); // Property count. } var code = skipCodes ? (Action <Op>)(o => { }) : o => writer.WriteShort((short)o); code(Op.AtomicityMode); writer.WriteInt((int)cfg.AtomicityMode); code(Op.Backups); writer.WriteInt(cfg.Backups); code(Op.CacheMode); writer.WriteInt((int)cfg.CacheMode); code(Op.CopyOnRead); writer.WriteBoolean(cfg.CopyOnRead); code(Op.DataRegionName); writer.WriteString(cfg.DataRegionName); code(Op.EagerTtl); writer.WriteBoolean(cfg.EagerTtl); code(Op.StatisticsEnabled); writer.WriteBoolean(cfg.EnableStatistics); code(Op.GroupName); writer.WriteString(cfg.GroupName); code(Op.DefaultLockTimeout); writer.WriteTimeSpanAsLong(cfg.LockTimeout); code(Op.MaxConcurrentAsyncOperations); writer.WriteInt(cfg.MaxConcurrentAsyncOperations); code(Op.MaxQueryIteratorsCount); writer.WriteInt(cfg.MaxQueryIteratorsCount); code(Op.Name); writer.WriteString(cfg.Name); code(Op.OnheapCacheEnabled); writer.WriteBoolean(cfg.OnheapCacheEnabled); code(Op.PartitionLossPolicy); writer.WriteInt((int)cfg.PartitionLossPolicy); code(Op.QueryDetailMetricsSize); writer.WriteInt(cfg.QueryDetailMetricsSize); code(Op.QueryParallelism); writer.WriteInt(cfg.QueryParallelism); code(Op.ReadFromBackup); writer.WriteBoolean(cfg.ReadFromBackup); code(Op.RebalanceBatchSize); writer.WriteInt(cfg.RebalanceBatchSize); code(Op.RebalanceBatchesPrefetchCount); writer.WriteLong(cfg.RebalanceBatchesPrefetchCount); code(Op.RebalanceDelay); writer.WriteTimeSpanAsLong(cfg.RebalanceDelay); code(Op.RebalanceMode); writer.WriteInt((int)cfg.RebalanceMode); code(Op.RebalanceOrder); writer.WriteInt(cfg.RebalanceOrder); code(Op.RebalanceThrottle); writer.WriteTimeSpanAsLong(cfg.RebalanceThrottle); code(Op.RebalanceTimeout); writer.WriteTimeSpanAsLong(cfg.RebalanceTimeout); code(Op.SqlEscapeAll); writer.WriteBoolean(cfg.SqlEscapeAll); code(Op.SqlIndexMaxInlineSize); writer.WriteInt(cfg.SqlIndexMaxInlineSize); code(Op.SqlSchema); writer.WriteString(cfg.SqlSchema); code(Op.WriteSynchronizationMode); writer.WriteInt((int)cfg.WriteSynchronizationMode); code(Op.KeyConfiguration); writer.WriteCollectionRaw(cfg.KeyConfiguration); code(Op.QueryEntities); writer.WriteCollectionRaw(cfg.QueryEntities, (w, qe) => WriteQueryEntity(w, qe, features)); code(Op.ExpiryPolicy); ExpiryPolicySerializer.WritePolicyFactory(writer, cfg.ExpiryPolicyFactory); // Write length (so that part of the config can be skipped). var len = writer.Stream.Position - pos - 4; writer.Stream.WriteInt(pos, len); }
/// <summary> /// Writes this instance to the specified writer. /// </summary> /// <param name="writer">The writer.</param> internal void Write(IBinaryRawWriter writer) { // Make sure system marshaller is used. Debug.Assert(((BinaryWriter)writer).Marshaller == BinaryUtils.Marshaller); writer.WriteInt((int)AtomicityMode); writer.WriteInt(Backups); writer.WriteInt((int)CacheMode); writer.WriteBoolean(CopyOnRead); writer.WriteBoolean(EagerTtl); writer.WriteBoolean(Invalidate); writer.WriteBoolean(KeepBinaryInStore); writer.WriteBoolean(LoadPreviousValue); writer.WriteLong((long)LockTimeout.TotalMilliseconds); writer.WriteLong((long)LongQueryWarningTimeout.TotalMilliseconds); writer.WriteInt(MaxConcurrentAsyncOperations); writer.WriteString(Name); writer.WriteBoolean(ReadFromBackup); writer.WriteInt(RebalanceBatchSize); writer.WriteLong((long)RebalanceDelay.TotalMilliseconds); writer.WriteInt((int)RebalanceMode); writer.WriteLong((long)RebalanceThrottle.TotalMilliseconds); writer.WriteLong((long)RebalanceTimeout.TotalMilliseconds); writer.WriteBoolean(SqlEscapeAll); writer.WriteInt(StartSize); writer.WriteInt(WriteBehindBatchSize); writer.WriteBoolean(WriteBehindEnabled); writer.WriteLong((long)WriteBehindFlushFrequency.TotalMilliseconds); writer.WriteInt(WriteBehindFlushSize); writer.WriteInt(WriteBehindFlushThreadCount); writer.WriteBoolean(WriteBehindCoalescing); writer.WriteInt((int)WriteSynchronizationMode); writer.WriteBoolean(ReadThrough); writer.WriteBoolean(WriteThrough); writer.WriteBoolean(EnableStatistics); writer.WriteString(MemoryPolicyName); writer.WriteInt((int)PartitionLossPolicy); writer.WriteObject(CacheStoreFactory); if (QueryEntities != null) { writer.WriteInt(QueryEntities.Count); foreach (var entity in QueryEntities) { if (entity == null) { throw new InvalidOperationException("Invalid cache configuration: QueryEntity can't be null."); } entity.Write(writer); } } else { writer.WriteInt(0); } if (NearConfiguration != null) { writer.WriteBoolean(true); NearConfiguration.Write(writer); } else { writer.WriteBoolean(false); } EvictionPolicyBase.Write(writer, EvictionPolicy); AffinityFunctionSerializer.Write(writer, AffinityFunction); ExpiryPolicySerializer.WritePolicyFactory(writer, ExpiryPolicyFactory); if (PluginConfigurations != null) { writer.WriteInt(PluginConfigurations.Count); foreach (var cachePlugin in PluginConfigurations) { if (cachePlugin == null) { throw new InvalidOperationException("Invalid cache configuration: " + "ICachePluginConfiguration can't be null."); } if (cachePlugin.CachePluginConfigurationClosureFactoryId != null) { writer.WriteBoolean(true); writer.WriteInt(cachePlugin.CachePluginConfigurationClosureFactoryId.Value); cachePlugin.WriteBinary(writer); } else { writer.WriteBoolean(false); writer.WriteObject(cachePlugin); } } } else { writer.WriteInt(0); } }