From e3b8725136f1fe6203cc821e4541c24471d8ab33 Mon Sep 17 00:00:00 2001 From: masesdevelopers <94312179+masesdevelopers@users.noreply.github.com> Date: Fri, 8 Mar 2024 04:33:22 +0100 Subject: [PATCH 1/6] Added JVM class on many other classes --- .../Kstream/SessionWindowedDeserializer.cs | 2 +- .../Kstream/TimeWindowedDeserializer.cs | 2 +- src/net/KNet/Specific/Connect/KNetTask.cs | 2 +- .../Specific/Streams/KNetClientSupplier.cs | 10 +- src/net/KNet/Specific/Streams/KNetStreams.cs | 6 +- src/net/KNet/Specific/Streams/KeyValue.cs | 76 ++++------- .../Specific/Streams/Kstream/Aggregator.cs | 17 ++- .../KNet/Specific/Streams/Kstream/Branched.cs | 2 + .../Streams/Kstream/CogroupedKStream.cs | 3 + .../KNet/Specific/Streams/Kstream/Consumed.cs | 104 +++++++++------ .../Specific/Streams/Kstream/ForeachAction.cs | 14 +- .../Specific/Streams/Kstream/GlobalKTable.cs | 2 + .../KNet/Specific/Streams/Kstream/Grouped.cs | 6 +- .../Specific/Streams/Kstream/Initializer.cs | 5 +- .../KNet/Specific/Streams/Kstream/Joined.cs | 13 +- .../Streams/Kstream/KBranchedKStream.cs | 2 + .../Streams/Kstream/KGroupedStream.cs | 6 + .../Specific/Streams/Kstream/KGroupedTable.cs | 6 + .../KNet/Specific/Streams/Kstream/KStream.cs | 86 ++++++++++++ .../KNet/Specific/Streams/Kstream/KTable.cs | 68 +++++++++- .../Streams/Kstream/KeyValueMapper.cs | 62 +++++---- .../Specific/Streams/Kstream/Materialized.cs | 8 +- .../KNet/Specific/Streams/Kstream/Merger.cs | 14 +- .../Specific/Streams/Kstream/Predicate.cs | 10 +- .../Streams/Kstream/PredicateEqualityTest.cs | 4 +- .../KNet/Specific/Streams/Kstream/Printed.cs | 4 +- .../KNet/Specific/Streams/Kstream/Produced.cs | 4 +- .../KNet/Specific/Streams/Kstream/Reducer.cs | 9 +- .../Specific/Streams/Kstream/Repartitioned.cs | 2 + .../SessionWindowedCogroupedKStream.cs | 2 + .../Streams/Kstream/SessionWindowedKStream.cs | 6 + .../Specific/Streams/Kstream/StreamJoined.cs | 3 + .../Specific/Streams/Kstream/Suppressed.cs | 3 +- .../Specific/Streams/Kstream/TableJoined.cs | 4 +- .../Kstream/TimeWindowedCogroupedKStream.cs | 2 + .../Streams/Kstream/TimeWindowedKStream.cs | 6 + .../Specific/Streams/Kstream/ValueJoiner.cs | 15 ++- .../Streams/Kstream/ValueJoinerWithKey.cs | 20 +-- .../Specific/Streams/Kstream/ValueMapper.cs | 20 +-- .../Streams/Kstream/ValueMapperWithKey.cs | 30 +++-- .../KNet/Specific/Streams/Kstream/Windowed.cs | 19 +-- .../Streams/Processor/Api/Processor.cs | 34 ++--- .../Streams/Processor/Api/ProcessorContext.cs | 26 ++-- .../Specific/Streams/Processor/Api/Record.cs | 62 +++++---- .../Streams/Processor/StreamPartitioner.cs | 10 +- .../Processor/StreamPartitionerNoValue.cs | 7 +- .../Streams/Processor/TimestampExtractor.cs | 28 ++-- .../Streams/Processor/TopicNameExtractor.cs | 8 +- .../Streams/State/KeyValueIterator.cs | 115 +++++++--------- .../Streams/State/ReadOnlyKeyValueStore.cs | 68 +++++----- .../Streams/State/ReadOnlySessionStore.cs | 126 +++++++++--------- .../Streams/State/ReadOnlyWindowStore.cs | 106 +++++++-------- .../State/TimestampedKeyValueIterator.cs | 96 ++++++------- .../Streams/State/TimestampedKeyValueStore.cs | 64 ++++----- .../Streams/State/TimestampedWindowStore.cs | 96 ++++++------- .../State/TimestampedWindowStoreIterator.cs | 13 +- .../TimestampedWindowedKeyValueIterator.cs | 48 +++---- .../Streams/State/ValueAndTimestamp.cs | 17 +-- .../Streams/State/WindowStoreIterator.cs | 15 ++- .../Streams/State/WindowedKeyValueIterator.cs | 62 ++++----- .../KNet/Specific/Streams/StreamsBuilder.cs | 28 ++-- .../Specific/Streams/TimestampedKeyValue.cs | 61 +++------ .../Streams/TimestampedWindowedKeyValue.cs | 26 ++-- src/net/KNet/Specific/Streams/Topology.cs | 60 ++++----- .../KNet/Specific/Streams/Utils/Function.cs | 8 +- .../Specific/Streams/Utils/KStreamConsumer.cs | 1 - .../KNet/Specific/Streams/WindowedKeyValue.cs | 30 +++-- 67 files changed, 1047 insertions(+), 847 deletions(-) diff --git a/src/net/KNet/Developed/Org/Apache/Kafka/Streams/Kstream/SessionWindowedDeserializer.cs b/src/net/KNet/Developed/Org/Apache/Kafka/Streams/Kstream/SessionWindowedDeserializer.cs index fc73dd1f41..5b8fc15881 100644 --- a/src/net/KNet/Developed/Org/Apache/Kafka/Streams/Kstream/SessionWindowedDeserializer.cs +++ b/src/net/KNet/Developed/Org/Apache/Kafka/Streams/Kstream/SessionWindowedDeserializer.cs @@ -24,7 +24,7 @@ namespace Org.Apache.Kafka.Streams.Kstream public partial class SessionWindowedDeserializer { /// - /// Override of to return + /// Override of to return /// public Windowed Deserialize2(string topic, byte[] data) { diff --git a/src/net/KNet/Developed/Org/Apache/Kafka/Streams/Kstream/TimeWindowedDeserializer.cs b/src/net/KNet/Developed/Org/Apache/Kafka/Streams/Kstream/TimeWindowedDeserializer.cs index 079d5abc41..f69d252df3 100644 --- a/src/net/KNet/Developed/Org/Apache/Kafka/Streams/Kstream/TimeWindowedDeserializer.cs +++ b/src/net/KNet/Developed/Org/Apache/Kafka/Streams/Kstream/TimeWindowedDeserializer.cs @@ -24,7 +24,7 @@ namespace Org.Apache.Kafka.Streams.Kstream public partial class TimeWindowedDeserializer { /// - /// Override of to return + /// Override of to return /// public Windowed Deserialize2(string topic, byte[] data) { diff --git a/src/net/KNet/Specific/Connect/KNetTask.cs b/src/net/KNet/Specific/Connect/KNetTask.cs index 8460e64e2e..74a5770758 100644 --- a/src/net/KNet/Specific/Connect/KNetTask.cs +++ b/src/net/KNet/Specific/Connect/KNetTask.cs @@ -156,7 +156,7 @@ protected T Context() /// public abstract string ReflectedTaskClassName { get; } /// - /// Public method used from Java to trigger + /// Public method used from Java to trigger /// public void StartInternal() { diff --git a/src/net/KNet/Specific/Streams/KNetClientSupplier.cs b/src/net/KNet/Specific/Streams/KNetClientSupplier.cs index 0aed074a6a..96d1244695 100644 --- a/src/net/KNet/Specific/Streams/KNetClientSupplier.cs +++ b/src/net/KNet/Specific/Streams/KNetClientSupplier.cs @@ -26,7 +26,7 @@ namespace MASES.KNet.Streams /// KNet implementation of /// /// The default used from allocates both and . - /// uses and , the instance shall be disposed when no more in use, but still be alive still is alive. + /// uses and , the instance shall be disposed when no more in use, but still be alive still is alive. public class KNetClientSupplier : Org.Apache.Kafka.Streams.KafkaClientSupplier { private readonly System.Collections.Generic.List _admins = new(); @@ -51,7 +51,7 @@ public override Org.Apache.Kafka.Clients.Consumer.Consumer GetCo Properties properties = new(); properties.PutAll(arg0); - var consumer = new KNetConsumer(properties); + var consumer = new KNetConsumer(properties); _consumers.Add(consumer); return consumer; } @@ -61,7 +61,7 @@ public override Org.Apache.Kafka.Clients.Consumer.Consumer GetGl Properties properties = new(); properties.PutAll(arg0); - var consumer = new KNetConsumer(properties); + var consumer = new KNetConsumer(properties); _consumers.Add(consumer); return consumer; } @@ -71,7 +71,7 @@ public override Org.Apache.Kafka.Clients.Producer.Producer GetPr Properties properties = new(); properties.PutAll(arg0); - var producer = new KNetProducer(properties); + var producer = new KNetProducer(properties); _producers.Add(producer); return producer; } @@ -81,7 +81,7 @@ public override Org.Apache.Kafka.Clients.Consumer.Consumer GetRe Properties properties = new(); properties.PutAll(arg0); - var consumer = new KNetConsumer(properties); + var consumer = new KNetConsumer(properties); _consumers.Add(consumer); return consumer; } diff --git a/src/net/KNet/Specific/Streams/KNetStreams.cs b/src/net/KNet/Specific/Streams/KNetStreams.cs index e38bb0a976..26f90b74e9 100644 --- a/src/net/KNet/Specific/Streams/KNetStreams.cs +++ b/src/net/KNet/Specific/Streams/KNetStreams.cs @@ -110,10 +110,10 @@ protected virtual Java.Util.Properties PrepareProperties(StreamsConfigBuilder bu /// /// /// - /// + /// /// /// - public Org.Apache.Kafka.Streams.KeyQueryMetadata QueryMetadataForKey(string arg0, TKey arg1, ISerializer arg2) + public Org.Apache.Kafka.Streams.KeyQueryMetadata QueryMetadataForKey(string arg0, TKey arg1, ISerializer arg2) { return _inner.QueryMetadataForKey(arg0, arg2.Serialize(null, arg1), arg2.KafkaSerializer); } @@ -128,7 +128,7 @@ public Org.Apache.Kafka.Streams.KeyQueryMetadata QueryMetadataForKey(strin public Org.Apache.Kafka.Streams.KeyQueryMetadata QueryMetadataForKey(string arg0, TKey arg1, StreamPartitioner arg2) { if (arg2 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; - var keySerDes = _factory?.BuildKeySerDes(); + var keySerDes = _factory?.BuildKeySerDes(); return _inner.IExecute("queryMetadataForKey", arg0, keySerDes.Serialize(null, arg1), arg2); } /// diff --git a/src/net/KNet/Specific/Streams/KeyValue.cs b/src/net/KNet/Specific/Streams/KeyValue.cs index 213f9285dd..40376d00f2 100644 --- a/src/net/KNet/Specific/Streams/KeyValue.cs +++ b/src/net/KNet/Specific/Streams/KeyValue.cs @@ -23,59 +23,39 @@ namespace MASES.KNet.Streams /// /// KNet implementation of /// - /// The key type - /// The value type - public sealed class KeyValue : IGenericSerDesFactoryApplier + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public sealed class KeyValue : IGenericSerDesFactoryApplier { - readonly Org.Apache.Kafka.Streams.KeyValue _valueInner1 = null; - readonly Org.Apache.Kafka.Streams.KeyValue _valueInner2 = null; - TKey _key; + readonly Org.Apache.Kafka.Streams.KeyValue _inner = null; + K _key; bool _keyStored; - TValue _value; + V _value; bool _valueStored; - ISerDes _keySerDes = null; - ISerDes _valueSerDes = null; + ISerDes _keySerDes = null; + ISerDes _valueSerDes = null; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } internal KeyValue(IGenericSerDesFactory factory, - Org.Apache.Kafka.Streams.KeyValue value, - ISerDes keySerDes, - ISerDes valueSerDes, + Org.Apache.Kafka.Streams.KeyValue value, + ISerDes keySerDes, + ISerDes valueSerDes, bool fromPrefetched) { _factory = factory; - _valueInner1 = value; + _inner = value; _keySerDes = keySerDes; _valueSerDes = valueSerDes; if (fromPrefetched) { - _keySerDes ??= _factory?.BuildKeySerDes(); - _key = _keySerDes.Deserialize(null, _valueInner1.key); + _keySerDes ??= _factory?.BuildKeySerDes(); + _key = _keySerDes.Deserialize(null, _inner.key); _keyStored = true; - _valueSerDes ??= _factory?.BuildValueSerDes(); - _value = _valueSerDes.Deserialize(null, _valueInner1.value); - _valueStored = true; - } - } - - internal KeyValue(IGenericSerDesFactory factory, - Org.Apache.Kafka.Streams.KeyValue value, - ISerDes keySerDes, - ISerDes valueSerDes, - bool fromPrefetched) - { - _factory = factory; - _valueInner2 = value; - _keySerDes = keySerDes; - _valueSerDes = valueSerDes; - if (fromPrefetched) - { - _keySerDes ??= _factory?.BuildKeySerDes(); - _key = (TKey)(object)_valueInner2.key.LongValue(); - _keyStored = true; - _valueSerDes ??= _factory?.BuildValueSerDes(); - _value = _valueSerDes.Deserialize(null, _valueInner1.value); + _valueSerDes ??= _factory?.BuildValueSerDes(); + _value = _valueSerDes.Deserialize(null, _inner.value); _valueStored = true; } } @@ -83,22 +63,14 @@ internal KeyValue(IGenericSerDesFactory factory, /// /// KNet implementation of /// - public TKey Key + public K Key { get { if (!_keyStored) { - if (_valueInner2 != null && _valueInner2.key != null) - { - var ll = _valueInner2.key; - _key = (TKey)(object)ll.LongValue(); - } - else - { - _keySerDes ??= _factory?.BuildKeySerDes(); - _key = _keySerDes.Deserialize(null, _valueInner1.key); - } + _keySerDes ??= _factory?.BuildKeySerDes(); + _key = _keySerDes.Deserialize(null, _inner.key); _keyStored = true; } return _key; @@ -107,14 +79,14 @@ public TKey Key /// /// KNet implementation of /// - public TValue Value + public V Value { get { if (!_valueStored) { - _valueSerDes ??= _factory?.BuildValueSerDes(); - _value = _valueSerDes.Deserialize(null, _valueInner1 != null ? _valueInner1.value : _valueInner2.value); + _valueSerDes ??= _factory?.BuildValueSerDes(); + _value = _valueSerDes.Deserialize(null, _inner.value); _valueStored = true; } return _value; diff --git a/src/net/KNet/Specific/Streams/Kstream/Aggregator.cs b/src/net/KNet/Specific/Streams/Kstream/Aggregator.cs index 97a874bad1..380259b6dc 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Aggregator.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Aggregator.cs @@ -27,6 +27,9 @@ namespace MASES.KNet.Streams.Kstream /// /// /// The key type + /// The JVM type of + /// The JVM type of + /// The JVM type of public abstract class Aggregator : Org.Apache.Kafka.Streams.Kstream.Aggregator, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -88,20 +91,20 @@ public class Aggregator : Aggregator bool _valueSet = false; VA _aggregate; bool _aggregateSet = false; - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; - ISerDes _vaSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; + ISerDes _vaSerializer = null; /// /// Handler for /// /// If has a value it takes precedence over corresponding class method public new System.Func, VA> OnApply { get; set; } = null; /// - public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } + public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } /// - public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } + public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } /// - public override VA Aggregate { get { if (!_aggregateSet) { _vaSerializer ??= Factory?.BuildValueSerDes(); _aggregate = _vaSerializer.Deserialize(null, _arg2); _aggregateSet = true; } return _aggregate; } } + public override VA Aggregate { get { if (!_aggregateSet) { _vaSerializer ??= Factory?.BuildValueSerDes(); _aggregate = _vaSerializer.Deserialize(null, _arg2); _aggregateSet = true; } return _aggregate; } } /// public sealed override byte[] Apply(byte[] arg0, byte[] arg1, byte[] arg2) { @@ -111,7 +114,7 @@ public sealed override byte[] Apply(byte[] arg0, byte[] arg1, byte[] arg2) _arg2 = arg2; VA res = (OnApply != null) ? OnApply(this) : Apply(); - _vaSerializer ??= Factory?.BuildValueSerDes(); + _vaSerializer ??= Factory?.BuildValueSerDes(); return _vaSerializer.Serialize(null, res); } } diff --git a/src/net/KNet/Specific/Streams/Kstream/Branched.cs b/src/net/KNet/Specific/Streams/Kstream/Branched.cs index 4f9dc75c57..3e427bf21c 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Branched.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Branched.cs @@ -26,6 +26,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class Branched : IGenericSerDesFactoryApplier { readonly Org.Apache.Kafka.Streams.Kstream.Branched _inner; diff --git a/src/net/KNet/Specific/Streams/Kstream/CogroupedKStream.cs b/src/net/KNet/Specific/Streams/Kstream/CogroupedKStream.cs index 8654effede..aa24a02a44 100644 --- a/src/net/KNet/Specific/Streams/Kstream/CogroupedKStream.cs +++ b/src/net/KNet/Specific/Streams/Kstream/CogroupedKStream.cs @@ -25,6 +25,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class CogroupedKStream : IGenericSerDesFactoryApplier { Org.Apache.Kafka.Streams.Kstream.CogroupedKStream _inner; @@ -50,6 +52,7 @@ internal CogroupedKStream(IGenericSerDesFactory factory, Org.Apache.Kafka.Stream /// /// /// + /// The JVM type of /// /// /// diff --git a/src/net/KNet/Specific/Streams/Kstream/Consumed.cs b/src/net/KNet/Specific/Streams/Kstream/Consumed.cs index 702b60f925..74a99f92df 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Consumed.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Consumed.cs @@ -16,6 +16,7 @@ * Refer to LICENSE for more information. */ +using Javax.Management; using MASES.KNet.Serialization; using MASES.KNet.Streams.Processor; @@ -26,10 +27,15 @@ namespace MASES.KNet.Streams.Kstream /// /// /// - public class Consumed : IGenericSerDesFactoryApplier + /// The JVM type of + /// The JVM type of + public class Consumed : IGenericSerDesFactoryApplier { - TimestampExtractor _timestampExtractor = null; - readonly Org.Apache.Kafka.Streams.Kstream.Consumed _inner; + ISerDes _keySerdes; + ISerDes _valueSerdes; + + TimestampExtractor _timestampExtractor = null; + readonly Org.Apache.Kafka.Streams.Kstream.Consumed _inner; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { @@ -41,71 +47,79 @@ IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory } } - Consumed(Org.Apache.Kafka.Streams.Kstream.Consumed inner, TimestampExtractor timestampExtractor = null) + Consumed(Org.Apache.Kafka.Streams.Kstream.Consumed inner) { _inner = inner; - _timestampExtractor = timestampExtractor; } /// - /// Converter from to + /// Converter from to /// - public static implicit operator Org.Apache.Kafka.Streams.Kstream.Consumed(Consumed t) => t._inner; + public static implicit operator Org.Apache.Kafka.Streams.Kstream.Consumed(Consumed t) => t._inner; #region Static methods /// /// /// /// - /// - public static Consumed As(string arg0) + /// + public static Consumed As(string arg0) { - var cons = Org.Apache.Kafka.Streams.Kstream.Consumed.As(arg0); - return new Consumed(cons); + var cons = Org.Apache.Kafka.Streams.Kstream.Consumed.As(arg0); + return new Consumed(cons); } /// /// /// - /// - /// - /// + /// + /// + /// /// - /// - public static Consumed With(ISerDes arg0, ISerDes arg1, TimestampExtractor arg2, Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg3) + /// + public static Consumed With(ISerDes arg0, ISerDes arg1, TimestampExtractor arg2, Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg3) { - var cons = Org.Apache.Kafka.Streams.Kstream.Consumed.With(arg0.KafkaSerde, arg1.KafkaSerde, arg2, arg3); - return new Consumed(cons, arg2); + var cons = Org.Apache.Kafka.Streams.Kstream.Consumed.With(arg0.KafkaSerde, arg1.KafkaSerde, arg2, arg3); + var instance = new Consumed(cons); + instance._keySerdes = arg0; + instance._valueSerdes = arg1; + instance._timestampExtractor = arg2; + return instance; } /// /// /// - /// - /// - /// - public static Consumed With(ISerDes arg0, ISerDes arg1) + /// + /// + /// + public static Consumed With(ISerDes arg0, ISerDes arg1) { - var cons = Org.Apache.Kafka.Streams.Kstream.Consumed.With(arg0.KafkaSerde, arg1.KafkaSerde); - return new Consumed(cons); + var cons = Org.Apache.Kafka.Streams.Kstream.Consumed.With(arg0.KafkaSerde, arg1.KafkaSerde); + var instance = new Consumed(cons); + instance._keySerdes = arg0; + instance._valueSerdes = arg1; + return instance; } /// /// /// - /// - /// - public static Consumed With(TimestampExtractor arg0) + /// + /// + public static Consumed With(TimestampExtractor arg0) { - var cons = Org.Apache.Kafka.Streams.Kstream.Consumed.With(arg0); - return new Consumed(cons, arg0); + var cons = Org.Apache.Kafka.Streams.Kstream.Consumed.With(arg0); + var instance = new Consumed(cons); + instance._timestampExtractor = arg0; + return instance; } /// /// /// /// - /// - public static Consumed With(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0) + /// + public static Consumed With(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0) { - var cons = Org.Apache.Kafka.Streams.Kstream.Consumed.With(arg0); - return new Consumed(cons); + var cons = Org.Apache.Kafka.Streams.Kstream.Consumed.With(arg0); + return new Consumed(cons); } #endregion @@ -114,19 +128,20 @@ public static Consumed With(Org.Apache.Kafka.Streams.Topology.AutoOffsetRe /// /// /// - /// - /// - public Consumed WithKeySerde(ISerDes arg0) + /// + /// + public Consumed WithKeySerde(ISerDes arg0) { _inner?.WithKeySerde(arg0.KafkaSerde); + _keySerdes = arg0; return this; } /// /// /// /// - /// - public Consumed WithOffsetResetPolicy(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0) + /// + public Consumed WithOffsetResetPolicy(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0) { _inner?.WithOffsetResetPolicy(arg0); return this; @@ -134,9 +149,9 @@ public Consumed WithOffsetResetPolicy(Org.Apache.Kafka.Streams.Topology.Au /// /// /// - /// - /// - public Consumed WithTimestampExtractor(TimestampExtractor arg0) + /// + /// + public Consumed WithTimestampExtractor(TimestampExtractor arg0) { if (arg0 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; _timestampExtractor = arg0; @@ -146,11 +161,12 @@ public Consumed WithTimestampExtractor(TimestampExtractor arg0) /// /// /// - /// - /// - public Consumed WithValueSerde(ISerDes arg0) + /// + /// + public Consumed WithValueSerde(ISerDes arg0) { _inner?.WithValueSerde(arg0.KafkaSerde); + _valueSerdes = arg0; return this; } diff --git a/src/net/KNet/Specific/Streams/Kstream/ForeachAction.cs b/src/net/KNet/Specific/Streams/Kstream/ForeachAction.cs index 044e0680dd..2582b5c276 100644 --- a/src/net/KNet/Specific/Streams/Kstream/ForeachAction.cs +++ b/src/net/KNet/Specific/Streams/Kstream/ForeachAction.cs @@ -26,6 +26,8 @@ namespace MASES.KNet.Streams.Kstream /// /// key value type /// first value type + /// The JVM type of + /// The JVM type of public abstract class ForeachAction : Org.Apache.Kafka.Streams.Kstream.ForeachAction, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -79,22 +81,22 @@ public class ForeachAction : ForeachAction bool _keySet = false; V _value; bool _valueSet = false; - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; /// /// Handler for /// /// If has a value it takes precedence over corresponding class method public new System.Action> OnApply { get; set; } = null; /// - public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } + public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } /// - public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } + public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } /// public sealed override void Apply(byte[] arg0, byte[] arg1) { - _kSerializer ??= Factory?.BuildKeySerDes(); - _vSerializer ??= Factory?.BuildValueSerDes(); + _kSerializer ??= Factory?.BuildKeySerDes(); + _vSerializer ??= Factory?.BuildValueSerDes(); _keySet = _valueSet = false; _arg0 = arg0; _arg1 = arg1; diff --git a/src/net/KNet/Specific/Streams/Kstream/GlobalKTable.cs b/src/net/KNet/Specific/Streams/Kstream/GlobalKTable.cs index c4a69c2ba6..53ffd0b8fa 100644 --- a/src/net/KNet/Specific/Streams/Kstream/GlobalKTable.cs +++ b/src/net/KNet/Specific/Streams/Kstream/GlobalKTable.cs @@ -25,6 +25,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class GlobalKTable : IGenericSerDesFactoryApplier { Org.Apache.Kafka.Streams.Kstream.GlobalKTable _inner; diff --git a/src/net/KNet/Specific/Streams/Kstream/Grouped.cs b/src/net/KNet/Specific/Streams/Kstream/Grouped.cs index 93a283a860..30fd3ae0ae 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Grouped.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Grouped.cs @@ -34,7 +34,7 @@ public class Grouped : IGenericSerDesFactoryApplier IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } - protected Grouped(Org.Apache.Kafka.Streams.Kstream.Grouped inner) + internal Grouped(Org.Apache.Kafka.Streams.Kstream.Grouped inner) { _inner = inner; } @@ -58,7 +58,7 @@ public static Grouped As(string arg0) /// /// /// - /// + /// /// public static Grouped KeySerde(ISerDes arg0) { @@ -68,7 +68,7 @@ public static Grouped KeySerde(ISerDes arg0) /// /// /// - /// + /// /// public static Grouped ValueSerde(ISerDes arg0) { diff --git a/src/net/KNet/Specific/Streams/Kstream/Initializer.cs b/src/net/KNet/Specific/Streams/Kstream/Initializer.cs index a6451e7900..ed93626e1e 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Initializer.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Initializer.cs @@ -25,6 +25,7 @@ namespace MASES.KNet.Streams.Kstream /// KNet implementation of /// /// The key type + /// The JVM type of public class Initializer : Org.Apache.Kafka.Streams.Kstream.Initializer, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -66,11 +67,11 @@ public virtual VA Apply2() /// The key type public class Initializer : Initializer { - ISerDes _valueSerializer = null; + ISerDes _valueSerializer = null; /// public sealed override byte[] Apply() { - _valueSerializer ??= Factory?.BuildValueSerDes(); + _valueSerializer ??= Factory?.BuildValueSerDes(); var methodToExecute = (OnApply2 != null) ? OnApply2 : Apply2; var res = methodToExecute(); diff --git a/src/net/KNet/Specific/Streams/Kstream/Joined.cs b/src/net/KNet/Specific/Streams/Kstream/Joined.cs index b480af3fc6..a4b5550ed0 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Joined.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Joined.cs @@ -27,13 +27,16 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of public class Joined : IGenericSerDesFactoryApplier { readonly Org.Apache.Kafka.Streams.Kstream.Joined _inner; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } - protected Joined(Org.Apache.Kafka.Streams.Kstream.Joined inner) + internal Joined(Org.Apache.Kafka.Streams.Kstream.Joined inner) { _inner = inner; } @@ -87,9 +90,9 @@ public static Joined ValueSerde(ISerDes /// /// - /// - /// - /// + /// + /// + /// /// /// /// @@ -145,7 +148,7 @@ public Joined WithGracePeriod(System.TimeSpan ar /// /// /// - /// + /// /// public Joined WithKeySerde(ISerDes arg0) { diff --git a/src/net/KNet/Specific/Streams/Kstream/KBranchedKStream.cs b/src/net/KNet/Specific/Streams/Kstream/KBranchedKStream.cs index bdcbeb919c..3e24aa009f 100644 --- a/src/net/KNet/Specific/Streams/Kstream/KBranchedKStream.cs +++ b/src/net/KNet/Specific/Streams/Kstream/KBranchedKStream.cs @@ -25,6 +25,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class BranchedKStream : IGenericSerDesFactoryApplier { Org.Apache.Kafka.Streams.Kstream.BranchedKStream _inner; diff --git a/src/net/KNet/Specific/Streams/Kstream/KGroupedStream.cs b/src/net/KNet/Specific/Streams/Kstream/KGroupedStream.cs index 46f16e5a85..9065e418d7 100644 --- a/src/net/KNet/Specific/Streams/Kstream/KGroupedStream.cs +++ b/src/net/KNet/Specific/Streams/Kstream/KGroupedStream.cs @@ -25,6 +25,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class KGroupedStream : IGenericSerDesFactoryApplier { Org.Apache.Kafka.Streams.Kstream.KGroupedStream _inner; @@ -49,6 +51,7 @@ internal KGroupedStream(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams. /// /// /// + /// The JVM type of /// /// /// @@ -64,6 +67,7 @@ public CogroupedKStream Cogroup /// /// + /// The JVM type of /// /// /// @@ -82,6 +86,7 @@ public KTable Aggregate /// /// + /// The JVM type of /// /// /// @@ -98,6 +103,7 @@ public KTable Aggregate /// /// + /// The JVM type of /// /// /// diff --git a/src/net/KNet/Specific/Streams/Kstream/KGroupedTable.cs b/src/net/KNet/Specific/Streams/Kstream/KGroupedTable.cs index 1be0449e63..d7120898d0 100644 --- a/src/net/KNet/Specific/Streams/Kstream/KGroupedTable.cs +++ b/src/net/KNet/Specific/Streams/Kstream/KGroupedTable.cs @@ -25,6 +25,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class KGroupedTable : IGenericSerDesFactoryApplier { Org.Apache.Kafka.Streams.Kstream.KGroupedTable _inner; @@ -51,6 +53,7 @@ internal KGroupedTable(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.K /// /// /// + /// The JVM type of /// /// /// @@ -73,6 +76,7 @@ public KTable Aggregate /// /// + /// The JVM type of /// /// /// @@ -94,6 +98,7 @@ public KTable Aggregate /// /// + /// The JVM type of /// /// /// @@ -113,6 +118,7 @@ public KTable Aggregate /// /// + /// The JVM type of /// /// /// diff --git a/src/net/KNet/Specific/Streams/Kstream/KStream.cs b/src/net/KNet/Specific/Streams/Kstream/KStream.cs index 05dcf290ce..c8c1687428 100644 --- a/src/net/KNet/Specific/Streams/Kstream/KStream.cs +++ b/src/net/KNet/Specific/Streams/Kstream/KStream.cs @@ -26,6 +26,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class KStream : IGenericSerDesFactoryApplier { Org.Apache.Kafka.Streams.Kstream.KStream _inner; @@ -54,6 +56,9 @@ internal KStream(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// /// /// @@ -76,6 +81,9 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// /// /// @@ -99,6 +107,9 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// /// /// @@ -122,6 +133,9 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// /// /// @@ -146,6 +160,9 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// /// /// @@ -168,6 +185,9 @@ public KStream LeftJoin /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// /// /// @@ -191,6 +211,9 @@ public KStream LeftJoin /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// /// /// @@ -214,6 +237,9 @@ public KStream LeftJoin /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// /// /// @@ -235,6 +261,8 @@ public KStream LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -251,6 +279,8 @@ public KStream FlatMap /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -268,6 +298,8 @@ public KStream FlatMap /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -284,6 +316,8 @@ public KStream Map /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -300,6 +334,7 @@ public KStream Map /// /// + /// The JVM type of /// /// /// @@ -314,6 +349,7 @@ public KGroupedStream GroupBy /// /// + /// The JVM type of /// /// /// @@ -328,6 +364,7 @@ public KGroupedStream GroupBy /// /// + /// The JVM type of /// /// /// @@ -342,6 +379,7 @@ public KStream SelectKey /// /// + /// The JVM type of /// /// /// @@ -360,6 +398,8 @@ public KStream SelectKey /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -378,6 +418,8 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -396,6 +438,8 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -415,6 +459,8 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -434,6 +480,8 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -452,6 +500,8 @@ public KStream LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -470,6 +520,8 @@ public KStream LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -489,6 +541,8 @@ public KStream LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -508,6 +562,8 @@ public KStream LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -526,6 +582,8 @@ public KStream OuterJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -544,6 +602,8 @@ public KStream OuterJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -563,6 +623,8 @@ public KStream OuterJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -579,6 +641,7 @@ public KStream OuterJoin /// /// + /// The JVM type of /// /// /// @@ -592,6 +655,7 @@ public KStream FlatMapValues /// /// + /// The JVM type of /// /// /// @@ -606,6 +670,7 @@ public KStream FlatMapValues /// /// + /// The JVM type of /// /// /// @@ -620,6 +685,7 @@ public KStream FlatMapValues /// /// + /// The JVM type of /// /// /// @@ -635,6 +701,7 @@ public KStream FlatMapValues /// /// + /// The JVM type of /// /// /// @@ -648,6 +715,7 @@ public KStream MapValues /// /// + /// The JVM type of /// /// /// @@ -662,6 +730,7 @@ public KStream MapValues /// /// + /// The JVM type of /// /// /// @@ -676,6 +745,7 @@ public KStream MapValues /// /// + /// The JVM type of /// /// /// @@ -693,6 +763,8 @@ public KStream MapValues /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -710,6 +782,8 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -727,6 +801,8 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -745,6 +821,8 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -763,6 +841,8 @@ public KStream Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -780,6 +860,8 @@ public KStream LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -797,6 +879,8 @@ public KStream LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -814,6 +898,8 @@ public KStream LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// diff --git a/src/net/KNet/Specific/Streams/Kstream/KTable.cs b/src/net/KNet/Specific/Streams/Kstream/KTable.cs index d038472f79..a20406ebf8 100644 --- a/src/net/KNet/Specific/Streams/Kstream/KTable.cs +++ b/src/net/KNet/Specific/Streams/Kstream/KTable.cs @@ -18,8 +18,6 @@ using MASES.KNet.Serialization; using MASES.KNet.Streams.Utils; -using System; -using System.Reflection; namespace MASES.KNet.Streams.Kstream { @@ -28,9 +26,11 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class KTable : IGenericSerDesFactoryApplier { - Org.Apache.Kafka.Streams.Kstream.KTable _inner; + readonly Org.Apache.Kafka.Streams.Kstream.KTable _inner; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } @@ -53,6 +53,8 @@ internal KTable(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.Kstream. /// /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -68,6 +70,8 @@ public KGroupedTable GroupBy /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -82,6 +86,7 @@ public KGroupedTable GroupBy /// /// + /// The JVM type of /// /// /// @@ -96,6 +101,7 @@ public KStream ToStream /// /// + /// The JVM type of /// /// /// @@ -113,6 +119,8 @@ public KStream ToStream /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -132,6 +140,8 @@ public KTable Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -150,6 +160,8 @@ public KTable Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -166,6 +178,8 @@ public KTable Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -183,6 +197,8 @@ public KTable Join /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -202,6 +218,8 @@ public KTable LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -220,6 +238,8 @@ public KTable LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -236,6 +256,8 @@ public KTable LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -253,6 +275,8 @@ public KTable LeftJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -272,6 +296,8 @@ public KTable OuterJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -290,6 +316,8 @@ public KTable OuterJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -306,6 +334,8 @@ public KTable OuterJoin /// /// + /// The JVM type of + /// The JVM type of /// /// /// @@ -325,6 +355,9 @@ public KTable OuterJoin /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// public KTable Join(KTable arg0, Function arg1, ValueJoiner arg2, Materialized arg3) { @@ -344,6 +377,9 @@ public KTable Join(KTa /// /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// public KTable Join(KTable arg0, Function arg1, ValueJoiner arg2, TableJoined arg3, Materialized arg4) { @@ -363,6 +399,9 @@ public KTable Join(KTa /// /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// public KTable Join(KTable arg0, Function arg1, ValueJoiner arg2, TableJoined arg3) { @@ -380,6 +419,9 @@ public KTable Join(KTa /// /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// public KTable Join(KTable arg0, Function arg1, ValueJoiner arg2) { @@ -397,6 +439,9 @@ public KTable Join(KTa /// /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// public KTable LeftJoin(KTable arg0, Function arg1, ValueJoiner arg2, Materialized arg3) { @@ -416,6 +461,9 @@ public KTable LeftJoin /// /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// public KTable LeftJoin(KTable arg0, Function arg1, ValueJoiner arg2, TableJoined arg3, Materialized arg4) { @@ -435,6 +483,9 @@ public KTable LeftJoin /// /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// public KTable LeftJoin(KTable arg0, Function arg1, ValueJoiner arg2, TableJoined arg3) { @@ -452,6 +503,9 @@ public KTable LeftJoin /// /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of /// public KTable LeftJoin(KTable arg0, Function arg1, ValueJoiner arg2) { @@ -465,6 +519,7 @@ public KTable LeftJoin /// /// /// + /// The JVM type of /// /// /// @@ -481,6 +536,7 @@ public KTable MapValues /// /// + /// The JVM type of /// /// /// @@ -496,6 +552,7 @@ public KTable MapValues /// /// + /// The JVM type of /// /// /// @@ -509,6 +566,7 @@ public KTable MapValues /// /// + /// The JVM type of /// /// /// @@ -523,6 +581,7 @@ public KTable MapValues /// /// + /// The JVM type of /// /// /// @@ -540,6 +599,7 @@ public KTable MapValues /// /// + /// The JVM type of /// /// /// @@ -556,6 +616,7 @@ public KTable MapValues /// /// + /// The JVM type of /// /// /// @@ -570,6 +631,7 @@ public KTable MapValues /// /// + /// The JVM type of /// /// /// diff --git a/src/net/KNet/Specific/Streams/Kstream/KeyValueMapper.cs b/src/net/KNet/Specific/Streams/Kstream/KeyValueMapper.cs index ffc7349506..4d712edad0 100644 --- a/src/net/KNet/Specific/Streams/Kstream/KeyValueMapper.cs +++ b/src/net/KNet/Specific/Streams/Kstream/KeyValueMapper.cs @@ -34,8 +34,6 @@ namespace MASES.KNet.Streams.Kstream /// The return JVM type to be managed public abstract class KeyValueMapper : Org.Apache.Kafka.Streams.Kstream.KeyValueMapper, IGenericSerDesFactoryApplier { - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; /// /// can be used from any class inherited from /// @@ -83,15 +81,15 @@ public virtual VR Apply(K arg0, V arg1) /// joined value type public class KeyValueMapper : KeyValueMapper { - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; - ISerDes _vrSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; + ISerDes _vrSerializer = null; /// public override byte[] Apply(byte[] arg0, byte[] arg1) { - _kSerializer ??= Factory?.BuildKeySerDes(); - _vSerializer ??= Factory?.BuildValueSerDes(); - _vrSerializer ??= Factory?.BuildValueSerDes(); + _kSerializer ??= Factory?.BuildKeySerDes(); + _vSerializer ??= Factory?.BuildValueSerDes(); + _vrSerializer ??= Factory?.BuildValueSerDes(); var methodToExecute = (OnApply != null) ? OnApply : Apply; var res = methodToExecute(_kSerializer.Deserialize(null, arg0), _vSerializer.Deserialize(null, arg1)); return _vrSerializer.Serialize(null, res); @@ -105,13 +103,13 @@ public override byte[] Apply(byte[] arg0, byte[] arg1) /// first value type public class KeyValueMapperForString : KeyValueMapper { - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; /// public override Java.Lang.String Apply(byte[] arg0, byte[] arg1) { - _kSerializer ??= Factory?.BuildKeySerDes(); - _vSerializer ??= Factory?.BuildValueSerDes(); + _kSerializer ??= Factory?.BuildKeySerDes(); + _vSerializer ??= Factory?.BuildValueSerDes(); var methodToExecute = (OnApply != null) ? OnApply : Apply; var res = methodToExecute(_kSerializer.Deserialize(null, arg0), _vSerializer.Deserialize(null, arg1)); return res; @@ -125,6 +123,10 @@ public override Java.Lang.String Apply(byte[] arg0, byte[] arg1) /// first value type /// first value type /// joined value type + /// The JVM type of + /// The JVM type of + /// The JVM type of + /// The JVM type of public abstract class KeyValueKeyValueMapper : KeyValueMapper> { /// @@ -153,10 +155,10 @@ public abstract class KeyValueKeyValueMapperjoined value type public class KeyValueKeyValueMapper : KeyValueKeyValueMapper { - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; - ISerDes _krSerializer = null; - ISerDes _vrSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; + ISerDes _krSerializer = null; + ISerDes _vrSerializer = null; /// /// Handler for /// @@ -165,10 +167,10 @@ public class KeyValueKeyValueMapper : KeyValueKeyValueMapper public sealed override Org.Apache.Kafka.Streams.KeyValue Apply(byte[] arg0, byte[] arg1) { - _kSerializer ??= Factory?.BuildKeySerDes(); - _vSerializer ??= Factory?.BuildValueSerDes(); - _krSerializer ??= Factory?.BuildValueSerDes(); - _vrSerializer ??= Factory?.BuildValueSerDes(); + _kSerializer ??= Factory?.BuildKeySerDes(); + _vSerializer ??= Factory?.BuildValueSerDes(); + _krSerializer ??= Factory?.BuildValueSerDes(); + _vrSerializer ??= Factory?.BuildValueSerDes(); var methodToExecute = (OnApply != null) ? OnApply : Apply; var res = methodToExecute(_kSerializer.Deserialize(null, arg0), _vSerializer.Deserialize(null, arg1)); @@ -193,6 +195,10 @@ public sealed override Org.Apache.Kafka.Streams.KeyValue Apply(b /// first value type /// first value type /// joined value type + /// The JVM type of + /// The JVM type of + /// The JVM type of + /// The JVM type of public abstract class EnumerableKeyValueMapper : KeyValueMapper>> { /// @@ -216,10 +222,10 @@ public abstract class EnumerableKeyValueMapperjoined value type public class EnumerableKeyValueMapper : EnumerableKeyValueMapper { - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; - ISerDes _krSerializer = null; - ISerDes _vrSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; + ISerDes _krSerializer = null; + ISerDes _vrSerializer = null; /// /// Handler for /// @@ -228,10 +234,10 @@ public class EnumerableKeyValueMapper : EnumerableKeyValueMapper public sealed override Java.Lang.Iterable> Apply(byte[] arg0, byte[] arg1) { - _kSerializer ??= Factory?.BuildKeySerDes(); - _vSerializer ??= Factory?.BuildValueSerDes(); - _krSerializer ??= Factory?.BuildValueSerDes(); - _vrSerializer ??= Factory?.BuildValueSerDes(); + _kSerializer ??= Factory?.BuildKeySerDes(); + _vSerializer ??= Factory?.BuildValueSerDes(); + _krSerializer ??= Factory?.BuildValueSerDes(); + _vrSerializer ??= Factory?.BuildValueSerDes(); var methodToExecute = (OnApply != null) ? OnApply : Apply; var res = methodToExecute(_kSerializer.Deserialize(null, arg0), _vSerializer.Deserialize(null, arg1)); diff --git a/src/net/KNet/Specific/Streams/Kstream/Materialized.cs b/src/net/KNet/Specific/Streams/Kstream/Materialized.cs index 43462fc354..0540e20777 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Materialized.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Materialized.cs @@ -32,7 +32,7 @@ public sealed class CountingMaterialized : Materialized /// /// - /// + /// /// public static CountingMaterialized With(ISerDes arg0) { @@ -48,7 +48,7 @@ public static CountingMaterialized With(ISerDes arg0) /// /// /// - /// + /// /// public CountingMaterialized WithValueSerde(ISerDes arg0) { @@ -86,7 +86,7 @@ public static Materialized With(ISerDes arg0, ISer /// /// /// - /// + /// /// public Materialized WithValueSerde(ISerDes arg0) { @@ -281,7 +281,7 @@ public TContainer WithCachingEnabled() /// /// /// - /// + /// /// public TContainer WithKeySerde(ISerDes arg0) { diff --git a/src/net/KNet/Specific/Streams/Kstream/Merger.cs b/src/net/KNet/Specific/Streams/Kstream/Merger.cs index ed046edb2e..9360620190 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Merger.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Merger.cs @@ -26,6 +26,8 @@ namespace MASES.KNet.Streams.Kstream /// /// key type /// value type + /// The JVM type of + /// The JVM type of public abstract class Merger : Org.Apache.Kafka.Streams.Kstream.Merger, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -89,19 +91,19 @@ public class Merger : Merger bool _value1Set; V _value2; bool _value2Set; - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; /// /// Handler for /// /// If has a value it takes precedence over corresponding class method public new System.Func, V> OnApply { get; set; } = null; /// - public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildValueSerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } + public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildValueSerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } /// - public override V Value1 { get { if (!_value1Set) { _vSerializer ??= Factory?.BuildValueSerDes(); _value1 = _vSerializer.Deserialize(null, _arg1); _value1Set = true; } return _value1; } } + public override V Value1 { get { if (!_value1Set) { _vSerializer ??= Factory?.BuildValueSerDes(); _value1 = _vSerializer.Deserialize(null, _arg1); _value1Set = true; } return _value1; } } /// - public override V Value2 { get { if (!_value2Set) { _vSerializer ??= Factory?.BuildValueSerDes(); _value2 = _vSerializer.Deserialize(null, _arg2); _value2Set = true; } return _value2; } } + public override V Value2 { get { if (!_value2Set) { _vSerializer ??= Factory?.BuildValueSerDes(); _value2 = _vSerializer.Deserialize(null, _arg2); _value2Set = true; } return _value2; } } /// public sealed override byte[] Apply(byte[] arg0, byte[] arg1, byte[] arg2) { @@ -111,7 +113,7 @@ public sealed override byte[] Apply(byte[] arg0, byte[] arg1, byte[] arg2) _arg2 = arg2; V res = (OnApply != null) ? OnApply(this) : Apply(); - _vSerializer ??= Factory?.BuildValueSerDes(); + _vSerializer ??= Factory?.BuildValueSerDes(); return _vSerializer.Serialize(null, res); } } diff --git a/src/net/KNet/Specific/Streams/Kstream/Predicate.cs b/src/net/KNet/Specific/Streams/Kstream/Predicate.cs index 74693272d6..1c9d58d742 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Predicate.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Predicate.cs @@ -26,6 +26,8 @@ namespace MASES.KNet.Streams.Kstream /// /// The key type /// The value type + /// The JVM type of + /// The JVM type of public abstract class Predicate : Org.Apache.Kafka.Streams.Kstream.Predicate, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -80,17 +82,17 @@ public class Predicate : Predicate bool _keySet; V _value; bool _valueSet; - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; /// /// Handler for /// /// If has a value it takes precedence over corresponding class method public new System.Func, bool> OnTest { get; set; } = null; /// - public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } + public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } /// - public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } + public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } /// public sealed override bool Test(byte[] arg0, byte[] arg1) { diff --git a/src/net/KNet/Specific/Streams/Kstream/PredicateEqualityTest.cs b/src/net/KNet/Specific/Streams/Kstream/PredicateEqualityTest.cs index 8744617b8c..5e85c1e037 100644 --- a/src/net/KNet/Specific/Streams/Kstream/PredicateEqualityTest.cs +++ b/src/net/KNet/Specific/Streams/Kstream/PredicateEqualityTest.cs @@ -41,8 +41,8 @@ public class PredicateEqualityTest : Predicate, IGen void updateRemote() { if (_factory == null) return; - var keySerDes = _factory?.BuildKeySerDes(); - var valueSerDes = _factory?.BuildValueSerDes(); + var keySerDes = _factory?.BuildKeySerDes(); + var valueSerDes = _factory?.BuildValueSerDes(); byte[] key = !_isKeyCheck.HasValue || _isKeyCheck.Value ? keySerDes.Serialize(null, _key): null; byte[] value = !_isKeyCheck.HasValue || !_isKeyCheck.Value ? valueSerDes.Serialize(null, _value) : null; diff --git a/src/net/KNet/Specific/Streams/Kstream/Printed.cs b/src/net/KNet/Specific/Streams/Kstream/Printed.cs index 01161dd043..28b88a9be5 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Printed.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Printed.cs @@ -25,13 +25,15 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class Printed : IGenericSerDesFactoryApplier { readonly Org.Apache.Kafka.Streams.Kstream.Printed _inner; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } - protected Printed(Org.Apache.Kafka.Streams.Kstream.Printed inner) + internal Printed(Org.Apache.Kafka.Streams.Kstream.Printed inner) { _inner = inner; } diff --git a/src/net/KNet/Specific/Streams/Kstream/Produced.cs b/src/net/KNet/Specific/Streams/Kstream/Produced.cs index dfc14589f9..ab6636464e 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Produced.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Produced.cs @@ -26,6 +26,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class Produced : IGenericSerDesFactoryApplier { StreamPartitioner _streamPartitioner = null; @@ -41,7 +43,7 @@ IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory } } - protected Produced(Org.Apache.Kafka.Streams.Kstream.Produced inner, StreamPartitioner streamPartitioner = null) + internal Produced(Org.Apache.Kafka.Streams.Kstream.Produced inner, StreamPartitioner streamPartitioner = null) { _inner = inner; _streamPartitioner = streamPartitioner; diff --git a/src/net/KNet/Specific/Streams/Kstream/Reducer.cs b/src/net/KNet/Specific/Streams/Kstream/Reducer.cs index b7b915b0e4..ab4fc8f075 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Reducer.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Reducer.cs @@ -25,6 +25,7 @@ namespace MASES.KNet.Streams.Kstream /// KNet extension of /// /// value type + /// The JVM type of public abstract class Reducer : Org.Apache.Kafka.Streams.Kstream.Reducer, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -82,16 +83,16 @@ public class Reducer : Reducer bool _value1Set; V _value2; bool _value2Set; - ISerDes _vSerializer = null; + ISerDes _vSerializer = null; /// /// Handler for /// /// If has a value it takes precedence over corresponding class method public new System.Func, V> OnApply { get; set; } = null; /// - public override V Value1 { get { if (!_value1Set) { _vSerializer ??= Factory?.BuildValueSerDes(); _value1 = _vSerializer.Deserialize(null, _arg0); _value1Set = true; } return _value1; } } + public override V Value1 { get { if (!_value1Set) { _vSerializer ??= Factory?.BuildValueSerDes(); _value1 = _vSerializer.Deserialize(null, _arg0); _value1Set = true; } return _value1; } } /// - public override V Value2 { get { if (!_value2Set) { _vSerializer ??= Factory?.BuildValueSerDes(); _value2 = _vSerializer.Deserialize(null, _arg1); _value2Set = true; } return _value2; } } + public override V Value2 { get { if (!_value2Set) { _vSerializer ??= Factory?.BuildValueSerDes(); _value2 = _vSerializer.Deserialize(null, _arg1); _value2Set = true; } return _value2; } } /// public sealed override byte[] Apply(byte[] arg0, byte[] arg1) { @@ -100,7 +101,7 @@ public sealed override byte[] Apply(byte[] arg0, byte[] arg1) _arg1 = arg1; V res = (OnApply != null) ? OnApply(this) : Apply(); - _vSerializer ??= Factory?.BuildValueSerDes(); + _vSerializer ??= Factory?.BuildValueSerDes(); return _vSerializer.Serialize(null, res); } } diff --git a/src/net/KNet/Specific/Streams/Kstream/Repartitioned.cs b/src/net/KNet/Specific/Streams/Kstream/Repartitioned.cs index 2b05321ad8..b3f3af2320 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Repartitioned.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Repartitioned.cs @@ -27,6 +27,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class Repartitioned : IGenericSerDesFactoryApplier { StreamPartitioner _streamPartitioner = null; diff --git a/src/net/KNet/Specific/Streams/Kstream/SessionWindowedCogroupedKStream.cs b/src/net/KNet/Specific/Streams/Kstream/SessionWindowedCogroupedKStream.cs index 6c65f62d84..0873adb801 100644 --- a/src/net/KNet/Specific/Streams/Kstream/SessionWindowedCogroupedKStream.cs +++ b/src/net/KNet/Specific/Streams/Kstream/SessionWindowedCogroupedKStream.cs @@ -25,6 +25,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class SessionWindowedCogroupedKStream : IGenericSerDesFactoryApplier { Org.Apache.Kafka.Streams.Kstream.SessionWindowedCogroupedKStream _inner; diff --git a/src/net/KNet/Specific/Streams/Kstream/SessionWindowedKStream.cs b/src/net/KNet/Specific/Streams/Kstream/SessionWindowedKStream.cs index 7c6f5a14a3..e91efc3845 100644 --- a/src/net/KNet/Specific/Streams/Kstream/SessionWindowedKStream.cs +++ b/src/net/KNet/Specific/Streams/Kstream/SessionWindowedKStream.cs @@ -25,6 +25,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class SessionWindowedKStream : IGenericSerDesFactoryApplier { Org.Apache.Kafka.Streams.Kstream.SessionWindowedKStream _inner; @@ -52,6 +54,7 @@ internal SessionWindowedKStream(IGenericSerDesFactory factory, Org.Apache.Kafka. /// /// /// + /// The JVM type of /// /// /// @@ -73,6 +76,7 @@ internal SessionWindowedKStream(IGenericSerDesFactory factory, Org.Apache.Kafka. /// /// /// + /// The JVM type of /// /// /// @@ -93,6 +97,7 @@ internal SessionWindowedKStream(IGenericSerDesFactory factory, Org.Apache.Kafka. /// /// /// + /// The JVM type of /// /// /// @@ -111,6 +116,7 @@ internal SessionWindowedKStream(IGenericSerDesFactory factory, Org.Apache.Kafka. /// /// /// + /// The JVM type of /// /// /// diff --git a/src/net/KNet/Specific/Streams/Kstream/StreamJoined.cs b/src/net/KNet/Specific/Streams/Kstream/StreamJoined.cs index ef9cf36409..22e8095382 100644 --- a/src/net/KNet/Specific/Streams/Kstream/StreamJoined.cs +++ b/src/net/KNet/Specific/Streams/Kstream/StreamJoined.cs @@ -26,6 +26,9 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of + /// The JVM type of public class StreamJoined : IGenericSerDesFactoryApplier { readonly Org.Apache.Kafka.Streams.Kstream.StreamJoined _inner; diff --git a/src/net/KNet/Specific/Streams/Kstream/Suppressed.cs b/src/net/KNet/Specific/Streams/Kstream/Suppressed.cs index e9727bdf95..18f5f7279a 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Suppressed.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Suppressed.cs @@ -25,13 +25,14 @@ namespace MASES.KNet.Streams.Kstream /// KNet extension of /// /// + /// The JVM type of public class Suppressed : IGenericSerDesFactoryApplier { readonly Org.Apache.Kafka.Streams.Kstream.Suppressed _inner; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } - protected Suppressed(Org.Apache.Kafka.Streams.Kstream.Suppressed inner) + internal Suppressed(Org.Apache.Kafka.Streams.Kstream.Suppressed inner) { _inner = inner; } diff --git a/src/net/KNet/Specific/Streams/Kstream/TableJoined.cs b/src/net/KNet/Specific/Streams/Kstream/TableJoined.cs index d8610d7cec..a04837d087 100644 --- a/src/net/KNet/Specific/Streams/Kstream/TableJoined.cs +++ b/src/net/KNet/Specific/Streams/Kstream/TableJoined.cs @@ -26,13 +26,15 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class TableJoined : IGenericSerDesFactoryApplier { readonly Org.Apache.Kafka.Streams.Kstream.TableJoined _inner; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } - protected TableJoined(Org.Apache.Kafka.Streams.Kstream.TableJoined inner) + internal TableJoined(Org.Apache.Kafka.Streams.Kstream.TableJoined inner) { _inner = inner; } diff --git a/src/net/KNet/Specific/Streams/Kstream/TimeWindowedCogroupedKStream.cs b/src/net/KNet/Specific/Streams/Kstream/TimeWindowedCogroupedKStream.cs index 718d7af30a..eec46f955d 100644 --- a/src/net/KNet/Specific/Streams/Kstream/TimeWindowedCogroupedKStream.cs +++ b/src/net/KNet/Specific/Streams/Kstream/TimeWindowedCogroupedKStream.cs @@ -25,6 +25,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class TimeWindowedCogroupedKStream : IGenericSerDesFactoryApplier { Org.Apache.Kafka.Streams.Kstream.TimeWindowedCogroupedKStream _inner; diff --git a/src/net/KNet/Specific/Streams/Kstream/TimeWindowedKStream.cs b/src/net/KNet/Specific/Streams/Kstream/TimeWindowedKStream.cs index cb180de965..f15ce76f70 100644 --- a/src/net/KNet/Specific/Streams/Kstream/TimeWindowedKStream.cs +++ b/src/net/KNet/Specific/Streams/Kstream/TimeWindowedKStream.cs @@ -25,6 +25,8 @@ namespace MASES.KNet.Streams.Kstream /// /// /// + /// The JVM type of + /// The JVM type of public class TimeWindowedKStream : IGenericSerDesFactoryApplier { Org.Apache.Kafka.Streams.Kstream.TimeWindowedKStream _inner; @@ -51,6 +53,7 @@ internal TimeWindowedKStream(IGenericSerDesFactory factory, Org.Apache.Kafka.Str /// /// /// + /// The JVM type of /// /// /// @@ -69,6 +72,7 @@ internal TimeWindowedKStream(IGenericSerDesFactory factory, Org.Apache.Kafka.Str /// /// /// + /// The JVM type of /// /// /// @@ -87,6 +91,7 @@ internal TimeWindowedKStream(IGenericSerDesFactory factory, Org.Apache.Kafka.Str /// /// /// + /// The JVM type of /// /// /// @@ -102,6 +107,7 @@ internal TimeWindowedKStream(IGenericSerDesFactory factory, Org.Apache.Kafka.Str /// /// /// + /// The JVM type of /// /// /// diff --git a/src/net/KNet/Specific/Streams/Kstream/ValueJoiner.cs b/src/net/KNet/Specific/Streams/Kstream/ValueJoiner.cs index b3528fff60..9711b0a025 100644 --- a/src/net/KNet/Specific/Streams/Kstream/ValueJoiner.cs +++ b/src/net/KNet/Specific/Streams/Kstream/ValueJoiner.cs @@ -27,6 +27,9 @@ namespace MASES.KNet.Streams.Kstream /// first value type /// second value type /// joined value type + /// The JVM type of + /// The JVM type of + /// The JVM type of public abstract class ValueJoiner : Org.Apache.Kafka.Streams.Kstream.ValueJoiner, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -82,9 +85,9 @@ public class ValueJoiner : ValueJoiner _v1Serializer = null; - ISerDes _v2Serializer = null; - ISerDes _vrSerializer = null; + ISerDes _v1Serializer = null; + ISerDes _v2Serializer = null; + ISerDes _vrSerializer = null; /// /// Handler for @@ -92,9 +95,9 @@ public class ValueJoiner : ValueJoinerIf has a value it takes precedence over corresponding class method public new System.Func, VR> OnApply { get; set; } = null; /// - public override V1 Value1 { get { if (!_value1Set) { _v1Serializer ??= Factory?.BuildValueSerDes(); _value1 = _v1Serializer.Deserialize(null, _arg0); _value1Set = true; } return _value1; } } + public override V1 Value1 { get { if (!_value1Set) { _v1Serializer ??= Factory?.BuildValueSerDes(); _value1 = _v1Serializer.Deserialize(null, _arg0); _value1Set = true; } return _value1; } } /// - public override V2 Value2 { get { if (!_value2Set) { _v2Serializer ??= Factory?.BuildValueSerDes(); _value2 = _v2Serializer.Deserialize(null, _arg1); _value2Set = true; } return _value2; } } + public override V2 Value2 { get { if (!_value2Set) { _v2Serializer ??= Factory?.BuildValueSerDes(); _value2 = _v2Serializer.Deserialize(null, _arg1); _value2Set = true; } return _value2; } } /// public sealed override byte[] Apply(byte[] arg0, byte[] arg1) { @@ -103,7 +106,7 @@ public sealed override byte[] Apply(byte[] arg0, byte[] arg1) _arg1 = arg1; VR res = (OnApply != null) ? OnApply(this) : Apply(); - _vrSerializer ??= Factory?.BuildValueSerDes(); + _vrSerializer ??= Factory?.BuildValueSerDes(); return _vrSerializer.Serialize(null, res); } } diff --git a/src/net/KNet/Specific/Streams/Kstream/ValueJoinerWithKey.cs b/src/net/KNet/Specific/Streams/Kstream/ValueJoinerWithKey.cs index ec6983286a..3400d23385 100644 --- a/src/net/KNet/Specific/Streams/Kstream/ValueJoinerWithKey.cs +++ b/src/net/KNet/Specific/Streams/Kstream/ValueJoinerWithKey.cs @@ -28,6 +28,10 @@ namespace MASES.KNet.Streams.Kstream /// first value type /// second value type /// joined value type + /// The JVM type of + /// The JVM type of + /// The JVM type of + /// The JVM type of public abstract class ValueJoinerWithKey : Org.Apache.Kafka.Streams.Kstream.ValueJoinerWithKey, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -91,21 +95,21 @@ public class ValueJoinerWithKey : ValueJoinerWithKey _k1Serializer = null; - ISerDes _v1Serializer = null; - ISerDes _v2Serializer = null; - ISerDes _vrSerializer = null; + ISerDes _k1Serializer = null; + ISerDes _v1Serializer = null; + ISerDes _v2Serializer = null; + ISerDes _vrSerializer = null; /// /// Handler for /// /// If has a value it takes precedence over corresponding class method public new System.Func, VR> OnApply { get; set; } = null; /// - public override K1 Key { get { if (!_key1Set) { _k1Serializer ??= Factory?.BuildKeySerDes(); _key1 = _k1Serializer.Deserialize(null, _arg0); _key1Set = true; } return _key1; } } + public override K1 Key { get { if (!_key1Set) { _k1Serializer ??= Factory?.BuildKeySerDes(); _key1 = _k1Serializer.Deserialize(null, _arg0); _key1Set = true; } return _key1; } } /// - public override V1 Value1 { get { if (!_value1Set) { _v1Serializer ??= Factory?.BuildValueSerDes(); _value1 = _v1Serializer.Deserialize(null, _arg1); _value1Set = true; } return _value1; } } + public override V1 Value1 { get { if (!_value1Set) { _v1Serializer ??= Factory?.BuildValueSerDes(); _value1 = _v1Serializer.Deserialize(null, _arg1); _value1Set = true; } return _value1; } } /// - public override V2 Value2 { get { if (!_value2Set) { _v2Serializer ??= Factory?.BuildValueSerDes(); _value2 = _v2Serializer.Deserialize(null, _arg2); _value2Set = true; } return _value2; } } + public override V2 Value2 { get { if (!_value2Set) { _v2Serializer ??= Factory?.BuildValueSerDes(); _value2 = _v2Serializer.Deserialize(null, _arg2); _value2Set = true; } return _value2; } } /// public sealed override byte[] Apply(byte[] arg0, byte[] arg1, byte[] arg2) { @@ -115,7 +119,7 @@ public sealed override byte[] Apply(byte[] arg0, byte[] arg1, byte[] arg2) _arg2 = arg2; VR res = (OnApply != null) ? OnApply(this) : Apply(); - _vrSerializer ??= Factory?.BuildValueSerDes(); + _vrSerializer ??= Factory?.BuildValueSerDes(); return _vrSerializer.Serialize(null, res); } } diff --git a/src/net/KNet/Specific/Streams/Kstream/ValueMapper.cs b/src/net/KNet/Specific/Streams/Kstream/ValueMapper.cs index bc1e267f36..a13030993c 100644 --- a/src/net/KNet/Specific/Streams/Kstream/ValueMapper.cs +++ b/src/net/KNet/Specific/Streams/Kstream/ValueMapper.cs @@ -28,6 +28,8 @@ namespace MASES.KNet.Streams.Kstream /// /// first value type /// joined value type + /// The JVM type of + /// The JVM type of public class ValueMapper : Org.Apache.Kafka.Streams.Kstream.ValueMapper, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -71,8 +73,8 @@ public virtual VR Apply(V arg0) /// joined value type public class ValueMapper : ValueMapper { - ISerDes _vSerializer = null; - ISerDes _vrSerializer = null; + ISerDes _vSerializer = null; + ISerDes _vrSerializer = null; /// /// Handler for /// @@ -82,8 +84,8 @@ public class ValueMapper : ValueMapper /// public sealed override byte[] Apply(byte[] arg0) { - _vSerializer ??= Factory?.BuildValueSerDes(); - _vrSerializer ??= Factory?.BuildValueSerDes(); + _vSerializer ??= Factory?.BuildValueSerDes(); + _vrSerializer ??= Factory?.BuildValueSerDes(); var methodToExecute = (OnApply != null) ? OnApply : Apply; var res = methodToExecute(_vSerializer.Deserialize(null, arg0)); @@ -96,6 +98,8 @@ public sealed override byte[] Apply(byte[] arg0) /// /// first value type /// joined value type + /// The JVM type of + /// The JVM type of public abstract class EnumerableValueMapper : ValueMapper> { /// @@ -122,8 +126,8 @@ public abstract class EnumerableValueMapper : ValueMapper< /// joined value type public class EnumerableValueMapper : EnumerableValueMapper { - ISerDes _vSerializer = null; - ISerDes _vrSerializer = null; + ISerDes _vSerializer = null; + ISerDes _vrSerializer = null; /// /// Handler for @@ -133,8 +137,8 @@ public class EnumerableValueMapper : EnumerableValueMapper public sealed override Java.Lang.Iterable Apply(byte[] arg0) { - _vSerializer ??= Factory?.BuildValueSerDes(); - _vrSerializer ??= Factory?.BuildValueSerDes(); + _vSerializer ??= Factory?.BuildValueSerDes(); + _vrSerializer ??= Factory?.BuildValueSerDes(); var methodToExecute = (OnApply != null) ? OnApply : Apply; var res = methodToExecute(_vSerializer.Deserialize(null, arg0)); diff --git a/src/net/KNet/Specific/Streams/Kstream/ValueMapperWithKey.cs b/src/net/KNet/Specific/Streams/Kstream/ValueMapperWithKey.cs index 8e35dcee3d..9535eb0635 100644 --- a/src/net/KNet/Specific/Streams/Kstream/ValueMapperWithKey.cs +++ b/src/net/KNet/Specific/Streams/Kstream/ValueMapperWithKey.cs @@ -30,6 +30,9 @@ namespace MASES.KNet.Streams.Kstream /// key value type /// first value type /// joined value type + /// The JVM type of + /// The JVM type of + /// The JVM type of public abstract class ValueMapperWithKey : Org.Apache.Kafka.Streams.Kstream.ValueMapperWithKey, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -85,9 +88,9 @@ public class ValueMapperWithKey : ValueMapperWithKey _kSerializer = null; - ISerDes _vSerializer = null; - ISerDes _vrSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; + ISerDes _vrSerializer = null; /// /// Handler for @@ -95,9 +98,9 @@ public class ValueMapperWithKey : ValueMapperWithKeyIf has a value it takes precedence over corresponding class method public new System.Func, VR> OnApply { get; set; } = null; /// - public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } + public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } /// - public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } + public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } /// public sealed override byte[] Apply(byte[] arg0, byte[] arg1) { @@ -106,7 +109,7 @@ public sealed override byte[] Apply(byte[] arg0, byte[] arg1) _arg1 = arg1; VR res = (OnApply != null) ? OnApply(this) : Apply(); - _vrSerializer ??= Factory?.BuildValueSerDes(); + _vrSerializer ??= Factory?.BuildValueSerDes(); return _vrSerializer.Serialize(null, res); } } @@ -117,6 +120,9 @@ public sealed override byte[] Apply(byte[] arg0, byte[] arg1) /// key value type /// first value type /// joined value type + /// The JVM type of + /// The JVM type of + /// The JVM type of public abstract class EnumerableValueMapperWithKey : ValueMapperWithKey> { /// @@ -148,9 +154,9 @@ public class EnumerableValueMapperWithKey : EnumerableValueMapperWithK bool _keySet = false; V _value; bool _valueSet = false; - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; - ISerDes _vrSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; + ISerDes _vrSerializer = null; /// /// Handler for @@ -158,9 +164,9 @@ public class EnumerableValueMapperWithKey : EnumerableValueMapperWithK /// If has a value it takes precedence over corresponding class method public new System.Func, IEnumerable> OnApply { get; set; } = null; /// - public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } + public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } /// - public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } + public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } /// public sealed override Java.Lang.Iterable Apply(byte[] arg0, byte[] arg1) { @@ -169,7 +175,7 @@ public sealed override Java.Lang.Iterable Apply(byte[] arg0, byte[] arg1 _arg1 = arg1; IEnumerable res = (OnApply != null) ? OnApply(this) : Apply(); - _vrSerializer ??= Factory?.BuildValueSerDes(); + _vrSerializer ??= Factory?.BuildValueSerDes(); var result = new ArrayList(); foreach (var item in res) { diff --git a/src/net/KNet/Specific/Streams/Kstream/Windowed.cs b/src/net/KNet/Specific/Streams/Kstream/Windowed.cs index b396a9360a..3357f9d155 100644 --- a/src/net/KNet/Specific/Streams/Kstream/Windowed.cs +++ b/src/net/KNet/Specific/Streams/Kstream/Windowed.cs @@ -23,30 +23,31 @@ namespace MASES.KNet.Streams.Kstream /// /// KNet implementation of /// - /// The key type - public class Windowed : IGenericSerDesFactoryApplier + /// The key type + /// The JVM type of + public class Windowed : IGenericSerDesFactoryApplier { - readonly Org.Apache.Kafka.Streams.Kstream.Windowed _inner; - ISerDes _keySerDes = null; + readonly Org.Apache.Kafka.Streams.Kstream.Windowed _inner; + ISerDes _keySerDes = null; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } - internal Windowed(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.Kstream.Windowed windowed) + internal Windowed(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.Kstream.Windowed windowed) { _factory = factory; _inner = windowed; } /// - /// Converter from to + /// Converter from to /// - public static implicit operator Org.Apache.Kafka.Streams.Kstream.Windowed(Windowed t) => t._inner; + public static implicit operator Org.Apache.Kafka.Streams.Kstream.Windowed(Windowed t) => t._inner; /// /// KNet implementation of /// - /// - public TKey Key { get { _keySerDes ??= _factory?.BuildKeySerDes(); return _keySerDes.Deserialize(null, _inner.Key()); } } + /// + public K Key { get { _keySerDes ??= _factory?.BuildKeySerDes(); return _keySerDes.Deserialize(null, _inner.Key()); } } /// /// KNet implementation of /// diff --git a/src/net/KNet/Specific/Streams/Processor/Api/Processor.cs b/src/net/KNet/Specific/Streams/Processor/Api/Processor.cs index 8766d45a00..02fcd0ad21 100644 --- a/src/net/KNet/Specific/Streams/Processor/Api/Processor.cs +++ b/src/net/KNet/Specific/Streams/Processor/Api/Processor.cs @@ -28,6 +28,10 @@ namespace MASES.KNet.Streams.Processor.Api /// The input key type /// The output key type /// The output value type + /// The JVM type of + /// The JVM type of + /// The JVM type of + /// The JVM type of public abstract class Processor : Org.Apache.Kafka.Streams.Processor.Api.Processor, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -48,21 +52,21 @@ protected IGenericSerDesFactory Factory } } /// - /// received from the init + /// received from the init /// - public abstract ProcessorContext Context { get; } + public abstract ProcessorContext Context { get; } /// /// Handler for /// /// If has a value it takes precedence over corresponding class method - public new System.Action> OnProcess { get; set; } = null; + public new System.Action> OnProcess { get; set; } = null; /// /// KNet implementation of /// - /// - public virtual void Process(Record arg0) + /// + public virtual void Process(Record arg0) { } @@ -71,13 +75,13 @@ public virtual void Process(Record arg0) /// Handler for /// /// If has a value it takes precedence over corresponding class method - public new System.Action> OnInit { get; set; } = null; + public new System.Action> OnInit { get; set; } = null; /// - /// KNet implementation of + /// KNet implementation of /// - /// - public virtual void Init(ProcessorContext arg0) + /// + public virtual void Init(ProcessorContext arg0) { } @@ -92,32 +96,32 @@ public virtual void Init(ProcessorContext arg0) /// The output value type public class Processor : Processor { - ProcessorContext _processorContext = null; + ProcessorContext _processorContext = null; /// - public override ProcessorContext Context => _processorContext; + public override ProcessorContext Context => _processorContext; /// /// Handler for /// /// If has a value it takes precedence over corresponding class method - public new System.Action> OnProcess { get; set; } = null; + public new System.Action> OnProcess { get; set; } = null; /// public sealed override void Process(Org.Apache.Kafka.Streams.Processor.Api.Record arg0) { var methodToExecute = OnProcess ?? Process; - methodToExecute(new Record(Factory, arg0, Context.RecordMetadata)); + methodToExecute(new Record(Factory, arg0, Context.RecordMetadata)); } /// /// Handler for /// /// If has a value it takes precedence over corresponding class method - public new System.Action> OnInit { get; set; } = null; + public new System.Action> OnInit { get; set; } = null; /// public sealed override void Init(Org.Apache.Kafka.Streams.Processor.Api.ProcessorContext arg0) { - _processorContext = new ProcessorContext(arg0); + _processorContext = new ProcessorContext(arg0); var methodToExecute = OnInit ?? Init; methodToExecute(_processorContext); diff --git a/src/net/KNet/Specific/Streams/Processor/Api/ProcessorContext.cs b/src/net/KNet/Specific/Streams/Processor/Api/ProcessorContext.cs index 91a3cf6040..f7f6031d98 100644 --- a/src/net/KNet/Specific/Streams/Processor/Api/ProcessorContext.cs +++ b/src/net/KNet/Specific/Streams/Processor/Api/ProcessorContext.cs @@ -21,23 +21,25 @@ namespace MASES.KNet.Streams.Processor.Api { /// - /// KNet implementation of + /// KNet implementation of /// /// /// - public class ProcessorContext + /// The JVM type of + /// The JVM type of + public class ProcessorContext { - internal ProcessorContext(Org.Apache.Kafka.Streams.Processor.Api.ProcessorContext context) + internal ProcessorContext(Org.Apache.Kafka.Streams.Processor.Api.ProcessorContext context) { _context = context; } - readonly Org.Apache.Kafka.Streams.Processor.Api.ProcessorContext _context; + readonly Org.Apache.Kafka.Streams.Processor.Api.ProcessorContext _context; /// - /// Converter from to + /// Converter from to /// - public static implicit operator Org.Apache.Kafka.Streams.Processor.Api.ProcessorContext(ProcessorContext t) => t._context; + public static implicit operator Org.Apache.Kafka.Streams.Processor.Api.ProcessorContext(ProcessorContext t) => t._context; #region ProcessorContext @@ -48,9 +50,11 @@ internal ProcessorContext(Org.Apache.Kafka.Streams.Processor.Api.ProcessorContex /// /// /// - public void Forward(Record arg0, string arg1) where K : KForward where V : VForward + /// The JVM type of + /// The JVM type of + public void Forward(Record arg0, string arg1) where K : KForward where V : VForward where TJVMK : TJVMKForward where TJVMV : TJVMVForward { - _context.Forward(arg0, arg1); + _context.Forward(arg0, arg1); } /// /// @@ -58,9 +62,11 @@ public void Forward(Record arg0, string arg1) where K : KForward whe /// /// /// - public void Forward(Record arg0) where K : KForward where V : VForward + /// The JVM type of + /// The JVM type of + public void Forward(Record arg0) where K : KForward where V : VForward where TJVMK : TJVMKForward where TJVMV : TJVMVForward { - _context.Forward(arg0); + _context.Forward(arg0); } #endregion diff --git a/src/net/KNet/Specific/Streams/Processor/Api/Record.cs b/src/net/KNet/Specific/Streams/Processor/Api/Record.cs index da44c30c47..ced8385be1 100644 --- a/src/net/KNet/Specific/Streams/Processor/Api/Record.cs +++ b/src/net/KNet/Specific/Streams/Processor/Api/Record.cs @@ -24,11 +24,13 @@ namespace MASES.KNet.Streams.Processor.Api /// /// KNet extension of /// - /// The key type - /// The value type - public class Record + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public class Record { - internal Record(IGenericSerDesFactory builder, Org.Apache.Kafka.Streams.Processor.Api.Record record, Org.Apache.Kafka.Streams.Processor.Api.RecordMetadata metadata) + internal Record(IGenericSerDesFactory builder, Org.Apache.Kafka.Streams.Processor.Api.Record record, Org.Apache.Kafka.Streams.Processor.Api.RecordMetadata metadata) { _builder = builder; _record = record; @@ -36,59 +38,61 @@ internal Record(IGenericSerDesFactory builder, Org.Apache.Kafka.Streams.Processo } readonly IGenericSerDesFactory _builder; - readonly Org.Apache.Kafka.Streams.Processor.Api.Record _record; + readonly Org.Apache.Kafka.Streams.Processor.Api.Record _record; readonly Org.Apache.Kafka.Streams.Processor.Api.RecordMetadata _metadata; /// - /// Converter from to + /// Converter from to /// - public static implicit operator Org.Apache.Kafka.Streams.Processor.Api.Record(Record t) => t._record; + public static implicit operator Org.Apache.Kafka.Streams.Processor.Api.Record(Record t) => t._record; /// /// /// /// /// - /// - public Record WithKey(NewK arg0) + /// The JVM type of + /// + public Record WithKey(NewK arg0) { - var serDes = _builder.BuildKeySerDes(); + var serDes = _builder.BuildKeySerDes(); var record = _record.WithKey(serDes.SerializeWithHeaders(_metadata?.Topic(), _record.Headers(), arg0)); - return new Record(_builder, record, _metadata); + return new Record(_builder, record, _metadata); } /// /// /// /// /// - /// - public Record WithValue(NewV arg0) + /// The JVM type of + /// + public Record WithValue(NewV arg0) { - var serDes = _builder.BuildValueSerDes(); + var serDes = _builder.BuildValueSerDes(); var record = _record.WithValue(serDes.SerializeWithHeaders(_metadata?.Topic(), _record.Headers(), arg0)); - return new Record(_builder, record, _metadata); + return new Record(_builder, record, _metadata); } /// /// /// - /// - public TKey Key + /// + public K Key { get { - var serDes = _builder.BuildKeySerDes(); + var serDes = _builder.BuildKeySerDes(); return serDes.DeserializeWithHeaders(_metadata?.Topic(), _record.Headers(), _record.Key()); } } /// /// /// - /// - public TValue Value + /// + public V Value { get { - var serDes = _builder.BuildValueSerDes(); + var serDes = _builder.BuildValueSerDes(); return serDes.DeserializeWithHeaders(_metadata?.Topic(), _record.Headers(), _record.Value()); } } @@ -109,28 +113,28 @@ public TValue Value /// /// /// - /// - public Record WithHeaders(Org.Apache.Kafka.Common.Header.Headers arg0) + /// + public Record WithHeaders(Org.Apache.Kafka.Common.Header.Headers arg0) { var record = _record.WithHeaders(arg0); - return new Record(_builder, record, _metadata); + return new Record(_builder, record, _metadata); } /// /// /// /// - /// - public Record WithTimestamp(long arg0) + /// + public Record WithTimestamp(long arg0) { var record = _record.WithTimestamp(arg0); - return new Record(_builder, record, _metadata); + return new Record(_builder, record, _metadata); } /// /// /// /// - /// - public Record WithDateTime(DateTime arg0) + /// + public Record WithDateTime(DateTime arg0) { return WithTimestamp(new DateTimeOffset(arg0).ToUnixTimeMilliseconds()); } diff --git a/src/net/KNet/Specific/Streams/Processor/StreamPartitioner.cs b/src/net/KNet/Specific/Streams/Processor/StreamPartitioner.cs index c07a322d0c..b0e654e694 100644 --- a/src/net/KNet/Specific/Streams/Processor/StreamPartitioner.cs +++ b/src/net/KNet/Specific/Streams/Processor/StreamPartitioner.cs @@ -28,6 +28,8 @@ namespace MASES.KNet.Streams.Processor /// /// The key type /// The value type + /// The JVM type of + /// The JVM type of public abstract class StreamPartitioner : Org.Apache.Kafka.Streams.Processor.StreamPartitioner, IGenericSerDesFactoryApplier { IGenericSerDesFactory _factory; @@ -92,8 +94,8 @@ public class StreamPartitioner : StreamPartitioner bool _keySet = false; V _value; bool _valueSet = false; - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; /// /// Handler for /// @@ -102,9 +104,9 @@ public class StreamPartitioner : StreamPartitioner /// public override string Topic => _arg0; /// - public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg1); _keySet = true; } return _key; } } + public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg1); _keySet = true; } return _key; } } /// - public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg2); _valueSet = true; } return _value; } } + public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg2); _valueSet = true; } return _value; } } /// public override int NumPartitions => _arg3; /// diff --git a/src/net/KNet/Specific/Streams/Processor/StreamPartitionerNoValue.cs b/src/net/KNet/Specific/Streams/Processor/StreamPartitionerNoValue.cs index f1871f17b0..270f7e192d 100644 --- a/src/net/KNet/Specific/Streams/Processor/StreamPartitionerNoValue.cs +++ b/src/net/KNet/Specific/Streams/Processor/StreamPartitionerNoValue.cs @@ -27,6 +27,7 @@ namespace MASES.KNet.Streams.Processor /// KNet implementation of /// /// The key type + /// The JVM type of public abstract class StreamPartitionerNoValue : StreamPartitioner { /// @@ -59,12 +60,12 @@ public class StreamPartitionerNoValue : StreamPartitionerNoValue int _arg3; K _key; bool _keySet = false; - ISerDes _kSerializer = null; + ISerDes _kSerializer = null; /// public override string Topic => _arg0; /// - public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg1); _keySet = true; } return _key; } } + public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg1); _keySet = true; } return _key; } } /// public override string Value { get { throw new InvalidOperationException("Value type is Java.Lang.Void"); } } /// @@ -73,7 +74,7 @@ public class StreamPartitionerNoValue : StreamPartitionerNoValue /// public sealed override Optional> Partitions(Java.Lang.String arg0, byte[] arg1, Java.Lang.Void arg2, int arg3) { - _kSerializer ??= Factory?.BuildKeySerDes(); + _kSerializer ??= Factory?.BuildKeySerDes(); _keySet = false; _arg0 = arg0; _arg1 = arg1; diff --git a/src/net/KNet/Specific/Streams/Processor/TimestampExtractor.cs b/src/net/KNet/Specific/Streams/Processor/TimestampExtractor.cs index 1380f30c83..f5a9eab220 100644 --- a/src/net/KNet/Specific/Streams/Processor/TimestampExtractor.cs +++ b/src/net/KNet/Specific/Streams/Processor/TimestampExtractor.cs @@ -26,25 +26,27 @@ namespace MASES.KNet.Streams.Processor /// /// KNet extension of /// - /// The key type - /// The value type - public class TimestampExtractor : Org.Apache.Kafka.Streams.Processor.TimestampExtractor, IGenericSerDesFactoryApplier + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public class TimestampExtractor : Org.Apache.Kafka.Streams.Processor.TimestampExtractor, IGenericSerDesFactoryApplier { - ConsumerRecord _record; + ConsumerRecord _record; DateTime? _partitionTime; - ISerDes _keySerializer = null; - ISerDes _valueSerializer = null; + ISerDes _keySerializer = null; + ISerDes _valueSerializer = null; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } /// /// Handler for /// /// If has a value it takes precedence over corresponding class method - public new System.Func, DateTime> OnExtract { get; set; } = null; + public new System.Func, DateTime> OnExtract { get; set; } = null; /// - /// The to be used + /// The to be used /// - public ConsumerRecord Record => _record; + public ConsumerRecord Record => _record; /// /// The highest extracted valid of the current record's partition˙ (could be if unknown) /// @@ -52,11 +54,11 @@ public class TimestampExtractor : Org.Apache.Kafka.Streams.Process /// public sealed override long Extract(Org.Apache.Kafka.Clients.Consumer.ConsumerRecord arg0, long arg1) { - _keySerializer ??= _factory?.BuildKeySerDes(); - _valueSerializer ??= _factory?.BuildValueSerDes(); - var record = arg0.Cast>(); // KNet consider the data within Apache Kafka Streams defined always as byte[] + _keySerializer ??= _factory?.BuildKeySerDes(); + _valueSerializer ??= _factory?.BuildValueSerDes(); + var record = arg0.Cast>(); // KNet consider the data within Apache Kafka Streams defined always as byte[] - _record = new ConsumerRecord(record, _factory); + _record = new ConsumerRecord(record, _factory); _partitionTime = (arg1 == -1) ? null : DateTimeOffset.FromUnixTimeMilliseconds(arg1).DateTime; var res = (OnExtract != null) ? OnExtract(this) : Extract(); return new DateTimeOffset(res).ToUnixTimeMilliseconds(); diff --git a/src/net/KNet/Specific/Streams/Processor/TopicNameExtractor.cs b/src/net/KNet/Specific/Streams/Processor/TopicNameExtractor.cs index e38d1826c6..991f3f513f 100644 --- a/src/net/KNet/Specific/Streams/Processor/TopicNameExtractor.cs +++ b/src/net/KNet/Specific/Streams/Processor/TopicNameExtractor.cs @@ -87,17 +87,17 @@ public class TopicNameExtractor : TopicNameExtractor V _value; bool _valueSet = false; Org.Apache.Kafka.Streams.Processor.RecordContext _context; - ISerDes _kSerializer = null; - ISerDes _vSerializer = null; + ISerDes _kSerializer = null; + ISerDes _vSerializer = null; /// /// Handler for /// /// If has a value it takes precedence over corresponding class method public new System.Func, string> OnExtract { get; set; } = null; /// - public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } + public override K Key { get { if (!_keySet) { _kSerializer ??= Factory?.BuildKeySerDes(); _key = _kSerializer.Deserialize(null, _arg0); _keySet = true; } return _key; } } /// - public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } + public override V Value { get { if (!_valueSet) { _vSerializer ??= Factory?.BuildValueSerDes(); _value = _vSerializer.Deserialize(null, _arg1); _valueSet = true; } return _value; } } /// public override Org.Apache.Kafka.Streams.Processor.RecordContext RecordContext => _context; /// diff --git a/src/net/KNet/Specific/Streams/State/KeyValueIterator.cs b/src/net/KNet/Specific/Streams/State/KeyValueIterator.cs index dd639bbf4b..9a7cde8111 100644 --- a/src/net/KNet/Specific/Streams/State/KeyValueIterator.cs +++ b/src/net/KNet/Specific/Streams/State/KeyValueIterator.cs @@ -27,24 +27,24 @@ namespace MASES.KNet.Streams.State { /// - /// KNet implementation of + /// KNet implementation of /// - /// The key type - /// The value type - public sealed class KeyValueIterator : CommonIterator> + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public sealed class KeyValueIterator : CommonIterator> { #if NET7_0_OR_GREATER - sealed class PrefetchableLocalEnumerator(bool isVersion2, - IGenericSerDesFactory factory, + sealed class PrefetchableLocalEnumerator(IGenericSerDesFactory factory, IJavaObject obj, - ISerDes keySerDes, - ISerDes valueSerDes, + ISerDes keySerDes, + ISerDes valueSerDes, bool isAsync, CancellationToken token = default) - : JVMBridgeBasePrefetchableEnumerator>(obj, new PrefetchableEnumeratorSettings()), + : JVMBridgeBasePrefetchableEnumerator>(obj, new PrefetchableEnumeratorSettings()), IGenericSerDesFactoryApplier, - IAsyncEnumerator> + IAsyncEnumerator> { - readonly bool _isVersion2 = isVersion2; IGenericSerDesFactory _factory = factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } @@ -52,12 +52,9 @@ protected override object ConvertObject(object input) { if (input is IJavaObject obj) { - return _isVersion2 ? new KeyValue(factory, - JVMBridgeBase.Wraps>(obj), - keySerDes, valueSerDes, true) - : new KeyValue(factory, - JVMBridgeBase.Wraps>(obj), - keySerDes, valueSerDes, true); + return new KeyValue(factory, + JVMBridgeBase.WrapsDirect> (obj), + keySerDes, valueSerDes, true); } throw new InvalidCastException($"input is not a valid IJavaObject"); } @@ -67,7 +64,7 @@ protected override bool DoWorkCycle() return isAsync ? !token.IsCancellationRequested : base.DoWorkCycle(); } - public KeyValue Current => (this as IEnumerator>).Current; + public KeyValue Current => (this as IEnumerator>).Current; public ValueTask MoveNextAsync() { @@ -81,22 +78,19 @@ public ValueTask DisposeAsync() } } #endif - sealed class StandardLocalEnumerator : JVMBridgeBaseEnumerator>, IGenericSerDesFactoryApplier, IAsyncEnumerator> + sealed class StandardLocalEnumerator : JVMBridgeBaseEnumerator>, IGenericSerDesFactoryApplier, IAsyncEnumerator> { - readonly ISerDes _keySerDes = null; - readonly ISerDes _valueSerDes = null; - readonly bool _isVersion2; + readonly ISerDes _keySerDes = null; + readonly ISerDes _valueSerDes = null; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } - public StandardLocalEnumerator(bool isVersion2, - IGenericSerDesFactory factory, + public StandardLocalEnumerator(IGenericSerDesFactory factory, IJavaObject obj, - ISerDes keySerDes, - ISerDes valueSerDes) + ISerDes keySerDes, + ISerDes valueSerDes) : base(obj) { - _isVersion2 = isVersion2; _factory = factory; _keySerDes = keySerDes; _valueSerDes = valueSerDes; @@ -106,21 +100,16 @@ protected override object ConvertObject(object input) { if (input is IJavaObject obj) { - return _isVersion2 ? new KeyValue(_factory, - JVMBridgeBase.Wraps>(obj), - _keySerDes, - _valueSerDes, - false) - : new KeyValue(_factory, - JVMBridgeBase.Wraps>(obj), - _keySerDes, - _valueSerDes, - false); + return new KeyValue(_factory, + JVMBridgeBase.WrapsDirect> (obj), + _keySerDes, + _valueSerDes, + false); } throw new InvalidCastException($"input is not a valid IJavaObject"); } - public KeyValue Current => (this as IEnumerator>).Current; + public KeyValue Current => (this as IEnumerator>).Current; public ValueTask MoveNextAsync() { @@ -134,37 +123,29 @@ public ValueTask DisposeAsync() } } - readonly Org.Apache.Kafka.Streams.State.KeyValueIterator _iterator; - readonly Org.Apache.Kafka.Streams.State.KeyValueIterator _iterator2; - ISerDes _keySerDes = null; - ISerDes _valueSerDes = null; + readonly Org.Apache.Kafka.Streams.State.KeyValueIterator _iterator; + ISerDes _keySerDes = null; + ISerDes _valueSerDes = null; - internal KeyValueIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.KeyValueIterator iterator) + internal KeyValueIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.KeyValueIterator iterator) : base(factory) { _iterator = iterator; } - internal KeyValueIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.KeyValueIterator iterator) - : base(factory) - { - _iterator2 = iterator; - } /// protected sealed override object GetEnumerator(bool isAsync, CancellationToken cancellationToken = default) { IGenericSerDesFactory factory = Factory; - _keySerDes ??= factory?.BuildKeySerDes(); - _valueSerDes ??= factory?.BuildValueSerDes(); + _keySerDes ??= factory?.BuildKeySerDes(); + _valueSerDes ??= factory?.BuildValueSerDes(); #if NET7_0_OR_GREATER if (UsePrefetch) { - return _iterator != null ? new PrefetchableLocalEnumerator(false, factory, _iterator.BridgeInstance, _keySerDes, _valueSerDes, isAsync, cancellationToken) - : new PrefetchableLocalEnumerator(true, factory, _iterator2.BridgeInstance, _keySerDes, _valueSerDes, isAsync, cancellationToken); + return new PrefetchableLocalEnumerator(factory, _iterator.BridgeInstance, _keySerDes, _valueSerDes, isAsync, cancellationToken); } #endif - return _iterator != null ? new StandardLocalEnumerator(false, factory, _iterator.BridgeInstance, _keySerDes, _valueSerDes) - : new StandardLocalEnumerator(true, factory, _iterator2.BridgeInstance, _keySerDes, _valueSerDes); + return new StandardLocalEnumerator(factory, _iterator.BridgeInstance, _keySerDes, _valueSerDes); } /// @@ -174,15 +155,14 @@ protected sealed override object GetEnumerator(bool isAsync, CancellationToken c /// /// KNet implementation of /// - public KeyValue Next + public KeyValue Next { get { IGenericSerDesFactory factory = Factory; - _keySerDes ??= factory?.BuildKeySerDes(); - _valueSerDes ??= factory?.BuildValueSerDes(); - return _iterator != null ? new KeyValue(factory, _iterator.Next, _keySerDes, _valueSerDes, false) - : new KeyValue(factory, _iterator2.Next, _keySerDes, _valueSerDes, false); + _keySerDes ??= factory?.BuildKeySerDes(); + _valueSerDes ??= factory?.BuildValueSerDes(); + return new KeyValue(factory, _iterator.Next, _keySerDes, _valueSerDes, false); } } /// @@ -193,26 +173,25 @@ public void Remove() _iterator.Remove(); } /// - /// Returns an of + /// Returns an of /// - /// to return an making preparation of in parallel - /// An of + /// to return an making preparation of in parallel + /// An of /// is not considered with .NET 6 and .NET Framework - public IEnumerator> ToIEnumerator(bool usePrefetch = true) + public IEnumerator> ToIEnumerator(bool usePrefetch = true) { UsePrefetch = usePrefetch; - return GetEnumerator(false) as IEnumerator>; + return GetEnumerator(false) as IEnumerator>; } /// /// KNet implementation of /// - /// - public TKey PeekNextKey + /// + public K PeekNextKey { get { - if (_iterator2 != null) return (TKey)(object)_iterator2.PeekNextKey(); - _keySerDes ??= Factory?.BuildKeySerDes(); + _keySerDes ??= Factory?.BuildKeySerDes(); var kk = _iterator.PeekNextKey(); return _keySerDes.Deserialize(null, kk); } diff --git a/src/net/KNet/Specific/Streams/State/ReadOnlyKeyValueStore.cs b/src/net/KNet/Specific/Streams/State/ReadOnlyKeyValueStore.cs index 51365bf81b..ca48e385c7 100644 --- a/src/net/KNet/Specific/Streams/State/ReadOnlyKeyValueStore.cs +++ b/src/net/KNet/Specific/Streams/State/ReadOnlyKeyValueStore.cs @@ -21,13 +21,13 @@ namespace MASES.KNet.Streams.State { /// - /// KNet implementation of + /// KNet implementation of /// - /// The key type - /// The value type - /// The JVM key type - /// The JVM value type - public abstract class ReadOnlyKeyValueStore : ManagedStore> + /// The key type + /// The value type + /// The JVM key type + /// The JVM value type + public abstract class ReadOnlyKeyValueStore : ManagedStore> { /// /// KNet implementation of @@ -37,51 +37,51 @@ public abstract class ReadOnlyKeyValueStore /// /// KNet implementation of /// - /// - public abstract KeyValueIterator All { get; } + /// + public abstract KeyValueIterator All { get; } /// /// KNet implementation of /// - /// - /// - /// - public abstract KeyValueIterator Range(TKey arg0, TKey arg1); + /// + /// + /// + public abstract KeyValueIterator Range(K arg0, K arg1); /// /// KNet implementation of /// - /// - /// - public abstract TValue Get(TKey arg0); + /// + /// + public abstract V Get(K arg0); /// /// KNet implementation of /// - /// - public abstract KeyValueIterator ReverseAll { get; } + /// + public abstract KeyValueIterator ReverseAll { get; } /// /// KNet implementation of /// - /// - /// - /// - public abstract KeyValueIterator ReverseRange(TKey arg0, TKey arg1); + /// + /// + /// + public abstract KeyValueIterator ReverseRange(K arg0, K arg1); } /// - /// KNet implementation of + /// KNet implementation of /// - /// The key type - /// The value type - public class ReadOnlyKeyValueStore : ReadOnlyKeyValueStore + /// The key type + /// The value type + public class ReadOnlyKeyValueStore : ReadOnlyKeyValueStore { /// public override long ApproximateNumEntries => Store.ApproximateNumEntries(); /// - public override KeyValueIterator All => new(Factory, Store.All()); + public override KeyValueIterator All => new(Factory, Store.All()); /// - public override KeyValueIterator Range(TKey arg0, TKey arg1) + public override KeyValueIterator Range(K arg0, K arg1) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); @@ -89,23 +89,23 @@ public override KeyValueIterator Range(TKey arg0, TKey arg1) return new(factory, Store.Range(r0, r1)); } /// - public override TValue Get(TKey arg0) + public override V Get(K arg0) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); - var _valueSerDes = factory?.BuildValueSerDes(); + var _keySerDes = factory?.BuildKeySerDes(); + var _valueSerDes = factory?.BuildValueSerDes(); var r0 = _keySerDes.Serialize(null, arg0); var res = Store.Get(r0); return _valueSerDes.Deserialize(null, res); } /// - public override KeyValueIterator ReverseAll => new(Factory, Store.ReverseAll()); + public override KeyValueIterator ReverseAll => new(Factory, Store.ReverseAll()); /// - public override KeyValueIterator ReverseRange(TKey arg0, TKey arg1) + public override KeyValueIterator ReverseRange(K arg0, K arg1) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); diff --git a/src/net/KNet/Specific/Streams/State/ReadOnlySessionStore.cs b/src/net/KNet/Specific/Streams/State/ReadOnlySessionStore.cs index ac7387680b..43d5279d5a 100644 --- a/src/net/KNet/Specific/Streams/State/ReadOnlySessionStore.cs +++ b/src/net/KNet/Specific/Streams/State/ReadOnlySessionStore.cs @@ -25,6 +25,8 @@ namespace MASES.KNet.Streams.State /// /// The key type /// The value type + /// The JVM type of + /// The JVM type of public abstract class ReadOnlySessionStore : ManagedStore> { /// @@ -32,14 +34,14 @@ public abstract class ReadOnlySessionStore : ManagedStor /// /// /// - /// - public abstract WindowedKeyValueIterator Fetch(K arg0, K arg1); + /// + public abstract WindowedKeyValueIterator Fetch(K arg0, K arg1); /// /// /// /// /// - public abstract WindowedKeyValueIterator Fetch(K arg0); + public abstract WindowedKeyValueIterator Fetch(K arg0); /// /// /// @@ -62,21 +64,21 @@ public abstract class ReadOnlySessionStore : ManagedStor /// /// /// - public abstract WindowedKeyValueIterator BackwardFetch(K arg0, K arg1); + public abstract WindowedKeyValueIterator BackwardFetch(K arg0, K arg1); /// /// /// /// - /// - public abstract WindowedKeyValueIterator BackwardFetch(K arg0); + /// + public abstract WindowedKeyValueIterator BackwardFetch(K arg0); /// /// /// /// /// /// - /// - public abstract WindowedKeyValueIterator BackwardFindSessions(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); + /// + public abstract WindowedKeyValueIterator BackwardFindSessions(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); /// /// /// @@ -84,8 +86,8 @@ public abstract class ReadOnlySessionStore : ManagedStor /// /// /// - /// - public abstract WindowedKeyValueIterator BackwardFindSessions(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); + /// + public abstract WindowedKeyValueIterator BackwardFindSessions(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); /// /// /// @@ -93,24 +95,24 @@ public abstract class ReadOnlySessionStore : ManagedStor /// /// /// - /// - public abstract WindowedKeyValueIterator BackwardFindSessions(K arg0, K arg1, long arg2, long arg3); + /// + public abstract WindowedKeyValueIterator BackwardFindSessions(K arg0, K arg1, long arg2, long arg3); /// /// /// /// /// /// - /// - public abstract WindowedKeyValueIterator BackwardFindSessions(K arg0, long arg1, long arg2); + /// + public abstract WindowedKeyValueIterator BackwardFindSessions(K arg0, long arg1, long arg2); /// /// /// /// /// /// - /// - public abstract WindowedKeyValueIterator FindSessions(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); + /// + public abstract WindowedKeyValueIterator FindSessions(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); /// /// /// @@ -118,8 +120,8 @@ public abstract class ReadOnlySessionStore : ManagedStor /// /// /// - /// - public abstract WindowedKeyValueIterator FindSessions(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); + /// + public abstract WindowedKeyValueIterator FindSessions(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); /// /// /// @@ -127,16 +129,16 @@ public abstract class ReadOnlySessionStore : ManagedStor /// /// /// - /// - public abstract WindowedKeyValueIterator FindSessions(K arg0, K arg1, long arg2, long arg3); + /// + public abstract WindowedKeyValueIterator FindSessions(K arg0, K arg1, long arg2, long arg3); /// /// /// /// /// /// - /// - public abstract WindowedKeyValueIterator FindSessions(K arg0, long arg1, long arg2); + /// + public abstract WindowedKeyValueIterator FindSessions(K arg0, long arg1, long arg2); } /// @@ -147,30 +149,30 @@ public abstract class ReadOnlySessionStore : ManagedStor public class ReadOnlySessionStore : ReadOnlySessionStore { /// - public override WindowedKeyValueIterator Fetch(K arg0, K arg1) + public override WindowedKeyValueIterator Fetch(K arg0, K arg1) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); - return new WindowedKeyValueIterator(factory, Store.Fetch(r0, r1)); + return new WindowedKeyValueIterator(factory, Store.Fetch(r0, r1)); } /// - public override WindowedKeyValueIterator Fetch(K arg0) + public override WindowedKeyValueIterator Fetch(K arg0) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); - return new WindowedKeyValueIterator(factory, Store.Fetch(r0)); + return new WindowedKeyValueIterator(factory, Store.Fetch(r0)); } /// public override AGG FetchSession(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); - var _valueSerDes = factory?.BuildValueSerDes(); + var _keySerDes = factory?.BuildKeySerDes(); + var _valueSerDes = factory?.BuildValueSerDes(); var r0 = _keySerDes.Serialize(null, arg0); var agg = Store.FetchSession(r0, arg1, arg2); @@ -180,107 +182,107 @@ public override AGG FetchSession(K arg0, Java.Time.Instant arg1, Java.Time.Insta public override AGG FetchSession(K arg0, long arg1, long arg2) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); - var _valueSerDes = factory?.BuildValueSerDes(); + var _keySerDes = factory?.BuildKeySerDes(); + var _valueSerDes = factory?.BuildValueSerDes(); var r0 = _keySerDes.Serialize(null, arg0); var agg = Store.FetchSession(r0, arg1, arg2); return _valueSerDes.Deserialize(null, agg); } /// - public override WindowedKeyValueIterator BackwardFetch(K arg0, K arg1) + public override WindowedKeyValueIterator BackwardFetch(K arg0, K arg1) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); - return new WindowedKeyValueIterator(factory, Store.BackwardFetch(r0, r1)); + return new WindowedKeyValueIterator(factory, Store.BackwardFetch(r0, r1)); } /// - public override WindowedKeyValueIterator BackwardFetch(K arg0) + public override WindowedKeyValueIterator BackwardFetch(K arg0) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); - return new WindowedKeyValueIterator(factory, Store.BackwardFetch(r0)); + return new WindowedKeyValueIterator(factory, Store.BackwardFetch(r0)); } /// - public override WindowedKeyValueIterator BackwardFindSessions(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) + public override WindowedKeyValueIterator BackwardFindSessions(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); - return new WindowedKeyValueIterator(factory, Store.BackwardFindSessions(r0, arg1, arg2)); + return new WindowedKeyValueIterator(factory, Store.BackwardFindSessions(r0, arg1, arg2)); } /// - public override WindowedKeyValueIterator BackwardFindSessions(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) + public override WindowedKeyValueIterator BackwardFindSessions(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); - return new WindowedKeyValueIterator(factory, Store.BackwardFindSessions(r0, r1, arg2, arg3)); + return new WindowedKeyValueIterator(factory, Store.BackwardFindSessions(r0, r1, arg2, arg3)); } /// - public override WindowedKeyValueIterator BackwardFindSessions(K arg0, K arg1, long arg2, long arg3) + public override WindowedKeyValueIterator BackwardFindSessions(K arg0, K arg1, long arg2, long arg3) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); - return new WindowedKeyValueIterator(factory, Store.BackwardFindSessions(r0, r1, arg2, arg3)); + return new WindowedKeyValueIterator(factory, Store.BackwardFindSessions(r0, r1, arg2, arg3)); } /// - public override WindowedKeyValueIterator BackwardFindSessions(K arg0, long arg1, long arg2) + public override WindowedKeyValueIterator BackwardFindSessions(K arg0, long arg1, long arg2) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); - return new WindowedKeyValueIterator(factory, Store.BackwardFindSessions(r0, arg1, arg2)); + return new WindowedKeyValueIterator(factory, Store.BackwardFindSessions(r0, arg1, arg2)); } /// - public override WindowedKeyValueIterator FindSessions(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) + public override WindowedKeyValueIterator FindSessions(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); - return new WindowedKeyValueIterator(factory, Store.BackwardFindSessions(r0, arg1, arg2)); + return new WindowedKeyValueIterator(factory, Store.BackwardFindSessions(r0, arg1, arg2)); } /// - public override WindowedKeyValueIterator FindSessions(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) + public override WindowedKeyValueIterator FindSessions(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); - return new WindowedKeyValueIterator(factory, Store.FindSessions(r0, r1, arg2, arg3)); + return new WindowedKeyValueIterator(factory, Store.FindSessions(r0, r1, arg2, arg3)); } /// - public override WindowedKeyValueIterator FindSessions(K arg0, K arg1, long arg2, long arg3) + public override WindowedKeyValueIterator FindSessions(K arg0, K arg1, long arg2, long arg3) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); - return new WindowedKeyValueIterator(factory, Store.FindSessions(r0, r1, arg2, arg3)); + return new WindowedKeyValueIterator(factory, Store.FindSessions(r0, r1, arg2, arg3)); } /// - public override WindowedKeyValueIterator FindSessions(K arg0, long arg1, long arg2) + public override WindowedKeyValueIterator FindSessions(K arg0, long arg1, long arg2) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); - return new WindowedKeyValueIterator(factory, Store.FindSessions(r0, arg1, arg2)); + return new WindowedKeyValueIterator(factory, Store.FindSessions(r0, arg1, arg2)); } } } diff --git a/src/net/KNet/Specific/Streams/State/ReadOnlyWindowStore.cs b/src/net/KNet/Specific/Streams/State/ReadOnlyWindowStore.cs index db3272ab00..9a0ee7ba9d 100644 --- a/src/net/KNet/Specific/Streams/State/ReadOnlyWindowStore.cs +++ b/src/net/KNet/Specific/Streams/State/ReadOnlyWindowStore.cs @@ -21,27 +21,29 @@ namespace MASES.KNet.Streams.State { /// - /// KNet implementation of + /// KNet implementation of /// - /// The key type - /// The value type - public abstract class ReadOnlyWindowStore : ManagedStore> + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public abstract class ReadOnlyWindowStore : ManagedStore> { /// /// /// - /// - public abstract WindowedKeyValueIterator All { get; } + /// + public abstract WindowedKeyValueIterator All { get; } /// /// /// - /// - /// + /// + /// /// /// - /// + /// /// - public abstract WindowedKeyValueIterator Fetch(TKey arg0, TKey arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); + public abstract WindowedKeyValueIterator Fetch(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); /// /// /// @@ -49,38 +51,38 @@ public abstract class ReadOnlyWindowStore : Ma /// /// /// - public abstract WindowedKeyValueIterator FetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1); + public abstract WindowedKeyValueIterator FetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1); /// /// /// - /// + /// /// /// - /// + /// /// - public abstract WindowStoreIterator Fetch(TKey arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); + public abstract WindowStoreIterator Fetch(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); /// /// /// - /// + /// /// - /// - public abstract TValue Fetch(TKey arg0, long arg1); + /// + public abstract V Fetch(K arg0, long arg1); /// /// /// - /// - public abstract WindowedKeyValueIterator BackwardAll { get; } + /// + public abstract WindowedKeyValueIterator BackwardAll { get; } /// /// /// - /// - /// + /// + /// /// /// - /// + /// /// - public abstract WindowedKeyValueIterator BackwardFetch(TKey arg0, TKey arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); + public abstract WindowedKeyValueIterator BackwardFetch(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); /// /// /// @@ -88,87 +90,87 @@ public abstract class ReadOnlyWindowStore : Ma /// /// /// - public abstract WindowedKeyValueIterator BackwardFetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1); + public abstract WindowedKeyValueIterator BackwardFetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1); /// /// /// - /// + /// /// /// - /// + /// /// - public abstract WindowStoreIterator BackwardFetch(TKey arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); + public abstract WindowStoreIterator BackwardFetch(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); } /// - /// KNet implementation of + /// KNet implementation of /// - /// The key type - /// The value type - public class ReadOnlyWindowStore : ReadOnlyWindowStore + /// The key type + /// The value type + public class ReadOnlyWindowStore : ReadOnlyWindowStore { /// - public override WindowedKeyValueIterator All => new WindowedKeyValueIterator(Factory, Store.All()); + public override WindowedKeyValueIterator All => new WindowedKeyValueIterator(Factory, Store.All()); /// - public override WindowedKeyValueIterator Fetch(TKey arg0, TKey arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) + public override WindowedKeyValueIterator Fetch(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); - return new WindowedKeyValueIterator(factory, Store.Fetch(r0, r1, arg2, arg3)); + return new WindowedKeyValueIterator(factory, Store.Fetch(r0, r1, arg2, arg3)); } /// - public override WindowedKeyValueIterator FetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1) + public override WindowedKeyValueIterator FetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1) { - return new WindowedKeyValueIterator(Factory, Store.FetchAll(arg0, arg1)); + return new WindowedKeyValueIterator(Factory, Store.FetchAll(arg0, arg1)); } /// - public override WindowStoreIterator Fetch(TKey arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) + public override WindowStoreIterator Fetch(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); - return new WindowStoreIterator(factory, Store.Fetch(r0, arg1, arg2)); + return new WindowStoreIterator(factory, Store.Fetch(r0, arg1, arg2)); } /// - public override TValue Fetch(TKey arg0, long arg1) + public override V Fetch(K arg0, long arg1) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); - var _valueSerDes = factory?.BuildValueSerDes(); + var _keySerDes = factory?.BuildKeySerDes(); + var _valueSerDes = factory?.BuildValueSerDes(); var r0 = _keySerDes.Serialize(null, arg0); var agg = Store.Fetch(r0, arg1); return _valueSerDes.Deserialize(null, agg); } /// - public override WindowedKeyValueIterator BackwardAll => new WindowedKeyValueIterator(Factory, Store.BackwardAll()); + public override WindowedKeyValueIterator BackwardAll => new WindowedKeyValueIterator(Factory, Store.BackwardAll()); /// - public override WindowedKeyValueIterator BackwardFetch(TKey arg0, TKey arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) + public override WindowedKeyValueIterator BackwardFetch(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); - return new WindowedKeyValueIterator(factory, Store.BackwardFetch(r0, r1, arg2, arg3)); + return new WindowedKeyValueIterator(factory, Store.BackwardFetch(r0, r1, arg2, arg3)); } /// - public override WindowedKeyValueIterator BackwardFetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1) + public override WindowedKeyValueIterator BackwardFetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1) { - return new WindowedKeyValueIterator(Factory, Store.BackwardFetchAll(arg0, arg1)); + return new WindowedKeyValueIterator(Factory, Store.BackwardFetchAll(arg0, arg1)); } /// - public override WindowStoreIterator BackwardFetch(TKey arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) + public override WindowStoreIterator BackwardFetch(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); - return new WindowStoreIterator(factory, Store.BackwardFetch(r0, arg1, arg2)); + return new WindowStoreIterator(factory, Store.BackwardFetch(r0, arg1, arg2)); } } } diff --git a/src/net/KNet/Specific/Streams/State/TimestampedKeyValueIterator.cs b/src/net/KNet/Specific/Streams/State/TimestampedKeyValueIterator.cs index d78e8fb535..a792ffcaf7 100644 --- a/src/net/KNet/Specific/Streams/State/TimestampedKeyValueIterator.cs +++ b/src/net/KNet/Specific/Streams/State/TimestampedKeyValueIterator.cs @@ -27,23 +27,23 @@ namespace MASES.KNet.Streams.State { /// - /// KNet implementation of + /// KNet implementation of /// - /// The key type - /// The value type - public sealed class TimestampedKeyValueIterator : CommonIterator> + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public sealed class TimestampedKeyValueIterator : CommonIterator> { #if NET7_0_OR_GREATER - sealed class PrefetchableLocalEnumerator(bool isVersion2, - IGenericSerDesFactory factory, + sealed class PrefetchableLocalEnumerator(IGenericSerDesFactory factory, IJavaObject obj, - ISerDes keySerDes, + ISerDes keySerDes, bool isAsync, CancellationToken token = default) - : JVMBridgeBasePrefetchableEnumerator>(obj, new PrefetchableEnumeratorSettings()), + : JVMBridgeBasePrefetchableEnumerator>(obj, new PrefetchableEnumeratorSettings()), IGenericSerDesFactoryApplier, - IAsyncEnumerator> + IAsyncEnumerator> { - readonly bool _isVersion2 = isVersion2; IGenericSerDesFactory _factory = factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } @@ -51,12 +51,9 @@ protected override object ConvertObject(object input) { if (input is IJavaObject obj) { - return _isVersion2 ? new TimestampedKeyValue(factory, - JVMBridgeBase.Wraps>>(obj), - keySerDes, true) - : new TimestampedKeyValue(factory, - JVMBridgeBase.Wraps>>(obj), - keySerDes, true); + return new TimestampedKeyValue(factory, + JVMBridgeBase.WrapsDirect>>(obj), + keySerDes, true); } throw new InvalidCastException($"input is not a valid IJavaObject"); } @@ -65,7 +62,7 @@ protected override bool DoWorkCycle() return isAsync ? !token.IsCancellationRequested : base.DoWorkCycle(); } - public TimestampedKeyValue Current => (this as IEnumerator>).Current; + public TimestampedKeyValue Current => (this as IEnumerator>).Current; public ValueTask MoveNextAsync() { @@ -79,20 +76,17 @@ public ValueTask DisposeAsync() } } #endif - sealed class StandardLocalEnumerator : JVMBridgeBaseEnumerator>, IGenericSerDesFactoryApplier, IAsyncEnumerator> + sealed class StandardLocalEnumerator : JVMBridgeBaseEnumerator>, IGenericSerDesFactoryApplier, IAsyncEnumerator> { - ISerDes _keySerDes = null; - readonly bool _isVersion2; + ISerDes _keySerDes = null; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } - public StandardLocalEnumerator(bool isVersion2, - IGenericSerDesFactory factory, + public StandardLocalEnumerator(IGenericSerDesFactory factory, IJavaObject obj, - ISerDes keySerDes) + ISerDes keySerDes) : base(obj) { - _isVersion2 = isVersion2; _factory = factory; _keySerDes = keySerDes; } @@ -101,17 +95,14 @@ protected override object ConvertObject(object input) { if (input is IJavaObject obj) { - return _isVersion2 ? new TimestampedKeyValue(_factory, - JVMBridgeBase.Wraps>>(obj), - _keySerDes, false) - : new TimestampedKeyValue(_factory, - JVMBridgeBase.Wraps>>(obj), - _keySerDes, false); + return new TimestampedKeyValue(_factory, + JVMBridgeBase.WrapsDirect>>(obj), + _keySerDes, false); } throw new InvalidCastException($"input is not a valid IJavaObject"); } - public TimestampedKeyValue Current => (this as IEnumerator>).Current; + public TimestampedKeyValue Current => (this as IEnumerator>).Current; public ValueTask MoveNextAsync() { @@ -125,36 +116,27 @@ public ValueTask DisposeAsync() } } - readonly Org.Apache.Kafka.Streams.State.KeyValueIterator> _iterator = null; - readonly Org.Apache.Kafka.Streams.State.KeyValueIterator> _iterator2 = null; - ISerDes _keySerDes; + readonly Org.Apache.Kafka.Streams.State.KeyValueIterator> _iterator = null; + ISerDes _keySerDes; - internal TimestampedKeyValueIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.KeyValueIterator> iterator) + internal TimestampedKeyValueIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.KeyValueIterator> iterator) : base(factory) { _iterator = iterator; } - internal TimestampedKeyValueIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.KeyValueIterator> iterator) - : base(factory) - { - _iterator2 = iterator; - } - /// protected sealed override object GetEnumerator(bool isAsync, CancellationToken cancellationToken = default) { IGenericSerDesFactory factory = Factory; - _keySerDes ??= factory?.BuildKeySerDes(); + _keySerDes ??= factory?.BuildKeySerDes(); #if NET7_0_OR_GREATER if (UsePrefetch) { - return _iterator != null ? new PrefetchableLocalEnumerator(false, factory, _iterator.BridgeInstance, _keySerDes, isAsync, cancellationToken) - : new PrefetchableLocalEnumerator(true, factory, _iterator2.BridgeInstance, _keySerDes, isAsync, cancellationToken); + return new PrefetchableLocalEnumerator(factory, _iterator.BridgeInstance, _keySerDes, isAsync, cancellationToken); } #endif - return _iterator != null ? new StandardLocalEnumerator(false, factory, _iterator.BridgeInstance, _keySerDes) - : new StandardLocalEnumerator(true, factory, _iterator2.BridgeInstance, _keySerDes); + return new StandardLocalEnumerator(factory, _iterator.BridgeInstance, _keySerDes); } /// /// KNet implementation of @@ -163,13 +145,13 @@ protected sealed override object GetEnumerator(bool isAsync, CancellationToken c /// /// KNet implementation of /// - public TimestampedKeyValue Next + public TimestampedKeyValue Next { get { IGenericSerDesFactory factory = Factory; - _keySerDes ??= factory?.BuildKeySerDes(); - return new TimestampedKeyValue(factory, _iterator.Next, _keySerDes, false); + _keySerDes ??= factory?.BuildKeySerDes(); + return new TimestampedKeyValue(factory, _iterator.Next, _keySerDes, false); } } /// @@ -180,25 +162,25 @@ public void Remove() _iterator.Remove(); } /// - /// Returns an of + /// Returns an of /// - /// to return an making preparation of in parallel - /// An of + /// to return an making preparation of in parallel + /// An of /// is not considered with .NET 6 and .NET Framework - public IEnumerator> ToIEnumerator(bool usePrefetch = true) + public IEnumerator> ToIEnumerator(bool usePrefetch = true) { UsePrefetch = usePrefetch; - return GetEnumerator(false) as IEnumerator>; + return GetEnumerator(false) as IEnumerator>; } /// /// KNet implementation of /// - /// - public TKey PeekNextKey + /// + public K PeekNextKey { get { - _keySerDes ??= Factory?.BuildKeySerDes(); + _keySerDes ??= Factory?.BuildKeySerDes(); var kk = _iterator.PeekNextKey(); return _keySerDes.Deserialize(null, kk); } diff --git a/src/net/KNet/Specific/Streams/State/TimestampedKeyValueStore.cs b/src/net/KNet/Specific/Streams/State/TimestampedKeyValueStore.cs index 9eadddd019..c2b7cc016e 100644 --- a/src/net/KNet/Specific/Streams/State/TimestampedKeyValueStore.cs +++ b/src/net/KNet/Specific/Streams/State/TimestampedKeyValueStore.cs @@ -21,11 +21,13 @@ namespace MASES.KNet.Streams.State { /// - /// KNet implementation of + /// KNet implementation of /// - /// The key type - /// The value type - public abstract class TimestampedKeyValueStore : ManagedStore>> + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public abstract class TimestampedKeyValueStore : ManagedStore>> { /// /// KNet implementation of @@ -35,51 +37,51 @@ public abstract class TimestampedKeyValueStore /// /// KNet implementation of /// - /// - public abstract TimestampedKeyValueIterator All { get; } + /// + public abstract TimestampedKeyValueIterator All { get; } /// /// KNet implementation of /// - /// - /// - /// - public abstract TimestampedKeyValueIterator Range(TKey arg0, TKey arg1); + /// + /// + /// + public abstract TimestampedKeyValueIterator Range(K arg0, K arg1); /// /// KNet implementation of /// - /// - /// - public abstract ValueAndTimestamp Get(TKey arg0); + /// + /// + public abstract ValueAndTimestamp Get(K arg0); /// /// KNet implementation of /// - /// - public abstract TimestampedKeyValueIterator ReverseAll { get; } + /// + public abstract TimestampedKeyValueIterator ReverseAll { get; } /// /// KNet implementation of /// - /// - /// - /// - public abstract TimestampedKeyValueIterator ReverseRange(TKey arg0, TKey arg1); + /// + /// + /// + public abstract TimestampedKeyValueIterator ReverseRange(K arg0, K arg1); } /// /// KNet implementation of /// - /// The key type - /// The value type - public class TimestampedKeyValueStore : TimestampedKeyValueStore + /// The key type + /// The value type + public class TimestampedKeyValueStore : TimestampedKeyValueStore { /// public override long ApproximateNumEntries => Store.ApproximateNumEntries(); /// - public override TimestampedKeyValueIterator All => new(Factory, Store.All()); + public override TimestampedKeyValueIterator All => new(Factory, Store.All()); /// - public override TimestampedKeyValueIterator Range(TKey arg0, TKey arg1) + public override TimestampedKeyValueIterator Range(K arg0, K arg1) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); @@ -87,22 +89,22 @@ public override TimestampedKeyValueIterator Range(TKey arg0, TKey return new(factory, Store.Range(r0, r1)); } /// - public override ValueAndTimestamp Get(TKey arg0) + public override ValueAndTimestamp Get(K arg0) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var res = Store.Get(r0); - return new ValueAndTimestamp(factory, res); + return new ValueAndTimestamp(factory, res); } /// - public override TimestampedKeyValueIterator ReverseAll => new(Factory, Store.ReverseAll()); + public override TimestampedKeyValueIterator ReverseAll => new(Factory, Store.ReverseAll()); /// - public override TimestampedKeyValueIterator ReverseRange(TKey arg0, TKey arg1) + public override TimestampedKeyValueIterator ReverseRange(K arg0, K arg1) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); diff --git a/src/net/KNet/Specific/Streams/State/TimestampedWindowStore.cs b/src/net/KNet/Specific/Streams/State/TimestampedWindowStore.cs index acc64fa647..471740d4f5 100644 --- a/src/net/KNet/Specific/Streams/State/TimestampedWindowStore.cs +++ b/src/net/KNet/Specific/Streams/State/TimestampedWindowStore.cs @@ -21,99 +21,101 @@ namespace MASES.KNet.Streams.State { /// - /// KNet implementation of + /// KNet implementation of /// - /// The key type - /// The value type - public abstract class TimestampedWindowStore : ManagedStore>> + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public abstract class TimestampedWindowStore : ManagedStore>> { /// /// /// - /// - public abstract TimestampedWindowedKeyValueIterator All { get; } + /// + public abstract TimestampedWindowedKeyValueIterator All { get; } /// /// /// - /// - /// + /// + /// /// /// - /// + /// /// - public abstract TimestampedWindowedKeyValueIterator Fetch(TKey arg0, TKey arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); + public abstract TimestampedWindowedKeyValueIterator Fetch(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); /// /// /// /// /// - /// + /// /// - public abstract TimestampedWindowedKeyValueIterator FetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1); + public abstract TimestampedWindowedKeyValueIterator FetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1); /// /// /// - /// + /// /// /// - /// + /// /// - public abstract TimestampedWindowStoreIterator Fetch(TKey arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); + public abstract TimestampedWindowStoreIterator Fetch(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); /// /// /// - /// + /// /// - /// - public abstract ValueAndTimestamp Fetch(TKey arg0, long arg1); + /// + public abstract ValueAndTimestamp Fetch(K arg0, long arg1); /// /// /// - /// - public abstract TimestampedWindowedKeyValueIterator BackwardAll { get; } + /// + public abstract TimestampedWindowedKeyValueIterator BackwardAll { get; } /// /// /// - /// - /// + /// + /// /// /// - /// + /// /// - public abstract TimestampedWindowedKeyValueIterator BackwardFetch(TKey arg0, TKey arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); + public abstract TimestampedWindowedKeyValueIterator BackwardFetch(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3); /// /// /// /// /// - /// + /// /// - public abstract TimestampedWindowedKeyValueIterator BackwardFetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1); + public abstract TimestampedWindowedKeyValueIterator BackwardFetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1); /// /// /// - /// + /// /// /// - /// + /// /// - public abstract TimestampedWindowStoreIterator BackwardFetch(TKey arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); + public abstract TimestampedWindowStoreIterator BackwardFetch(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2); } /// /// KNet implementation of /// - /// The key type - /// The value type - public class TimestampedWindowStore : TimestampedWindowStore + /// The key type + /// The value type + public class TimestampedWindowStore : TimestampedWindowStore { /// - public override TimestampedWindowedKeyValueIterator All => new TimestampedWindowedKeyValueIterator(Factory, Store.All()); + public override TimestampedWindowedKeyValueIterator All => new TimestampedWindowedKeyValueIterator(Factory, Store.All()); /// - public override TimestampedWindowedKeyValueIterator Fetch(TKey arg0, TKey arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) + public override TimestampedWindowedKeyValueIterator Fetch(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); @@ -121,36 +123,36 @@ public override TimestampedWindowedKeyValueIterator Fetch(TKey arg return new(factory, Store.Fetch(r0, r1, arg2, arg3)); } /// - public override TimestampedWindowedKeyValueIterator FetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1) + public override TimestampedWindowedKeyValueIterator FetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1) { return new(Factory, Store.FetchAll(arg0, arg1)); } /// - public override TimestampedWindowStoreIterator Fetch(TKey arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) + public override TimestampedWindowStoreIterator Fetch(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); return new(factory, Store.Fetch(r0, arg1, arg2)); } /// - public override ValueAndTimestamp Fetch(TKey arg0, long arg1) + public override ValueAndTimestamp Fetch(K arg0, long arg1) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var agg = Store.Fetch(r0, arg1); - return new ValueAndTimestamp(factory, agg); + return new ValueAndTimestamp(factory, agg); } /// - public override TimestampedWindowedKeyValueIterator BackwardAll => new(Factory, Store.BackwardAll()); + public override TimestampedWindowedKeyValueIterator BackwardAll => new(Factory, Store.BackwardAll()); /// - public override TimestampedWindowedKeyValueIterator BackwardFetch(TKey arg0, TKey arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) + public override TimestampedWindowedKeyValueIterator BackwardFetch(K arg0, K arg1, Java.Time.Instant arg2, Java.Time.Instant arg3) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); var r1 = _keySerDes.Serialize(null, arg1); @@ -158,15 +160,15 @@ public override TimestampedWindowedKeyValueIterator BackwardFetch( return new(factory, Store.BackwardFetch(r0, r1, arg2, arg3)); } /// - public override TimestampedWindowedKeyValueIterator BackwardFetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1) + public override TimestampedWindowedKeyValueIterator BackwardFetchAll(Java.Time.Instant arg0, Java.Time.Instant arg1) { return new(Factory, Store.BackwardFetchAll(arg0, arg1)); } /// - public override TimestampedWindowStoreIterator BackwardFetch(TKey arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) + public override TimestampedWindowStoreIterator BackwardFetch(K arg0, Java.Time.Instant arg1, Java.Time.Instant arg2) { IGenericSerDesFactory factory = Factory; - var _keySerDes = factory?.BuildKeySerDes(); + var _keySerDes = factory?.BuildKeySerDes(); var r0 = _keySerDes.Serialize(null, arg0); diff --git a/src/net/KNet/Specific/Streams/State/TimestampedWindowStoreIterator.cs b/src/net/KNet/Specific/Streams/State/TimestampedWindowStoreIterator.cs index 9fdd482179..767fc2b41e 100644 --- a/src/net/KNet/Specific/Streams/State/TimestampedWindowStoreIterator.cs +++ b/src/net/KNet/Specific/Streams/State/TimestampedWindowStoreIterator.cs @@ -24,23 +24,24 @@ namespace MASES.KNet.Streams.State /// /// KNet implementation of /// - /// The value type - public sealed class TimestampedWindowStoreIterator : IGenericSerDesFactoryApplier + /// The value type + /// The JVM value type + public sealed class TimestampedWindowStoreIterator : IGenericSerDesFactoryApplier { - readonly Org.Apache.Kafka.Streams.State.WindowStoreIterator> _iterator; + readonly Org.Apache.Kafka.Streams.State.WindowStoreIterator> _iterator; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } - internal TimestampedWindowStoreIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.WindowStoreIterator> iterator) + internal TimestampedWindowStoreIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.WindowStoreIterator> iterator) { _factory = factory; _iterator = iterator; } /// - /// Converter from to + /// Converter from to /// - public static implicit operator TimestampedKeyValueIterator(TimestampedWindowStoreIterator t) => new TimestampedKeyValueIterator(t._factory, t._iterator.Cast>>()); + public static implicit operator TimestampedKeyValueIterator(TimestampedWindowStoreIterator t) => new TimestampedKeyValueIterator(t._factory, t._iterator.Cast>>()); /// /// KNet implementation of diff --git a/src/net/KNet/Specific/Streams/State/TimestampedWindowedKeyValueIterator.cs b/src/net/KNet/Specific/Streams/State/TimestampedWindowedKeyValueIterator.cs index 3f1d4cba80..c3fe3317df 100644 --- a/src/net/KNet/Specific/Streams/State/TimestampedWindowedKeyValueIterator.cs +++ b/src/net/KNet/Specific/Streams/State/TimestampedWindowedKeyValueIterator.cs @@ -28,19 +28,21 @@ namespace MASES.KNet.Streams.State { /// - /// KNet implementation of + /// KNet implementation of /// - /// The key type - /// The value type - public sealed class TimestampedWindowedKeyValueIterator : CommonIterator> + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public sealed class TimestampedWindowedKeyValueIterator : CommonIterator> { #if NET7_0_OR_GREATER sealed class PrefetchableLocalEnumerator(IGenericSerDesFactory factory, IJavaObject obj, bool isAsync, CancellationToken token = default) - : JVMBridgeBasePrefetchableEnumerator>(obj, new PrefetchableEnumeratorSettings()), + : JVMBridgeBasePrefetchableEnumerator>(obj, new PrefetchableEnumeratorSettings()), IGenericSerDesFactoryApplier, - IAsyncEnumerator> + IAsyncEnumerator> { IGenericSerDesFactory _factory = factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } @@ -49,7 +51,7 @@ protected override object ConvertObject(object input) { if (input is IJavaObject obj) { - return new TimestampedWindowedKeyValue(factory, JVMBridgeBase.Wraps, Org.Apache.Kafka.Streams.State.ValueAndTimestamp>>(obj)); + return new TimestampedWindowedKeyValue(factory, JVMBridgeBase.WrapsDirect, Org.Apache.Kafka.Streams.State.ValueAndTimestamp>>(obj)); } throw new InvalidCastException($"input is not a valid IJavaObject"); } @@ -59,7 +61,7 @@ protected override bool DoWorkCycle() return isAsync ? !token.IsCancellationRequested : base.DoWorkCycle(); } - public TimestampedWindowedKeyValue Current => (this as IEnumerator>).Current; + public TimestampedWindowedKeyValue Current => (this as IEnumerator>).Current; public ValueTask MoveNextAsync() { @@ -74,7 +76,7 @@ public ValueTask DisposeAsync() } #endif - sealed class StandardLocalEnumerator : JVMBridgeBaseEnumerator>, IGenericSerDesFactoryApplier, IAsyncEnumerator> + sealed class StandardLocalEnumerator : JVMBridgeBaseEnumerator>, IGenericSerDesFactoryApplier, IAsyncEnumerator> { IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } @@ -88,12 +90,12 @@ protected override object ConvertObject(object input) { if (input is IJavaObject obj) { - return new TimestampedWindowedKeyValue(_factory, JVMBridgeBase.Wraps, Org.Apache.Kafka.Streams.State.ValueAndTimestamp>>(obj)); + return new TimestampedWindowedKeyValue(_factory, JVMBridgeBase.WrapsDirect, Org.Apache.Kafka.Streams.State.ValueAndTimestamp>>(obj)); } throw new InvalidCastException($"input is not a valid IJavaObject"); } - public TimestampedWindowedKeyValue Current => (this as IEnumerator>).Current; + public TimestampedWindowedKeyValue Current => (this as IEnumerator>).Current; public ValueTask MoveNextAsync() { @@ -107,9 +109,9 @@ public ValueTask DisposeAsync() } } - readonly Org.Apache.Kafka.Streams.State.KeyValueIterator, Org.Apache.Kafka.Streams.State.ValueAndTimestamp> _iterator; + readonly Org.Apache.Kafka.Streams.State.KeyValueIterator, Org.Apache.Kafka.Streams.State.ValueAndTimestamp> _iterator; - internal TimestampedWindowedKeyValueIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.KeyValueIterator, Org.Apache.Kafka.Streams.State.ValueAndTimestamp> iterator) + internal TimestampedWindowedKeyValueIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.KeyValueIterator, Org.Apache.Kafka.Streams.State.ValueAndTimestamp> iterator) :base(factory) { _iterator = iterator; @@ -134,9 +136,9 @@ protected sealed override object GetEnumerator(bool isAsync, CancellationToken c /// /// KNet implementation of /// - public TimestampedWindowedKeyValue Next + public TimestampedWindowedKeyValue Next { - get { return new TimestampedWindowedKeyValue(Factory, _iterator.Next); } + get { return new TimestampedWindowedKeyValue(Factory, _iterator.Next); } } /// /// @@ -146,26 +148,26 @@ public void Remove() _iterator.Remove(); } /// - /// Returns an of + /// Returns an of /// - /// to return an making preparation of in parallel - /// An of + /// to return an making preparation of in parallel + /// An of /// is not considered with .NET 6 and .NET Framework - public IEnumerator> ToIEnumerator(bool usePrefetch = true) + public IEnumerator> ToIEnumerator(bool usePrefetch = true) { UsePrefetch = usePrefetch; - return GetEnumerator(false) as IEnumerator>; + return GetEnumerator(false) as IEnumerator>; } /// /// KNet implementation of /// - /// - public Windowed PeekNextKey + /// + public Windowed PeekNextKey { get { var kk = _iterator.PeekNextKey(); - return new Windowed(Factory, kk); + return new Windowed(Factory, kk); } } /// diff --git a/src/net/KNet/Specific/Streams/State/ValueAndTimestamp.cs b/src/net/KNet/Specific/Streams/State/ValueAndTimestamp.cs index 82ad687ba6..e4b0f6a2c5 100644 --- a/src/net/KNet/Specific/Streams/State/ValueAndTimestamp.cs +++ b/src/net/KNet/Specific/Streams/State/ValueAndTimestamp.cs @@ -24,15 +24,16 @@ namespace MASES.KNet.Streams.State /// /// KNet Implementation of /// - /// The value type - public class ValueAndTimestamp : IGenericSerDesFactoryApplier + /// The value type + /// The JVM type of + public class ValueAndTimestamp : IGenericSerDesFactoryApplier { - readonly Org.Apache.Kafka.Streams.State.ValueAndTimestamp _valueAndTimestamp; - ISerDes _valueSerDes; + readonly Org.Apache.Kafka.Streams.State.ValueAndTimestamp _valueAndTimestamp; + ISerDes _valueSerDes; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } - internal ValueAndTimestamp(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.ValueAndTimestamp valueAndTimestamp) + internal ValueAndTimestamp(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.ValueAndTimestamp valueAndTimestamp) { _factory = factory; _valueAndTimestamp = valueAndTimestamp; @@ -51,12 +52,12 @@ internal ValueAndTimestamp(IGenericSerDesFactory factory, Org.Apache.Kafka.Strea /// /// /// - /// - public TValue Value + /// + public V Value { get { - _valueSerDes ??= _factory?.BuildKeySerDes(); + _valueSerDes ??= _factory?.BuildKeySerDes(); var vv = _valueAndTimestamp.Value(); return _valueSerDes.Deserialize(null, vv); } diff --git a/src/net/KNet/Specific/Streams/State/WindowStoreIterator.cs b/src/net/KNet/Specific/Streams/State/WindowStoreIterator.cs index 326ce3b622..7ca31c0e2a 100644 --- a/src/net/KNet/Specific/Streams/State/WindowStoreIterator.cs +++ b/src/net/KNet/Specific/Streams/State/WindowStoreIterator.cs @@ -22,25 +22,26 @@ namespace MASES.KNet.Streams.State { /// - /// KNet implementation of + /// KNet implementation of /// - /// The value type - public class WindowStoreIterator : IGenericSerDesFactoryApplier + /// The value type + /// The JVM type of + public class WindowStoreIterator : IGenericSerDesFactoryApplier { - readonly Org.Apache.Kafka.Streams.State.WindowStoreIterator _iterator; + readonly Org.Apache.Kafka.Streams.State.WindowStoreIterator _iterator; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } - internal WindowStoreIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.WindowStoreIterator iterator) + internal WindowStoreIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.WindowStoreIterator iterator) { _factory = factory; _iterator = iterator; } /// - /// Converter from to + /// Converter from to /// - public static implicit operator KeyValueIterator(WindowStoreIterator t) => new KeyValueIterator(t._factory, t._iterator.Cast>()); + public static implicit operator KeyValueIterator(WindowStoreIterator t) => new KeyValueIterator(t._factory, t._iterator.Cast>()); /// /// KNet implementation of diff --git a/src/net/KNet/Specific/Streams/State/WindowedKeyValueIterator.cs b/src/net/KNet/Specific/Streams/State/WindowedKeyValueIterator.cs index 9dded71c32..b75cc40230 100644 --- a/src/net/KNet/Specific/Streams/State/WindowedKeyValueIterator.cs +++ b/src/net/KNet/Specific/Streams/State/WindowedKeyValueIterator.cs @@ -30,18 +30,20 @@ namespace MASES.KNet.Streams.State /// /// KNet implementation of where K is /// - /// The key type - /// The value type - public sealed class WindowedKeyValueIterator : CommonIterator> + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public sealed class WindowedKeyValueIterator : CommonIterator> { #if NET7_0_OR_GREATER sealed class PrefetchableLocalEnumerator(IGenericSerDesFactory factory, IJavaObject obj, - ISerDes valueSerDes, + ISerDes valueSerDes, bool isAsync, CancellationToken token = default) - : JVMBridgeBasePrefetchableEnumerator>(obj, new PrefetchableEnumeratorSettings()), + : JVMBridgeBasePrefetchableEnumerator>(obj, new PrefetchableEnumeratorSettings()), IGenericSerDesFactoryApplier, - IAsyncEnumerator> + IAsyncEnumerator> { IGenericSerDesFactory _factory = factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } @@ -50,8 +52,8 @@ protected override object ConvertObject(object input) { if (input is IJavaObject obj) { - return new WindowedKeyValue(_factory, - JVMBridgeBase.Wraps, byte[]>>(obj), + return new WindowedKeyValue(_factory, + JVMBridgeBase.WrapsDirect, TJVMV>>(obj), valueSerDes, true); } throw new InvalidCastException($"input is not a valid IJavaObject"); @@ -62,7 +64,7 @@ protected override bool DoWorkCycle() return isAsync ? !token.IsCancellationRequested : base.DoWorkCycle(); } - public WindowedKeyValue Current => (this as IEnumerator>).Current; + public WindowedKeyValue Current => (this as IEnumerator>).Current; public ValueTask MoveNextAsync() { @@ -76,15 +78,15 @@ public ValueTask DisposeAsync() } } #endif - sealed class StandardLocalEnumerator : JVMBridgeBaseEnumerator>, IGenericSerDesFactoryApplier, IAsyncEnumerator> + sealed class StandardLocalEnumerator : JVMBridgeBaseEnumerator>, IGenericSerDesFactoryApplier, IAsyncEnumerator> { - ISerDes _valueSerDes = null; + ISerDes _valueSerDes = null; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } public StandardLocalEnumerator(IGenericSerDesFactory factory, IJavaObject obj, - ISerDes valueSerDes) + ISerDes valueSerDes) : base(obj) { _factory = factory; @@ -95,14 +97,14 @@ protected override object ConvertObject(object input) { if (input is IJavaObject obj) { - return new WindowedKeyValue(_factory, - JVMBridgeBase.Wraps, byte[]>>(obj), + return new WindowedKeyValue(_factory, + JVMBridgeBase.WrapsDirect, TJVMV>>(obj), _valueSerDes, false); } throw new InvalidCastException($"input is not a valid IJavaObject"); } - public WindowedKeyValue Current => (this as IEnumerator>).Current; + public WindowedKeyValue Current => (this as IEnumerator>).Current; public ValueTask MoveNextAsync() { @@ -116,10 +118,10 @@ public ValueTask DisposeAsync() } } - readonly Org.Apache.Kafka.Streams.State.KeyValueIterator, byte[]> _iterator; - ISerDes _valueSerDes = null; + readonly Org.Apache.Kafka.Streams.State.KeyValueIterator, TJVMV> _iterator; + ISerDes _valueSerDes = null; - internal WindowedKeyValueIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.KeyValueIterator, byte[]> iterator) + internal WindowedKeyValueIterator(IGenericSerDesFactory factory, Org.Apache.Kafka.Streams.State.KeyValueIterator, TJVMV> iterator) :base(factory) { _iterator = iterator; @@ -129,7 +131,7 @@ internal WindowedKeyValueIterator(IGenericSerDesFactory factory, Org.Apache.Kafk protected sealed override object GetEnumerator(bool isAsync, CancellationToken cancellationToken = default) { IGenericSerDesFactory factory = Factory; - _valueSerDes ??= factory?.BuildValueSerDes(); + _valueSerDes ??= factory?.BuildValueSerDes(); #if NET7_0_OR_GREATER if (UsePrefetch) { @@ -145,13 +147,13 @@ protected sealed override object GetEnumerator(bool isAsync, CancellationToken c /// /// KNet implementation of /// - public WindowedKeyValue Next + public WindowedKeyValue Next { get { IGenericSerDesFactory factory = Factory; - _valueSerDes ??= factory?.BuildValueSerDes(); - return new WindowedKeyValue(factory, _iterator.Next, _valueSerDes, false); + _valueSerDes ??= factory?.BuildValueSerDes(); + return new WindowedKeyValue(factory, _iterator.Next, _valueSerDes, false); } } /// @@ -162,26 +164,26 @@ public void Remove() _iterator.Remove(); } /// - /// Returns an of + /// Returns an of /// - /// to return an making preparation of in parallel - /// An of + /// to return an making preparation of in parallel + /// An of /// is not considered with .NET 6 and .NET Framework - public IEnumerator> ToIEnumerator(bool usePrefetch = true) + public IEnumerator> ToIEnumerator(bool usePrefetch = true) { UsePrefetch = usePrefetch; - return GetEnumerator(false) as IEnumerator>; + return GetEnumerator(false) as IEnumerator>; } /// /// KNet implementation of /// - /// - public Windowed PeekNextKey + /// + public Windowed PeekNextKey { get { var kk = _iterator.PeekNextKey(); - return new Windowed(Factory, kk); + return new Windowed(Factory, kk); } } /// diff --git a/src/net/KNet/Specific/Streams/StreamsBuilder.cs b/src/net/KNet/Specific/Streams/StreamsBuilder.cs index 97052495dd..d5a005f453 100644 --- a/src/net/KNet/Specific/Streams/StreamsBuilder.cs +++ b/src/net/KNet/Specific/Streams/StreamsBuilder.cs @@ -70,12 +70,12 @@ protected virtual Java.Util.Properties PrepareProperties(StreamsConfigBuilder bu /// /// /// - /// + /// /// /// /// /// - public GlobalKTable GlobalTable(string arg0, Consumed arg1, Materialized arg2) + public GlobalKTable GlobalTable(string arg0, Consumed arg1, Materialized arg2) { if (arg1 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; if (arg2 is IGenericSerDesFactoryApplier applier2) applier2.Factory = _factory; @@ -85,11 +85,11 @@ public GlobalKTable GlobalTable(string arg0, Consume /// /// /// - /// + /// /// /// /// - public GlobalKTable GlobalTable(string arg0, Consumed arg1) + public GlobalKTable GlobalTable(string arg0, Consumed arg1) { if (arg1 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; return new GlobalKTable(_factory, _builder.GlobalTable(arg0, arg1)); @@ -122,11 +122,11 @@ public GlobalKTable GlobalTable(string arg0) /// /// /// - /// + /// /// /// /// - public KStream Stream(string arg0, Consumed arg1) + public KStream Stream(string arg0, Consumed arg1) { if (arg1 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; return new KStream(_factory, _builder.Stream(arg0)); @@ -146,11 +146,11 @@ public KStream Stream(string arg0) /// /// /// - /// + /// /// /// /// - public KStream Stream(System.Collections.Generic.IEnumerable arg0, Consumed arg1) + public KStream Stream(System.Collections.Generic.IEnumerable arg0, Consumed arg1) { if (arg1 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; return new KStream(_factory, _builder.Stream(arg0.ToJVMCollection(), arg1)); @@ -170,11 +170,11 @@ public KStream Stream(System.Collections.Generic.IEn /// /// /// - /// + /// /// /// /// - public KStream Stream(Java.Util.Regex.Pattern arg0, Consumed arg1) + public KStream Stream(Java.Util.Regex.Pattern arg0, Consumed arg1) { if (arg1 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; return new KStream(_factory, _builder.Stream(arg0)); @@ -194,12 +194,12 @@ public KStream Stream(Java.Util.Regex.Pattern arg0) /// /// /// - /// + /// /// /// /// /// - public KTable Table(string arg0, Consumed arg1, Materialized arg2) + public KTable Table(string arg0, Consumed arg1, Materialized arg2) { if (arg1 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; if (arg2 is IGenericSerDesFactoryApplier applier2) applier2.Factory = _factory; @@ -209,11 +209,11 @@ public KTable Table(string arg0, Consumed arg1 /// /// /// - /// + /// /// /// /// - public KTable Table(string arg0, Consumed arg1) + public KTable Table(string arg0, Consumed arg1) { if (arg1 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; return new KTable(_factory, _builder.Table(arg0, arg1)); diff --git a/src/net/KNet/Specific/Streams/TimestampedKeyValue.cs b/src/net/KNet/Specific/Streams/TimestampedKeyValue.cs index 8bee2f8b52..10dacbf8a2 100644 --- a/src/net/KNet/Specific/Streams/TimestampedKeyValue.cs +++ b/src/net/KNet/Specific/Streams/TimestampedKeyValue.cs @@ -24,47 +24,33 @@ namespace MASES.KNet.Streams /// /// KNet implementation of /// - /// The key type - /// The value type - public sealed class TimestampedKeyValue : IGenericSerDesFactoryApplier + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public sealed class TimestampedKeyValue : IGenericSerDesFactoryApplier { - readonly Org.Apache.Kafka.Streams.KeyValue> _valueInner1 = null; - readonly Org.Apache.Kafka.Streams.KeyValue> _valueInner2 = null; - TKey _key; + readonly Org.Apache.Kafka.Streams.KeyValue> _inner = null; + + K _key; bool _keyStored = false; - ValueAndTimestamp _value = null; - ISerDes _keySerDes = null; + ValueAndTimestamp _value = null; + ISerDes _keySerDes = null; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } internal TimestampedKeyValue(IGenericSerDesFactory factory, - Org.Apache.Kafka.Streams.KeyValue> value, - ISerDes keySerDes, - bool fromPrefetched) - { - _factory = factory; - _valueInner1 = value; - _keySerDes = keySerDes; - if (fromPrefetched) - { - _keySerDes ??= _factory?.BuildKeySerDes(); - _key = _keySerDes.Deserialize(null, _valueInner1.key); - _keyStored = true; - } - } - - internal TimestampedKeyValue(IGenericSerDesFactory factory, - Org.Apache.Kafka.Streams.KeyValue> value, - ISerDes keySerDes, + Org.Apache.Kafka.Streams.KeyValue> value, + ISerDes keySerDes, bool fromPrefetched) { _factory = factory; - _valueInner2 = value; + _inner = value; _keySerDes = keySerDes; if (fromPrefetched) { - _keySerDes ??= _factory?.BuildKeySerDes(); - _key = (TKey)(object)_valueInner2.key.LongValue(); + _keySerDes ??= _factory?.BuildKeySerDes(); + _key = _keySerDes.Deserialize(null, _inner.key); _keyStored = true; } } @@ -72,21 +58,14 @@ internal TimestampedKeyValue(IGenericSerDesFactory factory, /// /// KNet implementation of /// - public TKey Key + public K Key { get { if (!_keyStored) { - if (_valueInner2 != null && _valueInner2.key != null) - { - var ll = _valueInner2.key; _key = (TKey)(object)ll.LongValue(); - } - else - { - _keySerDes ??= _factory?.BuildKeySerDes(); - _key = _keySerDes.Deserialize(null, _valueInner1.key); - } + _keySerDes ??= _factory?.BuildKeySerDes(); + _key = _keySerDes.Deserialize(null, _inner.key); _keyStored = true; } return _key; @@ -95,11 +74,11 @@ public TKey Key /// /// KNet implementation of /// - public ValueAndTimestamp Value + public ValueAndTimestamp Value { get { - _value ??= new ValueAndTimestamp(_factory, _valueInner1 != null ? _valueInner1.value : _valueInner2.value); + _value ??= new ValueAndTimestamp(_factory, _inner.value); return _value; } } diff --git a/src/net/KNet/Specific/Streams/TimestampedWindowedKeyValue.cs b/src/net/KNet/Specific/Streams/TimestampedWindowedKeyValue.cs index ec1a7535de..3324adc6fa 100644 --- a/src/net/KNet/Specific/Streams/TimestampedWindowedKeyValue.cs +++ b/src/net/KNet/Specific/Streams/TimestampedWindowedKeyValue.cs @@ -23,20 +23,22 @@ namespace MASES.KNet.Streams { /// - /// KNet implementation of + /// KNet implementation of /// - /// The key type - /// The value type - public sealed class TimestampedWindowedKeyValue : IGenericSerDesFactoryApplier + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public sealed class TimestampedWindowedKeyValue : IGenericSerDesFactoryApplier { - readonly Org.Apache.Kafka.Streams.KeyValue, Org.Apache.Kafka.Streams.State.ValueAndTimestamp> _valueInner; - Windowed _key = null; - ValueAndTimestamp _value = null; + readonly Org.Apache.Kafka.Streams.KeyValue, Org.Apache.Kafka.Streams.State.ValueAndTimestamp> _valueInner; + Windowed _key = null; + ValueAndTimestamp _value = null; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } internal TimestampedWindowedKeyValue(IGenericSerDesFactory factory, - Org.Apache.Kafka.Streams.KeyValue, Org.Apache.Kafka.Streams.State.ValueAndTimestamp> value) + Org.Apache.Kafka.Streams.KeyValue, Org.Apache.Kafka.Streams.State.ValueAndTimestamp> value) { _factory = factory; _valueInner = value; @@ -45,22 +47,22 @@ internal TimestampedWindowedKeyValue(IGenericSerDesFactory factory, /// /// KNet implementation of /// - public Windowed Key + public Windowed Key { get { - _key ??= new Windowed(_factory, _valueInner.key); + _key ??= new Windowed(_factory, _valueInner.key); return _key; } } /// /// KNet implementation of /// - public ValueAndTimestamp Value + public ValueAndTimestamp Value { get { - _value ??= new ValueAndTimestamp(_factory, _valueInner.value); + _value ??= new ValueAndTimestamp(_factory, _valueInner.value); return _value; } } diff --git a/src/net/KNet/Specific/Streams/Topology.cs b/src/net/KNet/Specific/Streams/Topology.cs index 5a860e5b17..c1a5375dcf 100644 --- a/src/net/KNet/Specific/Streams/Topology.cs +++ b/src/net/KNet/Specific/Streams/Topology.cs @@ -65,13 +65,13 @@ internal Topology(Org.Apache.Kafka.Streams.Topology topology, IGenericSerDesFact /// /// /// - /// - /// + /// + /// /// /// /// /// - public Topology AddSink(string arg0, string arg1, ISerializer arg2, ISerializer arg3, params string[] arg4) + public Topology AddSink(string arg0, string arg1, ISerializer arg2, ISerializer arg3, params string[] arg4) { var top = _topology.AddSink(arg0, arg1, arg2.KafkaSerializer, arg3.KafkaSerializer, arg4.ToJVMArray()); return new Topology(top, _factory); @@ -81,8 +81,8 @@ public Topology AddSink(string arg0, string arg1, ISerializer arg2, ISe /// /// /// - /// - /// + /// + /// /// /// /// @@ -90,7 +90,7 @@ public Topology AddSink(string arg0, string arg1, ISerializer arg2, ISe /// /// /// - public Topology AddSink(string arg0, string arg1, ISerializer arg2, ISerializer arg3, StreamPartitioner arg4, params string[] arg5) where Arg4objectSuperK : K where Arg4objectSuperV : V + public Topology AddSink(string arg0, string arg1, ISerializer arg2, ISerializer arg3, StreamPartitioner arg4, params string[] arg5) where Arg4objectSuperK : K where Arg4objectSuperV : V { if (arg4 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; var top = _topology.AddSink(arg0, arg1, arg2.KafkaSerializer, arg3.KafkaSerializer, arg4, arg5.ToJVMArray()); @@ -134,13 +134,13 @@ public Topology AddSink(string arg0, TopicNameExtractor arg1, params /// /// /// - /// - /// + /// + /// /// /// /// /// - public Topology AddSink(string arg0, TopicNameExtractor arg1, ISerializer arg2, ISerializer arg3, params string[] arg4) + public Topology AddSink(string arg0, TopicNameExtractor arg1, ISerializer arg2, ISerializer arg3, params string[] arg4) { if (arg1 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; var top = _topology.AddSink(arg0, arg1, arg2.KafkaSerializer, arg3.KafkaSerializer, arg4.ToJVMArray()); @@ -151,8 +151,8 @@ public Topology AddSink(string arg0, TopicNameExtractor arg1, ISeria /// /// /// - /// - /// + /// + /// /// /// /// @@ -160,7 +160,7 @@ public Topology AddSink(string arg0, TopicNameExtractor arg1, ISeria /// /// /// - public Topology AddSink(string arg0, TopicNameExtractor arg1, ISerializer arg2, ISerializer arg3, StreamPartitioner arg4, params string[] arg5) where Arg4objectSuperK : K where Arg4objectSuperV : V + public Topology AddSink(string arg0, TopicNameExtractor arg1, ISerializer arg2, ISerializer arg3, StreamPartitioner arg4, params string[] arg5) where Arg4objectSuperK : K where Arg4objectSuperV : V { if (arg1 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; var top = _topology.AddSink(arg0, arg1, arg2.KafkaSerializer, arg3.KafkaSerializer, arg4, arg5.ToJVMArray()); @@ -223,11 +223,11 @@ public Topology AddSource(string arg0, Java.Util.Regex.Pattern arg1) /// /// /// - /// - /// + /// + /// /// /// - public Topology AddSource(string arg0, IDeserializer arg1, IDeserializer arg2, params string[] arg3) + public Topology AddSource(string arg0, IDeserializer arg1, IDeserializer arg2, params string[] arg3) { var top = (arg3.Length == 0) ? _topology.IExecute("addSource", arg0, arg1.KafkaDeserializer, arg2.KafkaDeserializer) : _topology.IExecute("addSource", arg0, arg1.KafkaDeserializer, arg2.KafkaDeserializer, arg3); return new Topology(top, _factory); @@ -236,11 +236,11 @@ public Topology AddSource(string arg0, IDeserializer arg1, IDeserializer /// /// /// - /// - /// + /// + /// /// /// - public Topology AddSource(string arg0, IDeserializer arg1, IDeserializer arg2, Java.Util.Regex.Pattern arg3) + public Topology AddSource(string arg0, IDeserializer arg1, IDeserializer arg2, Java.Util.Regex.Pattern arg3) { var top = _topology.IExecute("addSource", arg0, arg1.KafkaDeserializer, arg2.KafkaDeserializer, arg3); return new Topology(top, _factory); @@ -300,11 +300,11 @@ public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0 /// /// /// - /// - /// + /// + /// /// /// - public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0, string arg1, IDeserializer arg2, IDeserializer arg3, params string[] arg4) + public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0, string arg1, IDeserializer arg2, IDeserializer arg3, params string[] arg4) { var top = (arg4.Length == 0) ? _topology.IExecute("addSource", arg0, arg1, arg2.KafkaDeserializer, arg3.KafkaDeserializer) : _topology.IExecute("addSource", arg0, arg1, arg2.KafkaDeserializer, arg3.KafkaDeserializer, arg4); return new Topology(top, _factory); @@ -314,11 +314,11 @@ public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0 /// /// /// - /// - /// + /// + /// /// /// - public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0, string arg1, IDeserializer arg2, IDeserializer arg3, Java.Util.Regex.Pattern arg4) + public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0, string arg1, IDeserializer arg2, IDeserializer arg3, Java.Util.Regex.Pattern arg4) { var top = _topology.IExecute("addSource", arg0, arg1, arg2.KafkaDeserializer, arg3.KafkaDeserializer, arg4); return new Topology(top, _factory); @@ -329,11 +329,11 @@ public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0 /// /// /// - /// - /// + /// + /// /// /// - public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0, string arg1, Org.Apache.Kafka.Streams.Processor.TimestampExtractor arg2, IDeserializer arg3, IDeserializer arg4, params string[] arg5) + public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0, string arg1, Org.Apache.Kafka.Streams.Processor.TimestampExtractor arg2, IDeserializer arg3, IDeserializer arg4, params string[] arg5) { if (arg2 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; var top = (arg5.Length == 0) ? _topology.IExecute("addSource", arg0, arg1, arg2, arg3.KafkaDeserializer, arg4.KafkaDeserializer) : _topology.IExecute("addSource", arg0, arg1, arg2, arg3.KafkaDeserializer, arg4.KafkaDeserializer, arg5); @@ -345,11 +345,11 @@ public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0 /// /// /// - /// - /// + /// + /// /// /// - public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0, string arg1, Org.Apache.Kafka.Streams.Processor.TimestampExtractor arg2, IDeserializer arg3, IDeserializer arg4, Java.Util.Regex.Pattern arg5) + public Topology AddSource(Org.Apache.Kafka.Streams.Topology.AutoOffsetReset arg0, string arg1, Org.Apache.Kafka.Streams.Processor.TimestampExtractor arg2, IDeserializer arg3, IDeserializer arg4, Java.Util.Regex.Pattern arg5) { if (arg2 is IGenericSerDesFactoryApplier applier) applier.Factory = _factory; var top = _topology.IExecute("addSource", arg0, arg1, arg2, arg3.KafkaDeserializer, arg4.KafkaDeserializer, arg5); diff --git a/src/net/KNet/Specific/Streams/Utils/Function.cs b/src/net/KNet/Specific/Streams/Utils/Function.cs index aa3d0639f3..2966c8bee9 100644 --- a/src/net/KNet/Specific/Streams/Utils/Function.cs +++ b/src/net/KNet/Specific/Streams/Utils/Function.cs @@ -51,8 +51,8 @@ public class Function : Java.Util.Function.FunctionThe value type public class Function : Function { - ISerDes _keySerializer = null; - ISerDes _valueSerializer = null; + ISerDes _keySerializer = null; + ISerDes _valueSerializer = null; /// /// The to be executed /// @@ -66,8 +66,8 @@ public override byte[] Apply(byte[] arg0) { throw new InvalidOperationException("The serialization factory instance was not set."); } - _keySerializer ??= factory?.BuildKeySerDes(); - _valueSerializer ??= factory?.BuildValueSerDes(); + _keySerializer ??= factory?.BuildKeySerDes(); + _valueSerializer ??= factory?.BuildValueSerDes(); var methodToExecute = (OnApply != null) ? OnApply : Apply; var res = methodToExecute(_valueSerializer.Deserialize(null, arg0)); diff --git a/src/net/KNet/Specific/Streams/Utils/KStreamConsumer.cs b/src/net/KNet/Specific/Streams/Utils/KStreamConsumer.cs index a10c19d361..fce1dcfc62 100644 --- a/src/net/KNet/Specific/Streams/Utils/KStreamConsumer.cs +++ b/src/net/KNet/Specific/Streams/Utils/KStreamConsumer.cs @@ -31,7 +31,6 @@ namespace MASES.KNet.Streams.Utils /// The JVM value type public class KStreamConsumer : Java.Util.Function.Consumer>, IGenericSerDesFactoryApplier { - ISerDes _valueSerializer = null; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } diff --git a/src/net/KNet/Specific/Streams/WindowedKeyValue.cs b/src/net/KNet/Specific/Streams/WindowedKeyValue.cs index e1b4066593..6387d18dc4 100644 --- a/src/net/KNet/Specific/Streams/WindowedKeyValue.cs +++ b/src/net/KNet/Specific/Streams/WindowedKeyValue.cs @@ -24,21 +24,23 @@ namespace MASES.KNet.Streams /// /// KNet implementation of where the key is /// - /// The key type - /// The value type - public sealed class WindowedKeyValue : IGenericSerDesFactoryApplier + /// The key type + /// The value type + /// The JVM type of + /// The JVM type of + public sealed class WindowedKeyValue : IGenericSerDesFactoryApplier { - readonly Org.Apache.Kafka.Streams.KeyValue, byte[]> _valueInner; - Windowed _key = null; - TValue _value; + readonly Org.Apache.Kafka.Streams.KeyValue, TJVMV> _valueInner; + Windowed _key = null; + V _value; bool _valueStored; - ISerDes _valueSerDes = null; + ISerDes _valueSerDes = null; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } internal WindowedKeyValue(IGenericSerDesFactory factory, - Org.Apache.Kafka.Streams.KeyValue, byte[]> value, - ISerDes valueSerDes, + Org.Apache.Kafka.Streams.KeyValue, TJVMV> value, + ISerDes valueSerDes, bool fromPrefetched) { _factory = factory; @@ -46,7 +48,7 @@ internal WindowedKeyValue(IGenericSerDesFactory factory, _valueSerDes = valueSerDes; if (fromPrefetched) { - _valueSerDes ??= _factory?.BuildValueSerDes(); + _valueSerDes ??= _factory?.BuildValueSerDes(); _value = _valueSerDes.Deserialize(null, _valueInner.value); _valueStored = true; } @@ -55,24 +57,24 @@ internal WindowedKeyValue(IGenericSerDesFactory factory, /// /// KNet implementation of /// - public Windowed Key + public Windowed Key { get { - _key ??= new Windowed(_factory, _valueInner.key); + _key ??= new Windowed(_factory, _valueInner.key); return _key; } } /// /// KNet implementation of /// - public TValue Value + public V Value { get { if (!_valueStored) { - _valueSerDes ??= _factory?.BuildValueSerDes(); + _valueSerDes ??= _factory?.BuildValueSerDes(); var kk = _valueInner.value; _value = _valueSerDes.Deserialize(null, kk); _valueStored = true; From 77fcf439ce15493cfa3206cc33b403551728e225 Mon Sep 17 00:00:00 2001 From: masesdevelopers <94312179+masesdevelopers@users.noreply.github.com> Date: Sun, 12 May 2024 02:32:24 +0200 Subject: [PATCH 2/6] Added some other JVM class on many other classes --- .../KNet/Specific/Consumer/ConsumerRecord.cs | 32 +- .../KNet/Specific/Consumer/ConsumerRecords.cs | 48 +- .../Consumer/ConsumerRecordsEnumerator.cs | 20 +- .../ConsumerRecordsPrefetchableEnumerator.cs | 16 +- .../KNet/Specific/Consumer/KNetConsumer.cs | 250 +++++++++-- .../Specific/Consumer/KNetConsumerCallback.cs | 22 +- src/net/KNet/Specific/GenericConfigBuilder.cs | 82 ++-- .../KNet/Specific/Producer/KNetProducer.cs | 385 ++++++++++++---- .../KNet/Specific/Producer/ProducerRecord.cs | 135 +++++- .../Replicator/KNetCompactedReplicator.cs | 419 ++++++++++-------- .../Specific/Serialization/IDeserializer.cs | 31 +- .../Serialization/IGenericSerDesFactory.cs | 31 +- .../Specific/Serialization/ISerializer.cs | 29 +- .../Serialization/KNetSerialization.cs | 158 ++++--- 14 files changed, 1104 insertions(+), 554 deletions(-) diff --git a/src/net/KNet/Specific/Consumer/ConsumerRecord.cs b/src/net/KNet/Specific/Consumer/ConsumerRecord.cs index a6982ee046..246a7ec466 100644 --- a/src/net/KNet/Specific/Consumer/ConsumerRecord.cs +++ b/src/net/KNet/Specific/Consumer/ConsumerRecord.cs @@ -21,25 +21,27 @@ namespace MASES.KNet.Consumer { /// - /// KNet extension of + /// KNet extension of /// /// The key type /// The value type - public class ConsumerRecord: IGenericSerDesFactoryApplier + /// The JVM type of + /// The JVM type of + public class ConsumerRecord: IGenericSerDesFactoryApplier { - IDeserializer _keyDeserializer; - IDeserializer _valueDeserializer; - readonly Org.Apache.Kafka.Clients.Consumer.ConsumerRecord _record; + IDeserializer _keyDeserializer; + IDeserializer _valueDeserializer; + readonly Org.Apache.Kafka.Clients.Consumer.ConsumerRecord _record; IGenericSerDesFactory _factory; IGenericSerDesFactory IGenericSerDesFactoryApplier.Factory { get => _factory; set { _factory = value; } } /// - /// Initialize a new + /// Initialize a new /// - /// The to use for initialization - /// Key serializer base on - /// Value serializer base on + /// The to use for initialization + /// Key serializer base on + /// Value serializer base on /// True if the initialization comes from the prefetch iterator - internal ConsumerRecord(Org.Apache.Kafka.Clients.Consumer.ConsumerRecord record, IDeserializer keyDeserializer, IDeserializer valueDeserializer, bool fromPrefetched) + internal ConsumerRecord(Org.Apache.Kafka.Clients.Consumer.ConsumerRecord record, IDeserializer keyDeserializer, IDeserializer valueDeserializer, bool fromPrefetched) { _record = record; _keyDeserializer = keyDeserializer; @@ -52,11 +54,11 @@ internal ConsumerRecord(Org.Apache.Kafka.Clients.Consumer.ConsumerRecord - /// Initialize a new + /// Initialize a new /// - /// The to use for initialization + /// The to use for initialization /// - internal ConsumerRecord(Org.Apache.Kafka.Clients.Consumer.ConsumerRecord record, IGenericSerDesFactory factory) + internal ConsumerRecord(Org.Apache.Kafka.Clients.Consumer.ConsumerRecord record, IGenericSerDesFactory factory) { _record = record; _factory = factory; @@ -100,7 +102,7 @@ public K Key { if (!_localKeyDes) { - _keyDeserializer ??= _factory?.BuildKeySerDes(); + _keyDeserializer ??= _factory?.BuildKeySerDes(); _localKey = _keyDeserializer.UseHeaders ? _keyDeserializer.DeserializeWithHeaders(Topic, Headers, _record.Key()) : _keyDeserializer.Deserialize(Topic, _record.Key()); _localKeyDes = true; } @@ -117,7 +119,7 @@ public V Value { if (!_localValueDes) { - _valueDeserializer ??= _factory?.BuildKeySerDes(); + _valueDeserializer ??= _factory?.BuildKeySerDes(); _localValue = _valueDeserializer.UseHeaders ? _valueDeserializer.DeserializeWithHeaders(Topic, Headers, _record.Value()) : _valueDeserializer.Deserialize(Topic, _record.Value()); _localValueDes = true; } diff --git a/src/net/KNet/Specific/Consumer/ConsumerRecords.cs b/src/net/KNet/Specific/Consumer/ConsumerRecords.cs index 8b7eb3b20d..539ac2d88e 100644 --- a/src/net/KNet/Specific/Consumer/ConsumerRecords.cs +++ b/src/net/KNet/Specific/Consumer/ConsumerRecords.cs @@ -24,22 +24,24 @@ namespace MASES.KNet.Consumer { /// - /// KNet extension of + /// KNet extension of /// /// The key type /// The value type - public class ConsumerRecords : IEnumerable>, IAsyncEnumerable> + /// The JVM type of + /// The JVM type of + public class ConsumerRecords : IEnumerable>, IAsyncEnumerable> { - readonly ISerDes _keyDeserializer; - readonly ISerDes _valueDeserializer; - readonly Org.Apache.Kafka.Clients.Consumer.ConsumerRecords _records; + readonly ISerDes _keyDeserializer; + readonly ISerDes _valueDeserializer; + readonly Org.Apache.Kafka.Clients.Consumer.ConsumerRecords _records; /// - /// Initialize a new + /// Initialize a new /// /// The to use for initialization - /// Key serializer base on - /// Value serializer base on - internal ConsumerRecords(Org.Apache.Kafka.Clients.Consumer.ConsumerRecords records, ISerDes keyDeserializer, ISerDes valueDeserializer) + /// Key serializer base on + /// Value serializer base on + internal ConsumerRecords(Org.Apache.Kafka.Clients.Consumer.ConsumerRecords records, ISerDes keyDeserializer, ISerDes valueDeserializer) { _records = records; _keyDeserializer = keyDeserializer; @@ -47,33 +49,33 @@ internal ConsumerRecords(Org.Apache.Kafka.Clients.Consumer.ConsumerRecords - /// if enumeration will use prefetch and the number of records is more than , i.e. the preparation of happens in an external thread + /// if enumeration will use prefetch and the number of records is more than , i.e. the preparation of happens in an external thread /// /// It is by default if one of or are not , override the value using public bool IsPrefecth { get; private set; } = !(typeof(K).IsValueType && typeof(V).IsValueType); /// - /// The minimum threshold to activate pretech, i.e. the preparation of happens in external thread if contains more than elements + /// The minimum threshold to activate pretech, i.e. the preparation of happens in external thread if contains more than elements /// /// The default value is 10, however it shall be chosen by the developer and in the decision shall be verified if external thread activation costs more than inline execution public int PrefetchThreshold { get; private set; } = 10; #endif /// - /// if the is empty + /// if the is empty /// public bool IsEmpty => _records.IsEmpty(); /// - /// The number of elements in + /// The number of elements in /// public int Count => _records.Count(); #if NET7_0_OR_GREATER /// - /// Set to to enable enumeration with prefetch over threshold, i.e. preparation of in external thread + /// Set to to enable enumeration with prefetch over threshold, i.e. preparation of in external thread /// /// to enable prefetch. See /// The minimum threshold to activate pretech, default is 10. See /// This instance with and set /// Setting to a value less, or equal, to 0 and to , the prefetch is always actived - public ConsumerRecords ApplyPrefetch(bool enablePrefetch = true, int prefetchThreshold = 10) + public ConsumerRecords ApplyPrefetch(bool enablePrefetch = true, int prefetchThreshold = 10) { IsPrefecth = enablePrefetch; PrefetchThreshold = IsPrefecth ? prefetchThreshold : -1; @@ -86,34 +88,34 @@ bool UsePrefetch() (PrefetchThreshold <= 0 || _records.Count() > PrefetchThreshold); } #endif - IEnumerator> IEnumerable>.GetEnumerator() + IEnumerator> IEnumerable>.GetEnumerator() { #if NET7_0_OR_GREATER if (UsePrefetch()) - return new ConsumerRecordsPrefetchableEnumerator(_records.Iterator(), _keyDeserializer, _valueDeserializer, false); + return new ConsumerRecordsPrefetchableEnumerator(_records.Iterator(), _keyDeserializer, _valueDeserializer, false); else #endif - return new ConsumerRecordsEnumerator(_records, _keyDeserializer, _valueDeserializer); + return new ConsumerRecordsEnumerator(_records, _keyDeserializer, _valueDeserializer); } System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() { #if NET7_0_OR_GREATER if (UsePrefetch()) - return new ConsumerRecordsPrefetchableEnumerator(_records.Iterator(), _keyDeserializer, _valueDeserializer, false); + return new ConsumerRecordsPrefetchableEnumerator(_records.Iterator(), _keyDeserializer, _valueDeserializer, false); else #endif - return new ConsumerRecordsEnumerator(_records, _keyDeserializer, _valueDeserializer); + return new ConsumerRecordsEnumerator(_records, _keyDeserializer, _valueDeserializer); } - IAsyncEnumerator> IAsyncEnumerable>.GetAsyncEnumerator(CancellationToken cancellationToken) + IAsyncEnumerator> IAsyncEnumerable>.GetAsyncEnumerator(CancellationToken cancellationToken) { #if NET7_0_OR_GREATER if (UsePrefetch()) - return new ConsumerRecordsPrefetchableEnumerator(_records.Iterator(), _keyDeserializer, _valueDeserializer, true, cancellationToken); + return new ConsumerRecordsPrefetchableEnumerator(_records.Iterator(), _keyDeserializer, _valueDeserializer, true, cancellationToken); else #endif - return new ConsumerRecordsEnumerator(_records, _keyDeserializer, _valueDeserializer, cancellationToken); + return new ConsumerRecordsEnumerator(_records, _keyDeserializer, _valueDeserializer, cancellationToken); } } } diff --git a/src/net/KNet/Specific/Consumer/ConsumerRecordsEnumerator.cs b/src/net/KNet/Specific/Consumer/ConsumerRecordsEnumerator.cs index f01fde5148..21c4e239d4 100644 --- a/src/net/KNet/Specific/Consumer/ConsumerRecordsEnumerator.cs +++ b/src/net/KNet/Specific/Consumer/ConsumerRecordsEnumerator.cs @@ -23,16 +23,16 @@ namespace MASES.KNet.Consumer { - class ConsumerRecordsEnumerator : IEnumerator>, IAsyncEnumerator> + class ConsumerRecordsEnumerator : IEnumerator>, IAsyncEnumerator> { - readonly IDeserializer _keyDeserializer; - readonly IDeserializer _valueDeserializer; + readonly IDeserializer _keyDeserializer; + readonly IDeserializer _valueDeserializer; readonly CancellationToken _cancellationToken; - readonly Org.Apache.Kafka.Clients.Consumer.ConsumerRecords _records; - IEnumerator> _recordEnumerator; - IAsyncEnumerator> _recordAsyncEnumerator; + readonly Org.Apache.Kafka.Clients.Consumer.ConsumerRecords _records; + IEnumerator> _recordEnumerator; + IAsyncEnumerator> _recordAsyncEnumerator; - public ConsumerRecordsEnumerator(Org.Apache.Kafka.Clients.Consumer.ConsumerRecords records, IDeserializer keyDeserializer, IDeserializer valueDeserializer) + public ConsumerRecordsEnumerator(Org.Apache.Kafka.Clients.Consumer.ConsumerRecords records, IDeserializer keyDeserializer, IDeserializer valueDeserializer) { _records = records; _recordEnumerator = _records.GetEnumerator(); @@ -40,7 +40,7 @@ public ConsumerRecordsEnumerator(Org.Apache.Kafka.Clients.Consumer.ConsumerRecor _valueDeserializer = valueDeserializer; } - public ConsumerRecordsEnumerator(Org.Apache.Kafka.Clients.Consumer.ConsumerRecords records, IDeserializer keyDeserializer, IDeserializer valueDeserializer, CancellationToken cancellationToken) + public ConsumerRecordsEnumerator(Org.Apache.Kafka.Clients.Consumer.ConsumerRecords records, IDeserializer keyDeserializer, IDeserializer valueDeserializer, CancellationToken cancellationToken) { _records = records; _recordAsyncEnumerator = _records.GetAsyncEnumerator(cancellationToken); @@ -49,9 +49,9 @@ public ConsumerRecordsEnumerator(Org.Apache.Kafka.Clients.Consumer.ConsumerRecor _cancellationToken = cancellationToken; } - ConsumerRecord IAsyncEnumerator>.Current => new ConsumerRecord(_recordAsyncEnumerator.Current, _keyDeserializer, _valueDeserializer, false); + ConsumerRecord IAsyncEnumerator>.Current => new ConsumerRecord(_recordAsyncEnumerator.Current, _keyDeserializer, _valueDeserializer, false); - ConsumerRecord IEnumerator>.Current => new ConsumerRecord(_recordEnumerator.Current, _keyDeserializer, _valueDeserializer, false); + ConsumerRecord IEnumerator>.Current => new ConsumerRecord(_recordEnumerator.Current, _keyDeserializer, _valueDeserializer, false); object System.Collections.IEnumerator.Current => (_recordEnumerator as System.Collections.IEnumerator)?.Current; diff --git a/src/net/KNet/Specific/Consumer/ConsumerRecordsPrefetchableEnumerator.cs b/src/net/KNet/Specific/Consumer/ConsumerRecordsPrefetchableEnumerator.cs index 9a0b2c9512..9b66016a20 100644 --- a/src/net/KNet/Specific/Consumer/ConsumerRecordsPrefetchableEnumerator.cs +++ b/src/net/KNet/Specific/Consumer/ConsumerRecordsPrefetchableEnumerator.cs @@ -27,20 +27,20 @@ namespace MASES.KNet.Consumer { #if NET7_0_OR_GREATER - sealed class ConsumerRecordsPrefetchableEnumerator(Java.Util.Iterator> records, - ISerDes keySerDes, - ISerDes valueSerDes, + sealed class ConsumerRecordsPrefetchableEnumerator(Java.Util.Iterator> records, + ISerDes keySerDes, + ISerDes valueSerDes, bool isAsync, CancellationToken token = default) - : JVMBridgeBasePrefetchableEnumerator>(records.BridgeInstance, new PrefetchableEnumeratorSettings()), - IAsyncEnumerator> + : JVMBridgeBasePrefetchableEnumerator>(records.BridgeInstance, new PrefetchableEnumeratorSettings()), + IAsyncEnumerator> { - Java.Util.Iterator> _records = records; // used to do not lost reference + Java.Util.Iterator> _records = records; // used to do not lost reference protected override object ConvertObject(object input) { if (input is IJavaObject obj) { - return new ConsumerRecord(JVMBridgeBase.Wraps>(obj), keySerDes, valueSerDes, true); + return new ConsumerRecord(JVMBridgeBase.WrapsDirect>(obj), keySerDes, valueSerDes, true); } throw new InvalidCastException($"input is not a valid IJavaObject"); } @@ -50,7 +50,7 @@ protected override bool DoWorkCycle() return isAsync ? !token.IsCancellationRequested : base.DoWorkCycle(); } - public ConsumerRecord Current => (this as IEnumerator>).Current; + public ConsumerRecord Current => (this as IEnumerator>).Current; public ValueTask MoveNextAsync() { diff --git a/src/net/KNet/Specific/Consumer/KNetConsumer.cs b/src/net/KNet/Specific/Consumer/KNetConsumer.cs index 3f87cd39ea..d00a2b6744 100644 --- a/src/net/KNet/Specific/Consumer/KNetConsumer.cs +++ b/src/net/KNet/Specific/Consumer/KNetConsumer.cs @@ -25,40 +25,44 @@ namespace MASES.KNet.Consumer { + #region IConsumer + /// /// KNet extension of /// /// The key type /// The value type - public interface IConsumer : Org.Apache.Kafka.Clients.Consumer.IConsumer + /// The JVM type of + /// The JVM type of + public interface IConsumer : Org.Apache.Kafka.Clients.Consumer.IConsumer { #if NET7_0_OR_GREATER /// - /// if enumeration will use prefetch and the number of records is more than , i.e. the preparation of happens in an external thread + /// if enumeration will use prefetch and the number of records is more than , i.e. the preparation of happens in an external thread /// /// It is by default if one of or are not , override the value using bool IsPrefecth { get; } /// - /// The minimum threshold to activate pretech, i.e. the preparation of happens in external thread if contains more than elements + /// The minimum threshold to activate pretech, i.e. the preparation of happens in external thread if contains more than elements /// /// The default value is 10, however it shall be chosen by the developer and in the decision shall be verified if external thread activation costs more than inline execution int PrefetchThreshold { get; } #endif /// - /// if the instance is completing async operation + /// if the instance is completing async operation /// bool IsCompleting { get; } /// - /// if the instance has an empty set of items in async operation + /// if the instance has an empty set of items in async operation /// bool IsEmpty { get; } /// - /// Number of messages in the instance waiting to be processed in async operation + /// Number of messages in the instance waiting to be processed in async operation /// int WaitingMessages { get; } #if NET7_0_OR_GREATER /// - /// Set to to enable enumeration with prefetch over threshold, i.e. preparation of in external thread + /// Set to to enable enumeration with prefetch over threshold, i.e. preparation of in external thread /// /// to enable prefetch. See /// The minimum threshold to activate pretech, default is 10. See @@ -66,22 +70,22 @@ public interface IConsumer : Org.Apache.Kafka.Clients.Consumer.IConsumer - /// Sets the to use to receive + /// Sets the to use to receive /// /// The callback - void SetCallback(Action> cb); + void SetCallback(Action> cb); /// /// KNet extension for /// /// Timeout in milliseconds - /// - ConsumerRecords Poll(long timeoutMs); + /// + ConsumerRecords Poll(long timeoutMs); /// /// KNet extension for /// /// Timeout expressed as - /// - ConsumerRecords Poll(TimeSpan timeout); + /// + ConsumerRecords Poll(TimeSpan timeout); /// /// KNet async extension for /// @@ -92,24 +96,31 @@ public interface IConsumer : Org.Apache.Kafka.Clients.Consumer.IConsumer /// /// Timeout in milliseconds - /// The where receives - void Consume(long timeoutMs, Action> callback); + /// The where receives + void Consume(long timeoutMs, Action> callback); } + + #endregion + + #region KNetConsumer + /// /// KNet extension of /// /// The key type /// The value type - public class KNetConsumer : Org.Apache.Kafka.Clients.Consumer.KafkaConsumer, IConsumer + /// The JVM type of + /// The JVM type of + public class KNetConsumer : Org.Apache.Kafka.Clients.Consumer.KafkaConsumer, IConsumer { readonly bool _autoCreateSerDes = false; bool _threadRunning = false; long _dequeing = 0; readonly System.Threading.Thread _consumeThread = null; - readonly ConcurrentQueue> _consumedRecords = null; - readonly KNetConsumerCallback _consumerCallback = null; - readonly ISerDes _keyDeserializer; - readonly ISerDes _valueDeserializer; + readonly ConcurrentQueue> _consumedRecords = null; + readonly KNetConsumerCallback _consumerCallback = null; + readonly ISerDes _keyDeserializer; + readonly ISerDes _valueDeserializer; /// /// /// @@ -118,22 +129,22 @@ public class KNetConsumer : Org.Apache.Kafka.Clients.Consumer.KafkaConsume internal KNetConsumer(Properties props) : base(props) { } /// - /// Initialize a new instance of + /// Initialize a new instance of /// /// An instance of /// to active callback based mode public KNetConsumer(ConsumerConfigBuilder configBuilder, bool useJVMCallback = false) - : this(configBuilder, configBuilder.BuildKeySerDes(), configBuilder.BuildValueSerDes(), useJVMCallback) + : this(configBuilder, configBuilder.BuildKeySerDes(), configBuilder.BuildValueSerDes(), useJVMCallback) { } /// - /// Initialize a new instance of + /// Initialize a new instance of /// /// The properties to use, see - /// Key serializer base on - /// Value serializer base on + /// Key serializer base on + /// Value serializer base on /// to active callback based mode - public KNetConsumer(ConsumerConfigBuilder props, ISerDes keyDeserializer, ISerDes valueDeserializer, bool useJVMCallback = false) + public KNetConsumer(ConsumerConfigBuilder props, ISerDes keyDeserializer, ISerDes valueDeserializer, bool useJVMCallback = false) : base(CheckProperties(props), keyDeserializer.KafkaDeserializer, valueDeserializer.KafkaDeserializer) { _keyDeserializer = keyDeserializer; @@ -141,7 +152,7 @@ public KNetConsumer(ConsumerConfigBuilder props, ISerDes keyDeserializer, ISe if (useJVMCallback) { - _consumerCallback = new KNetConsumerCallback(CallbackMessage, _keyDeserializer, _valueDeserializer); + _consumerCallback = new KNetConsumerCallback(CallbackMessage, _keyDeserializer, _valueDeserializer); IExecute("setCallback", _consumerCallback); } else @@ -157,13 +168,27 @@ static Properties CheckProperties(Properties props) { if (!props.ContainsKey(Org.Apache.Kafka.Clients.Consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG)) { - props.Put(Org.Apache.Kafka.Clients.Consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer"); + if (typeof(TJVMK) == typeof(byte[])) + { + props.Put(Org.Apache.Kafka.Clients.Consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer"); + } + else + { + props.Put(Org.Apache.Kafka.Clients.Consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG, "org.mases.knet.common.serialization.ByteBufferDeserializer"); + } } else throw new InvalidOperationException($"KNetConsumer auto manages configuration property {Org.Apache.Kafka.Clients.Consumer.ConsumerConfig.KEY_DESERIALIZER_CLASS_CONFIG}, remove from configuration."); if (!props.ContainsKey(Org.Apache.Kafka.Clients.Consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG)) { - props.Put(Org.Apache.Kafka.Clients.Consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer"); + if (typeof(TJVMV) == typeof(byte[])) + { + props.Put(Org.Apache.Kafka.Clients.Consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArrayDeserializer"); + } + else + { + props.Put(Org.Apache.Kafka.Clients.Consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG, "org.mases.knet.common.serialization.ByteBufferDeserializer"); + } } else throw new InvalidOperationException($"KNetConsumer auto manages configuration property {Org.Apache.Kafka.Clients.Consumer.ConsumerConfig.VALUE_DESERIALIZER_CLASS_CONFIG}, remove from configuration."); @@ -177,27 +202,27 @@ static Properties CheckProperties(Properties props) this.Dispose(); } - /// - public new ConsumerRecords Poll(long timeoutMs) + /// + public new ConsumerRecords Poll(long timeoutMs) { var records = base.Poll(timeoutMs); - return new ConsumerRecords(records, _keyDeserializer, _valueDeserializer); + return new ConsumerRecords(records, _keyDeserializer, _valueDeserializer); } - /// - public ConsumerRecords Poll(TimeSpan timeout) + /// + public ConsumerRecords Poll(TimeSpan timeout) { Duration duration = timeout; try { var records = base.Poll(duration); - return new ConsumerRecords(records, _keyDeserializer, _valueDeserializer); + return new ConsumerRecords(records, _keyDeserializer, _valueDeserializer); } finally { duration?.Dispose(); } } - Action> actionCallback = null; + Action> actionCallback = null; - void CallbackMessage(ConsumerRecord message) + void CallbackMessage(ConsumerRecord message) { actionCallback?.Invoke(message); } @@ -227,15 +252,15 @@ public override void Dispose() base.Dispose(); } #if NET7_0_OR_GREATER - /// + /// public void ApplyPrefetch(bool enablePrefetch = true, int prefetchThreshold = 10) { IsPrefecth = enablePrefetch; PrefetchThreshold = IsPrefecth ? prefetchThreshold : 10; } #endif - /// - public void SetCallback(Action> cb) + /// + public void SetCallback(Action> cb) { actionCallback = cb; } @@ -246,7 +271,7 @@ void ConsumeHandler(object o) { while (_threadRunning) { - if (_consumedRecords.TryDequeue(out ConsumerRecords records)) + if (_consumedRecords.TryDequeue(out ConsumerRecords records)) { System.Threading.Interlocked.Increment(ref _dequeing); try @@ -274,18 +299,18 @@ void ConsumeHandler(object o) catch { } } #if NET7_0_OR_GREATER - /// + /// public bool IsPrefecth { get; private set; } = !(typeof(K).IsValueType && typeof(V).IsValueType); - /// + /// public int PrefetchThreshold { get; private set; } = 10; #endif - /// + /// public bool IsCompleting => !_consumedRecords.IsEmpty || System.Threading.Interlocked.Read(ref _dequeing) != 0; - /// + /// public bool IsEmpty => _consumedRecords.IsEmpty; - /// + /// public int WaitingMessages => _consumedRecords.Count; - /// + /// public bool ConsumeAsync(long timeoutMs) { if (_consumedRecords == null) throw new ArgumentException("Cannot be used since constructor was called with useJVMCallback set to true."); @@ -306,8 +331,8 @@ public bool ConsumeAsync(long timeoutMs) } return !isEmpty; } - /// - public void Consume(long timeoutMs, Action> callback) + /// + public void Consume(long timeoutMs, Action> callback) { Duration duration = TimeSpan.FromMilliseconds(timeoutMs); if (_consumerCallback == null) throw new ArgumentException("Cannot be used since constructor was called with useJVMCallback set to false."); @@ -323,4 +348,131 @@ public void Consume(long timeoutMs, Action> callback) } } } + + #endregion + + #region KNetConsumer + /// + /// Extends using array of + /// + /// The key type + /// The value type + public class KNetConsumer : KNetConsumer + { + /// + /// Initialize a new instance of + /// + /// An instance of + /// to active callback based mode + public KNetConsumer(ConsumerConfigBuilder configBuilder, bool useJVMCallback = false) + : base(configBuilder, useJVMCallback) + { + } + /// + /// Initialize a new instance of + /// + /// The properties to use, see + /// Key serializer base on + /// Value serializer base on + /// to active callback based mode + public KNetConsumer(ConsumerConfigBuilder props, ISerDes keyDeserializer, ISerDes valueDeserializer, bool useJVMCallback = false) + : base(props, keyDeserializer, valueDeserializer) + { + } + } + + #endregion + + #region KNetConsumerBuffered + /// + /// Extends using + /// + /// The key type + /// The value type + public class KNetConsumerBuffered : KNetConsumer + { + /// + /// Initialize a new instance of + /// + /// An instance of + /// to active callback based mode + public KNetConsumerBuffered(ConsumerConfigBuilder configBuilder, bool useJVMCallback = false) + : base(configBuilder, useJVMCallback) + { + } + /// + /// Initialize a new instance of + /// + /// The properties to use, see + /// Key serializer base on + /// Value serializer base on + /// to active callback based mode + public KNetConsumerBuffered(ConsumerConfigBuilder props, ISerDes keyDeserializer, ISerDes valueDeserializer, bool useJVMCallback = false) + : base(props, keyDeserializer, valueDeserializer) + { + } + } + #endregion + + #region KNetConsumerKeyBuffered + /// + /// Extends using for key + /// + /// The key type + /// The value type + public class KNetConsumerKeyBuffered : KNetConsumer + { + /// + /// Initialize a new instance of + /// + /// An instance of + /// to active callback based mode + public KNetConsumerKeyBuffered(ConsumerConfigBuilder configBuilder, bool useJVMCallback = false) + : base(configBuilder, useJVMCallback) + { + } + /// + /// Initialize a new instance of + /// + /// The properties to use, see + /// Key serializer base on + /// Value serializer base on + /// to active callback based mode + public KNetConsumerKeyBuffered(ConsumerConfigBuilder props, ISerDes keyDeserializer, ISerDes valueDeserializer, bool useJVMCallback = false) + : base(props, keyDeserializer, valueDeserializer) + { + } + } + #endregion + + #region KNetConsumerValueBuffered + /// + /// Extends using for value + /// + /// The key type + /// The value type + public class KNetConsumerValueBuffered : KNetConsumer + { + /// + /// Initialize a new instance of + /// + /// An instance of + /// to active callback based mode + public KNetConsumerValueBuffered(ConsumerConfigBuilder configBuilder, bool useJVMCallback = false) + : base(configBuilder, useJVMCallback) + { + } + /// + /// Initialize a new instance of + /// + /// The properties to use, see + /// Key serializer base on + /// Value serializer base on + /// to active callback based mode + public KNetConsumerValueBuffered(ConsumerConfigBuilder props, ISerDes keyDeserializer, ISerDes valueDeserializer, bool useJVMCallback = false) + : base(props, keyDeserializer, valueDeserializer) + { + } + } + #endregion } diff --git a/src/net/KNet/Specific/Consumer/KNetConsumerCallback.cs b/src/net/KNet/Specific/Consumer/KNetConsumerCallback.cs index 963bf152e9..360c6ebd68 100644 --- a/src/net/KNet/Specific/Consumer/KNetConsumerCallback.cs +++ b/src/net/KNet/Specific/Consumer/KNetConsumerCallback.cs @@ -23,23 +23,23 @@ namespace MASES.KNet.Consumer { - interface IKNetConsumerCallback : IJVMBridgeBase + interface IKNetConsumerCallback : IJVMBridgeBase { - void RecordReady(ConsumerRecord message); + void RecordReady(ConsumerRecord message); } - class KNetConsumerCallback : JVMBridgeListener, IKNetConsumerCallback + class KNetConsumerCallback : JVMBridgeListener, IKNetConsumerCallback { - readonly IDeserializer _keyDeserializer; - readonly IDeserializer _valueDeserializer; + readonly IDeserializer _keyDeserializer; + readonly IDeserializer _valueDeserializer; /// /// /// public sealed override string BridgeClassName => "org.mases.knet.clients.consumer.KNetConsumerCallback"; - readonly Action> recordReadyFunction = null; - public virtual Action> OnRecordReady { get { return recordReadyFunction; } } - public KNetConsumerCallback(Action> recordReady, IDeserializer keyDeserializer, IDeserializer valueDeserializer) + readonly Action> recordReadyFunction = null; + public virtual Action> OnRecordReady { get { return recordReadyFunction; } } + public KNetConsumerCallback(Action> recordReady, IDeserializer keyDeserializer, IDeserializer valueDeserializer) { if (recordReady != null) recordReadyFunction = recordReady; else recordReadyFunction = RecordReady; @@ -52,10 +52,10 @@ public KNetConsumerCallback(Action> recordReady, IDeseriali void OnRecordReadyEventHandler(object sender, CLRListenerEventArgs data) { - var record = this.BridgeInstance.Invoke>("getRecord"); - recordReadyFunction(new ConsumerRecord(record, _keyDeserializer, _valueDeserializer, false)); + var record = this.BridgeInstance.Invoke>("getRecord"); + recordReadyFunction(new ConsumerRecord(record, _keyDeserializer, _valueDeserializer, false)); } - public virtual void RecordReady(ConsumerRecord message) { } + public virtual void RecordReady(ConsumerRecord message) { } } } diff --git a/src/net/KNet/Specific/GenericConfigBuilder.cs b/src/net/KNet/Specific/GenericConfigBuilder.cs index 3ba964f9f5..4c62a77717 100644 --- a/src/net/KNet/Specific/GenericConfigBuilder.cs +++ b/src/net/KNet/Specific/GenericConfigBuilder.cs @@ -146,6 +146,10 @@ public Properties ToProperties() return props; } + + /// + public bool AutoSelectBuffered { get; set; } + Type _KNetKeySerDes = null; /// public Type KNetKeySerDes @@ -163,7 +167,7 @@ public Type KNetKeySerDes var keyT = value.GetGenericArguments(); if (keyT.Length != 1) { throw new ArgumentException($"{value.Name} does not contains a single generic argument and cannot be used because it is not a valid Serializer type"); } var t = value.GetGenericTypeDefinition(); - if (t.GetInterface(typeof(ISerDes<>).Name) == null) + if (t.GetInterface(typeof(ISerDes<,>).Name) == null) { throw new ArgumentException($"{value.Name} does not implement IKNetSerDes<> and cannot be used because it is not a valid Serializer type"); } @@ -190,7 +194,7 @@ public Type KNetValueSerDes var keyT = value.GetGenericArguments(); if (keyT.Length != 1) { throw new ArgumentException($"{value.Name} does not contains a single generic argument and cannot be used because it is not a valid Serializer type"); } var t = value.GetGenericTypeDefinition(); - if (t.GetInterface(typeof(ISerDes<>).Name) == null) + if (t.GetInterface(typeof(ISerDes<,>).Name) == null) { throw new ArgumentException($"{value.Name} does not implement IKNetSerDes<> and cannot be used because it is not a valid Serializer type"); } @@ -211,7 +215,14 @@ public ISerDes BuildKeySerDes() { if (KNetSerialization.IsInternalManaged()) { - serDes = new SerDes(); + if (AutoSelectBuffered && typeof(TJVMTKey) == typeof(Java.Nio.ByteBuffer)) + { + serDes = new SerDesBuffered(); + } + else + { + serDes = new SerDes(); + } } else { @@ -225,30 +236,6 @@ public ISerDes BuildKeySerDes() } } - readonly ConcurrentDictionary _keySerDesSimple = new(); - - /// - public ISerDes BuildKeySerDes() - { - lock (_keySerDesSimple) - { - if (!_keySerDesSimple.TryGetValue(typeof(TKey), out object serDes)) - { - if (KNetSerialization.IsInternalManaged()) - { - serDes = new SerDes(); - } - else - { - if (KNetKeySerDes == null) throw new InvalidOperationException($"No default serializer available for {typeof(TKey)}, property {nameof(KNetKeySerDes)} shall be set."); - var tmp = KNetKeySerDes.MakeGenericType(typeof(TKey)); - serDes = Activator.CreateInstance(tmp); - } - _keySerDesSimple[typeof(TKey)] = serDes; - } - return serDes as ISerDes; - } - } readonly ConcurrentDictionary<(Type, Type), object> _valueSerDesComplete = new(); @@ -261,7 +248,14 @@ public ISerDes BuildValueSerDes() { if (KNetSerialization.IsInternalManaged()) { - serDes = new SerDes(); + if (AutoSelectBuffered && typeof(TJVMTValue) == typeof(Java.Nio.ByteBuffer)) + { + serDes = new SerDesBuffered(); + } + else + { + serDes = new SerDes(); + } } else { @@ -275,46 +269,22 @@ public ISerDes BuildValueSerDes() } } - readonly ConcurrentDictionary _valueSerDesSimple = new(); - - /// - public ISerDes BuildValueSerDes() - { - lock (_valueSerDesSimple) - { - if (!_valueSerDesSimple.TryGetValue(typeof(TValue), out object serDes)) - { - if (KNetSerialization.IsInternalManaged()) - { - serDes = new SerDes(); - } - else - { - if (KNetValueSerDes == null) throw new InvalidOperationException($"No default serializer available for {typeof(TValue)}, property {nameof(KNetValueSerDes)} shall be set."); - var tmp = KNetValueSerDes.MakeGenericType(typeof(TValue)); - serDes = Activator.CreateInstance(tmp); - } - _valueSerDesSimple[typeof(TValue)] = serDes; - } - return serDes as ISerDes; - } - } /// public void Clear() { - foreach (IDisposable item in _keySerDesSimple.Values.Cast()) + foreach (IDisposable item in _keySerDesComplete.Values.Cast()) { item?.Dispose(); } - _keySerDesSimple.Clear(); + _keySerDesComplete.Clear(); - foreach (IDisposable item in _valueSerDesSimple.Values.Cast()) + foreach (IDisposable item in _valueSerDesComplete.Values.Cast()) { item?.Dispose(); } - _valueSerDesSimple.Clear(); + _valueSerDesComplete.Clear(); } /// diff --git a/src/net/KNet/Specific/Producer/KNetProducer.cs b/src/net/KNet/Specific/Producer/KNetProducer.cs index 6378661b82..77149f9827 100644 --- a/src/net/KNet/Specific/Producer/KNetProducer.cs +++ b/src/net/KNet/Specific/Producer/KNetProducer.cs @@ -24,15 +24,20 @@ using MASES.JCOBridge.C2JBridge; using System.Threading.Tasks; using System; +using System.Collections.Concurrent; namespace MASES.KNet.Producer { + #region IProducer + /// - /// Extends adding less intrusive methods which performs better in high throughput applications + /// Extends adding less intrusive methods which performs better in high throughput applications /// - /// Same meaning of - /// Same meaning of - public interface IProducer : Org.Apache.Kafka.Clients.Producer.IProducer + /// Same meaning of + /// Same meaning of + /// The JVM type of + /// The JVM type of + public interface IProducer : Org.Apache.Kafka.Clients.Producer.IProducer { /// /// Set into instance of @@ -42,11 +47,11 @@ public interface IProducer : Org.Apache.Kafka.Clients.Producer.IProducer /// KNet version of /// - public Future Send(ProducerRecord record); + public Future Send(ProducerRecord record); /// /// KNet version of /// - public Future Send(ProducerRecord record, Callback callback); + public Future Send(ProducerRecord record, Callback callback); /// /// KNet version of /// @@ -90,7 +95,7 @@ public interface IProducer : Org.Apache.Kafka.Clients.Producer.IProducer /// KNet version of /// - void Produce(ProducerRecord record, Action action = null); + void Produce(ProducerRecord record, Action action = null); /// /// KNet version of /// @@ -126,11 +131,11 @@ public interface IProducer : Org.Apache.Kafka.Clients.Producer.IProducer /// KNet version of /// - Future Produce(ProducerRecord record, Callback cb = null); + Future Produce(ProducerRecord record, Callback cb = null); /// /// KNet version of /// - void ProduceAndWait(ProducerRecord record, Callback cb = null); + void ProduceAndWait(ProducerRecord record, Callback cb = null); /// /// KNet async version of /// @@ -150,15 +155,57 @@ public interface IProducer : Org.Apache.Kafka.Clients.Producer.IProducer /// KNet async version of /// - Task ProduceAsync(ProducerRecord record, Action action = null); + Task ProduceAsync(ProducerRecord record, Action action = null); + /// + /// Initialize a new + /// + public ProducerRecord NewRecord(); + /// + /// Initialize a new + /// + public ProducerRecord NewRecord(string topic, int partition, long timestamp, K key, V value, Headers headers); + /// + /// Initialize a new + /// + public ProducerRecord NewRecord(string topic, int partition, System.DateTime timestamp, K key, V value, Headers headers); + /// + /// Initialize a new + /// + public ProducerRecord NewRecord(string topic, int partition, long timestamp, K key, V value); + /// + /// Initialize a new + /// + public ProducerRecord NewRecord(string topic, int partition, System.DateTime timestamp, K key, V value); + /// + /// Initialize a new + /// + public ProducerRecord NewRecord(string topic, int partition, K key, V value, Headers headers); + /// + /// Initialize a new + /// + public ProducerRecord NewRecord(string topic, int partition, K key, V value); + /// + /// Initialize a new + /// + public ProducerRecord NewRecord(string topic, K key, V value); + /// + /// Initialize a new + /// + public ProducerRecord NewRecord(string topic, V value); } + #endregion + + #region KNetProducer + /// /// Extends adding less intrusive methods which performs better in high throughput applications /// /// Same meaning of /// Same meaning of - public class KNetProducer : KafkaProducer, IProducer + /// The JVM type of + /// The JVM type of + public class KNetProducer : KafkaProducer, IProducer { /// /// @@ -166,26 +213,26 @@ public class KNetProducer : KafkaProducer, IProducer public override string BridgeClassName => "org.mases.knet.clients.producer.KNetProducer"; readonly bool _autoCreateSerDes = false; - readonly ISerDes _keySerializer; - readonly ISerDes _valueSerializer; + readonly ISerDes _keySerializer; + readonly ISerDes _valueSerializer; internal KNetProducer(Properties props) : base(props) { } /// - /// Initialize a new instance of + /// Initialize a new instance of /// /// An instance of public KNetProducer(ProducerConfigBuilder configBuilder) - : this(configBuilder, configBuilder.BuildKeySerDes(), configBuilder.BuildValueSerDes()) + : this(configBuilder, configBuilder.BuildKeySerDes(), configBuilder.BuildValueSerDes()) { } /// - /// Initialize a new instance of + /// Initialize a new instance of /// /// The properties to use, see - /// Key serializer base on - /// Value serializer base on - public KNetProducer(ProducerConfigBuilder props, ISerDes keySerializer, ISerDes valueSerializer) + /// Key serializer base on + /// Value serializer base on + public KNetProducer(ProducerConfigBuilder props, ISerDes keySerializer, ISerDes valueSerializer) : base(CheckProperties(props), keySerializer.KafkaSerializer, valueSerializer.KafkaSerializer) { _keySerializer = keySerializer; @@ -196,13 +243,27 @@ static Properties CheckProperties(Properties props) { if (!props.ContainsKey(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG)) { - props.Put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); + if (typeof(TJVMK) == typeof(byte[])) + { + props.Put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); + } + else + { + props.Put(ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG, "org.mases.knet.common.serialization.ByteBufferSerializer"); + } } else throw new InvalidOperationException($"KNetProducer auto manages configuration property {ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG}, remove from configuration."); if (!props.ContainsKey(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG)) { - props.Put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); + if (typeof(TJVMV) == typeof(byte[])) + { + props.Put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.apache.kafka.common.serialization.ByteArraySerializer"); + } + else + { + props.Put(ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG, "org.mases.knet.common.serialization.ByteBufferSerializer"); + } } else throw new InvalidOperationException($"KNetProducer auto manages configuration property {ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG}, remove from configuration."); @@ -220,7 +281,7 @@ static Properties CheckProperties(Properties props) } } - static Org.Apache.Kafka.Clients.Producer.ProducerRecord ToProducerRecord(ProducerRecord record, ISerializer keySerializer, ISerializer valueSerializer) + static Org.Apache.Kafka.Clients.Producer.ProducerRecord ToProducerRecord(ProducerRecord record, ISerializer keySerializer, ISerializer valueSerializer) { var headers = record.Headers; if ((keySerializer.UseHeaders || valueSerializer.UseHeaders) && headers == null) @@ -228,27 +289,27 @@ static Org.Apache.Kafka.Clients.Producer.ProducerRecord ToProduc headers = Headers.Create(); } - return new Org.Apache.Kafka.Clients.Producer.ProducerRecord(record.Topic, record.Partition, record.Timestamp, + return new Org.Apache.Kafka.Clients.Producer.ProducerRecord(record.Topic, record.Partition, record.Timestamp, record.Key == null ? null : DataSerialize(keySerializer, record.Topic, record.Key, headers), record.Value == null ? null : DataSerialize(valueSerializer, record.Topic, record.Value, headers), headers); } - static byte[] DataSerialize(ISerializer serializer, string topic, T data, Headers headers) + static TJVMT DataSerialize(ISerializer serializer, string topic, T data, Headers headers) { - if (serializer == null) return null; + if (serializer == null) return default; if (serializer.UseHeaders) { return serializer.SerializeWithHeaders(topic, headers, data); } return serializer.Serialize(topic, data); } - /// + /// public void SetCallback(Callback callback) => IExecute("setCallback", callback); - /// - public Future Send(ProducerRecord record) + /// + public Future Send(ProducerRecord record) { - Org.Apache.Kafka.Clients.Producer.ProducerRecord kRecord = KNetProducer.ToProducerRecord((Producer.ProducerRecord)record, (ISerializer)_keySerializer, (ISerializer)_valueSerializer); + Org.Apache.Kafka.Clients.Producer.ProducerRecord kRecord = KNetProducer.ToProducerRecord((Producer.ProducerRecord)record, (ISerializer)_keySerializer, (ISerializer)_valueSerializer); try { GC.SuppressFinalize(kRecord); @@ -256,10 +317,10 @@ public Future Send(ProducerRecord record) } finally { GC.ReRegisterForFinalize(kRecord); } } - /// - public Future Send(ProducerRecord record, Callback callback) + /// + public Future Send(ProducerRecord record, Callback callback) { - Org.Apache.Kafka.Clients.Producer.ProducerRecord kRecord = KNetProducer.ToProducerRecord((Producer.ProducerRecord)record, (ISerializer)_keySerializer, (ISerializer)_valueSerializer); + Org.Apache.Kafka.Clients.Producer.ProducerRecord kRecord = KNetProducer.ToProducerRecord((Producer.ProducerRecord)record, (ISerializer)_keySerializer, (ISerializer)_valueSerializer); try { GC.SuppressFinalize(kRecord); @@ -267,58 +328,58 @@ public Future Send(ProducerRecord record, Callback callbac } finally { GC.ReRegisterForFinalize(kRecord); } } - /// + /// public void Send(string topic, int partition, long timestamp, K key, V value, Headers headers) { IExecute("send", topic, partition, timestamp, _keySerializer.SerializeWithHeaders(topic, headers, key), _valueSerializer.SerializeWithHeaders(topic, headers, value), headers); } - /// + /// public void Send(string topic, int partition, long timestamp, K key, V value) { IExecute("send", topic, partition, timestamp, _keySerializer.Serialize(topic, key), _valueSerializer.Serialize(topic, value)); } - /// + /// public void Send(string topic, int partition, K key, V value, Headers headers) { IExecute("send", topic, partition, _keySerializer.SerializeWithHeaders(topic, headers, key), _valueSerializer.SerializeWithHeaders(topic, headers, value), headers); } - /// + /// public void Send(string topic, int partition, K key, V value) { IExecute("send", topic, partition, _keySerializer.Serialize(topic, key), _valueSerializer.Serialize(topic, value)); } - /// + /// public void Send(string topic, K key, V value) { IExecute("send", topic, _keySerializer.Serialize(topic, key), _valueSerializer.Serialize(topic, value)); } - /// + /// public void Send(string topic, V value) { IExecute("send", topic, _valueSerializer.Serialize(topic, value)); } - /// + /// public void Produce(string topic, K key, V value, Action action = null) { - Produce(new ProducerRecord(topic, key, value), action); + Produce(new ProducerRecord(topic, key, value), action); } - /// + /// public void Produce(string topic, int partition, K key, V value, Action action = null) { - Produce(new ProducerRecord(topic, partition, key, value), action); + Produce(new ProducerRecord(topic, partition, key, value), action); } - /// + /// public void Produce(string topic, int partition, long timestamp, K key, V value, Action action = null) { - Produce(new ProducerRecord(topic, partition, timestamp, key, value), action); + Produce(new ProducerRecord(topic, partition, timestamp, key, value), action); } - /// + /// public void Produce(string topic, int partition, DateTime timestamp, K key, V value, Action action = null) { - Produce(new ProducerRecord(topic, partition, timestamp, key, value), action); + Produce(new ProducerRecord(topic, partition, timestamp, key, value), action); } - /// - public void Produce(ProducerRecord record, Action action = null) + /// + public void Produce(ProducerRecord record, Action action = null) { Callback cb = null; @@ -339,48 +400,48 @@ public void Produce(ProducerRecord record, Action + /// public Future Produce(string topic, K key, V value, Callback cb = null) { - return Produce(new ProducerRecord(topic, key, value), cb); + return Produce(new ProducerRecord(topic, key, value), cb); } - /// + /// public void ProduceAndWait(string topic, K key, V value, Callback cb = null) { - ProduceAndWait(new ProducerRecord(topic, key, value), cb); + ProduceAndWait(new ProducerRecord(topic, key, value), cb); } - /// + /// public Future Produce(string topic, int partition, K key, V value, Callback cb = null) { - return Produce(new ProducerRecord(topic, partition, key, value), cb); + return Produce(new ProducerRecord(topic, partition, key, value), cb); } - /// + /// public void ProduceAndWait(string topic, int partition, K key, V value, Callback cb = null) { - ProduceAndWait(new ProducerRecord(topic, partition, key, value), cb); + ProduceAndWait(new ProducerRecord(topic, partition, key, value), cb); } - /// + /// public Future Produce(string topic, int partition, long timestamp, K key, V value, Callback cb = null) { - return Produce(new ProducerRecord(topic, partition, timestamp, key, value), cb); + return Produce(new ProducerRecord(topic, partition, timestamp, key, value), cb); } - /// + /// public void ProduceAndWait(string topic, int partition, long timestamp, K key, V value, Callback cb = null) { - ProduceAndWait(new ProducerRecord(topic, partition, timestamp, key, value), cb); + ProduceAndWait(new ProducerRecord(topic, partition, timestamp, key, value), cb); } - /// + /// public Future Produce(string topic, int partition, DateTime timestamp, K key, V value, Callback cb = null) { - return Produce(new ProducerRecord(topic, partition, timestamp, key, value), cb); + return Produce(new ProducerRecord(topic, partition, timestamp, key, value), cb); } - /// + /// public void ProduceAndWait(string topic, int partition, DateTime timestamp, K key, V value, Callback cb = null) { - ProduceAndWait(new ProducerRecord(topic, partition, timestamp, key, value), cb); + ProduceAndWait(new ProducerRecord(topic, partition, timestamp, key, value), cb); } - /// - public Future Produce(ProducerRecord record, Callback cb = null) + /// + public Future Produce(ProducerRecord record, Callback cb = null) { if (cb != null) { @@ -391,8 +452,8 @@ public Future Produce(ProducerRecord record, Callback cb = return this.Send(record); } } - /// - public void ProduceAndWait(ProducerRecord record, Callback cb = null) + /// + public void ProduceAndWait(ProducerRecord record, Callback cb = null) { try { @@ -404,28 +465,28 @@ public void ProduceAndWait(ProducerRecord record, Callback cb = null) throw e.InnerException; } } - /// + /// public async Task ProduceAsync(string topic, K key, V value, Action action = null) { - await ProduceAsync(new ProducerRecord(topic, key, value), action); + await ProduceAsync(new ProducerRecord(topic, key, value), action); } - /// + /// public async Task ProduceAsync(string topic, int partition, K key, V value, Action action = null) { - await ProduceAsync(new ProducerRecord(topic, partition, key, value), action); + await ProduceAsync(new ProducerRecord(topic, partition, key, value), action); } - /// + /// public async Task ProduceAsync(string topic, int partition, long timestamp, K key, V value, Action action = null) { - await ProduceAsync(new ProducerRecord(topic, partition, timestamp, key, value), action); + await ProduceAsync(new ProducerRecord(topic, partition, timestamp, key, value), action); } - /// + /// public async Task ProduceAsync(string topic, int partition, DateTime timestamp, K key, V value, Action action = null) { - await ProduceAsync(new ProducerRecord(topic, partition, timestamp, key, value), action); + await ProduceAsync(new ProducerRecord(topic, partition, timestamp, key, value), action); } - /// - public async Task ProduceAsync(ProducerRecord record, Action action = null) + /// + public async Task ProduceAsync(ProducerRecord record, Action action = null) { Task task = Task.Factory.StartNew(() => { @@ -439,5 +500,173 @@ public async Task ProduceAsync(ProducerRecord record, Action + public ProducerRecord NewRecord() + { + return new ProducerRecord(); + } + /// + public ProducerRecord NewRecord(string topic, int partition, long timestamp, K key, V value, Headers headers) + { + return new ProducerRecord(topic, partition, timestamp, key, value, headers); + } + /// + public ProducerRecord NewRecord(string topic, int partition, System.DateTime timestamp, K key, V value, Headers headers) + { + return new ProducerRecord(topic, partition, timestamp, key, value, headers); + } + /// + public ProducerRecord NewRecord(string topic, int partition, long timestamp, K key, V value) + { + return new ProducerRecord(topic, partition, timestamp, key, value); + } + /// + public ProducerRecord NewRecord(string topic, int partition, System.DateTime timestamp, K key, V value) + { + return new ProducerRecord(topic, partition, timestamp, key, value); + } + /// + public ProducerRecord NewRecord(string topic, int partition, K key, V value, Headers headers) + { + return new ProducerRecord(topic, partition, key, value, headers); + } + /// + public ProducerRecord NewRecord(string topic, int partition, K key, V value) + { + return new ProducerRecord(topic, partition, key, value); + } + /// + public ProducerRecord NewRecord(string topic, K key, V value) + { + return new ProducerRecord(topic, key, value); + } + /// + public ProducerRecord NewRecord(string topic, V value) + { + return new ProducerRecord(topic, value); + } + } + + #endregion + + #region KNetProducer + /// + /// Extends adding less intrusive methods which performs better in high throughput applications, extends using array of + /// + /// Same meaning of + /// Same meaning of + public class KNetProducer : KNetProducer + { + /// + /// Initialize a new instance of + /// + /// An instance of + public KNetProducer(ProducerConfigBuilder configBuilder) + : base(configBuilder) + { + } + /// + /// Initialize a new instance of + /// + /// The properties to use, see + /// Key serializer base on + /// Value serializer base on + public KNetProducer(ProducerConfigBuilder props, ISerDes keySerializer, ISerDes valueSerializer) + : base(props, keySerializer, valueSerializer) + { + } } + + #endregion + + #region KNetProducerBuffered + /// + /// Extends adding less intrusive methods which performs better in high throughput applications, extends using + /// + /// Same meaning of + /// Same meaning of + public class KNetProducerBuffered : KNetProducer + { + /// + /// Initialize a new instance of + /// + /// An instance of + public KNetProducerBuffered(ProducerConfigBuilder configBuilder) + : base(configBuilder) + { + } + /// + /// Initialize a new instance of + /// + /// The properties to use, see + /// Key serializer base on + /// Value serializer base on + public KNetProducerBuffered(ProducerConfigBuilder props, ISerDes keySerializer, ISerDes valueSerializer) + : base(props, keySerializer, valueSerializer) + { + } + } + + #endregion + + #region KNetProducerKeyBuffered + /// + /// Extends adding less intrusive methods which performs better in high throughput applications, extends using for key + /// + /// Same meaning of + /// Same meaning of + public class KNetProducerKeyBuffered : KNetProducer + { + /// + /// Initialize a new instance of + /// + /// An instance of + public KNetProducerKeyBuffered(ProducerConfigBuilder configBuilder) + : base(configBuilder) + { + } + /// + /// Initialize a new instance of + /// + /// The properties to use, see + /// Key serializer base on + /// Value serializer base on + public KNetProducerKeyBuffered(ProducerConfigBuilder props, ISerDes keySerializer, ISerDes valueSerializer) + : base(props, keySerializer, valueSerializer) + { + } + } + + #endregion + + #region KNetProducerValueBuffered + /// + /// Extends adding less intrusive methods which performs better in high throughput applications, extends using for value + /// + /// Same meaning of + /// Same meaning of + public class KNetProducerValueBuffered : KNetProducer + { + /// + /// Initialize a new instance of + /// + /// An instance of + public KNetProducerValueBuffered(ProducerConfigBuilder configBuilder) + : base(configBuilder) + { + } + /// + /// Initialize a new instance of + /// + /// The properties to use, see + /// Key serializer base on + /// Value serializer base on + public KNetProducerValueBuffered(ProducerConfigBuilder props, ISerDes keySerializer, ISerDes valueSerializer) + : base(props, keySerializer, valueSerializer) + { + } + } + + #endregion } diff --git a/src/net/KNet/Specific/Producer/ProducerRecord.cs b/src/net/KNet/Specific/Producer/ProducerRecord.cs index 6de8f9eca9..ffdf0a1cf2 100644 --- a/src/net/KNet/Specific/Producer/ProducerRecord.cs +++ b/src/net/KNet/Specific/Producer/ProducerRecord.cs @@ -17,23 +17,23 @@ */ using Org.Apache.Kafka.Common.Header; -using Org.Apache.Kafka.Clients.Producer; namespace MASES.KNet.Producer { + #region ProducerRecord /// /// KNet extension of /// - public class ProducerRecord + public class ProducerRecord { /// - /// Initialize a new + /// Initialize a new /// public ProducerRecord() { } /// - /// Initialize a new + /// Initialize a new /// public ProducerRecord(string topic, int partition, long timestamp, K key, V value, Headers headers) { @@ -45,7 +45,7 @@ public ProducerRecord(string topic, int partition, long timestamp, K key, V valu Headers = headers; } /// - /// Initialize a new + /// Initialize a new /// public ProducerRecord(string topic, int partition, System.DateTime timestamp, K key, V value, Headers headers) { @@ -57,7 +57,7 @@ public ProducerRecord(string topic, int partition, System.DateTime timestamp, K Headers = headers; } /// - /// Initialize a new + /// Initialize a new /// public ProducerRecord(string topic, int partition, long timestamp, K key, V value) { @@ -68,7 +68,7 @@ public ProducerRecord(string topic, int partition, long timestamp, K key, V valu Value = value; } /// - /// Initialize a new + /// Initialize a new /// public ProducerRecord(string topic, int partition, System.DateTime timestamp, K key, V value) { @@ -79,7 +79,7 @@ public ProducerRecord(string topic, int partition, System.DateTime timestamp, K Value = value; } /// - /// Initialize a new + /// Initialize a new /// public ProducerRecord(string topic, int partition, K key, V value, Headers headers) { @@ -90,7 +90,7 @@ public ProducerRecord(string topic, int partition, K key, V value, Headers heade Headers = headers; } /// - /// Initialize a new + /// Initialize a new /// public ProducerRecord(string topic, int partition, K key, V value) { @@ -100,7 +100,7 @@ public ProducerRecord(string topic, int partition, K key, V value) Value = value; } /// - /// Initialize a new + /// Initialize a new /// public ProducerRecord(string topic, K key, V value) { @@ -109,7 +109,7 @@ public ProducerRecord(string topic, K key, V value) Value = value; } /// - /// Initialize a new + /// Initialize a new /// public ProducerRecord(string topic, V value) { @@ -136,4 +136,117 @@ public override string ToString() return $"Topic: {Topic} - Partition {Partition} - Key {Key} - Value {Value}"; } } + + #endregion + + #region ProducerRecord + /// + /// Extends using array of + /// + /// The key type + /// The value type + public class ProducerRecord : ProducerRecord + { + /// + public ProducerRecord() + { + } + /// + public ProducerRecord(string topic, int partition, long timestamp, K key, V value, Headers headers) + : base(topic, partition, timestamp, key, value, headers) + { + } + /// + public ProducerRecord(string topic, int partition, System.DateTime timestamp, K key, V value, Headers headers) + : base(topic, partition, timestamp, key, value, headers) + { + } + /// + public ProducerRecord(string topic, int partition, long timestamp, K key, V value) + : base(topic, partition, timestamp, key, value) + { + } + /// + public ProducerRecord(string topic, int partition, System.DateTime timestamp, K key, V value) + : base(topic, partition, timestamp, key, value) + { + } + /// + public ProducerRecord(string topic, int partition, K key, V value, Headers headers) + : base(topic, partition, key, value, headers) + { + } + /// + public ProducerRecord(string topic, int partition, K key, V value) + : base(topic, partition, key, value) + { + } + /// + public ProducerRecord(string topic, K key, V value) + : base(topic, key, value) + { + } + /// + public ProducerRecord(string topic, V value) + :base(topic, value) + { + } + } + + #endregion + + #region ProducerRecordBuffered + /// + /// Extends using + /// + /// The key type + /// The value type + public class ProducerRecordBuffered : ProducerRecord + { + /// + public ProducerRecordBuffered() + { + } + /// + public ProducerRecordBuffered(string topic, int partition, long timestamp, K key, V value, Headers headers) + : base(topic, partition, timestamp, key, value, headers) + { + } + /// + public ProducerRecordBuffered(string topic, int partition, System.DateTime timestamp, K key, V value, Headers headers) + : base(topic, partition, timestamp, key, value, headers) + { + } + /// + public ProducerRecordBuffered(string topic, int partition, long timestamp, K key, V value) + : base(topic, partition, timestamp, key, value) + { + } + /// + public ProducerRecordBuffered(string topic, int partition, System.DateTime timestamp, K key, V value) + : base(topic, partition, timestamp, key, value) + { + } + /// + public ProducerRecordBuffered(string topic, int partition, K key, V value, Headers headers) + : base(topic, partition, key, value, headers) + { + } + /// + public ProducerRecordBuffered(string topic, int partition, K key, V value) + : base(topic, partition, key, value) + { + } + /// + public ProducerRecordBuffered(string topic, K key, V value) + : base(topic, key, value) + { + } + /// + public ProducerRecordBuffered(string topic, V value) + : base(topic, value) + { + } + } + #endregion } diff --git a/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs b/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs index 0aaf05c6db..bf9d841563 100644 --- a/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs +++ b/src/net/KNet/Specific/Replicator/KNetCompactedReplicator.cs @@ -35,21 +35,21 @@ namespace MASES.KNet.Replicator { #region AccessRightsType /// - /// access rights to data + /// access rights to data /// [Flags] public enum AccessRightsType { /// - /// Data are readable, i.e. aligned with the others and accessible from this + /// Data are readable, i.e. aligned with the others and accessible from this /// Read = 1, /// - /// Data are writable, i.e. updates can be produced, but this is not accessible and not aligned with the others + /// Data are writable, i.e. updates can be produced, but this is not accessible and not aligned with the others /// Write = 2, /// - /// Data are readable and writable, i.e. updates can be produced, and data are aligned with the others and accessible from this + /// Data are readable and writable, i.e. updates can be produced, and data are aligned with the others and accessible from this /// ReadWrite = Read | Write, } @@ -59,77 +59,79 @@ public enum AccessRightsType #region UpdateModeTypes /// - /// update modes + /// update modes /// [Flags()] public enum UpdateModeTypes { /// - /// The is updated as soon as an update is delivered to Kafka by the current application + /// The is updated as soon as an update is delivered to Kafka by the current application /// OnDelivery = 1, /// - /// The is updated only after an update is consumed from Kafka, even if the add or update is made locally by the current instance + /// The is updated only after an update is consumed from Kafka, even if the add or update is made locally by the current instance /// OnConsume = 2, /// - /// The is updated only after an update is consumed from Kafka, even if the add or update is made locally by the current instance. Plus the update waits the consume of the data before unlock + /// The is updated only after an update is consumed from Kafka, even if the add or update is made locally by the current instance. Plus the update waits the consume of the data before unlock /// OnConsumeSync = 3, /// - /// The value is stored in only upon a request, otherwise only the key is stored + /// The value is stored in only upon a request, otherwise only the key is stored /// Delayed = 0x1000 } #endregion - #region IKNetCompactedReplicator + #region IKNetCompactedReplicator /// - /// Public interface for + /// Public interface for /// - /// The type of keys in the dictionary - /// The type of values in the dictionary. Must be a nullable type - public interface IKNetCompactedReplicator : IDictionary, IDisposable - where TValue : class + /// The type of keys in the dictionary + /// The type of values in the dictionary. Must be a nullable type + /// The JVM type of + /// The JVM type of + public interface IKNetCompactedReplicator : IDictionary, IDisposable + where V : class { #region Events /// - /// Called when a [, ] is added by consuming data from the others + /// Called when a [, ] is added by consuming data from the others /// - event Action, KeyValuePair> OnRemoteAdd; + event Action, KeyValuePair> OnRemoteAdd; /// - /// Called when a [, ] is updated by consuming data from the others + /// Called when a [, ] is updated by consuming data from the others /// - event Action, KeyValuePair> OnRemoteUpdate; + event Action, KeyValuePair> OnRemoteUpdate; /// - /// Called when a [, ] is removed by consuming data from the others + /// Called when a [, ] is removed by consuming data from the others /// - event Action, KeyValuePair> OnRemoteRemove; + event Action, KeyValuePair> OnRemoteRemove; /// - /// Called when a [, ] is added on this + /// Called when a [, ] is added on this /// - event Action, KeyValuePair> OnLocalAdd; + event Action, KeyValuePair> OnLocalAdd; /// - /// Called when a [, ] is updated on this + /// Called when a [, ] is updated on this /// - event Action, KeyValuePair> OnLocalUpdate; + event Action, KeyValuePair> OnLocalUpdate; /// - /// Called when a [, ] is removed from this + /// Called when a [, ] is removed from this /// - event Action, KeyValuePair> OnLocalRemove; + event Action, KeyValuePair> OnLocalRemove; /// - /// It is called to request if the [, ] can be stored in the instance. + /// It is called to request if the [, ] can be stored in the instance. /// /// The second parameter reports the current value that depends on values set to and if it contains the - Func, bool, KeyValuePair, bool> OnDelayedStore { get; } + Func, bool, KeyValuePair, bool> OnDelayedStore { get; } #endregion @@ -159,7 +161,7 @@ public interface IKNetCompactedReplicator : IDictionary int Partitions { get; } /// - /// Get or set the number of instances to be used, null to allocate based on + /// Get or set the number of instances to be used, null to allocate based on /// int? ConsumerInstances { get; } /// @@ -167,7 +169,7 @@ public interface IKNetCompactedReplicator : IDictionary short ReplicationFactor { get; } /// - /// Get or set the poll timeout to be used for + /// Get or set the poll timeout to be used for /// long ConsumePollTimeout { get; } /// @@ -175,11 +177,11 @@ public interface IKNetCompactedReplicator : IDictionary TopicConfigBuilder TopicConfig { get; } /// - /// Get or set to use in + /// Get or set to use in /// ConsumerConfigBuilder ConsumerConfig { get; } /// - /// Get or set to use in + /// Get or set to use in /// ProducerConfigBuilder ProducerConfig { get; } /// @@ -187,25 +189,25 @@ public interface IKNetCompactedReplicator : IDictionary Type KNetKeySerDes { get; } /// - /// Get or set an instance of to use in , by default it creates a default one based on + /// Get or set an instance of to use in , by default it creates a default one based on /// - ISerDes KeySerDes { get; } + ISerDes KeySerDes { get; } /// /// The used to create an instance of "/> /// Type KNetValueSerDes { get; } /// - /// Get or set an instance of to use in , by default it creates a default one based on + /// Get or set an instance of to use in , by default it creates a default one based on /// - ISerDes ValueSerDes { get; } + ISerDes ValueSerDes { get; } #if NET7_0_OR_GREATER /// - /// if enumeration will use prefetch and the number of records is more than , i.e. the preparation of happens in an external thread + /// if enumeration will use prefetch and the number of records is more than , i.e. the preparation of happens in an external thread /// - /// It is by default if one of or are not , override the value using + /// It is by default if one of or are not , override the value using bool IsPrefecth { get; } /// - /// The minimum threshold to activate pretech, i.e. the preparation of happens in external thread if contains more than elements + /// The minimum threshold to activate pretech, i.e. the preparation of happens in external thread if contains more than elements /// /// The default value is 10, however it shall be chosen by the developer and in the decision shall be verified if external thread activation costs more than inline execution int PrefetchThreshold { get; } @@ -233,7 +235,7 @@ public interface IKNetCompactedReplicator : IDictionary - /// Set to to enable enumeration with prefetch over threshold, i.e. preparation of in external thread + /// Set to to enable enumeration with prefetch over threshold, i.e. preparation of in external thread /// /// to enable prefetch. See /// The minimum threshold to activate pretech, default is 10. See @@ -241,12 +243,12 @@ public interface IKNetCompactedReplicator : IDictionary - /// Start this : create the topic if not available, allocates Producer and Consumer, sets serializer/deserializer + /// Start this : create the topic if not available, allocates Producer and Consumer, sets serializer/deserializer /// /// Some errors occurred void Start(); /// - /// Start this : create the topic if not available, allocates Producer and Consumers, sets serializer/deserializer + /// Start this : create the topic if not available, allocates Producer and Consumers, sets serializer/deserializer /// Then waits its synchronization with topic which stores dictionary data /// /// The number of milliseconds to wait, or to wait indefinitely @@ -261,7 +263,7 @@ public interface IKNetCompactedReplicator : IDictionaryThe provided do not include the flag bool WaitForStateAssignment(int timeout = Timeout.Infinite); /// - /// Waits that is synchronized to the topic which stores dictionary data + /// Waits that is synchronized to the topic which stores dictionary data /// /// The number of milliseconds to wait, or to wait indefinitely /// if the current instance synchronize within the given ; otherwise, @@ -272,30 +274,32 @@ public interface IKNetCompactedReplicator : IDictionary void Flush(); /// - /// Reports the metrics. + /// Reports the metrics. /// /// Extends /// A of and Java.Util.Map ProducerMetrics() where TMetric : Org.Apache.Kafka.Common.Metric; /// - /// Reports the metrics. + /// Reports the metrics. /// /// Extends - /// An where the key is the current allocated and value is a of and + /// An where the key is the current allocated and value is a of and IReadOnlyDictionary> ConsumerMetrics() where TMetric : Org.Apache.Kafka.Common.Metric; #endregion } #endregion - #region KNetCompactedReplicator + #region KNetCompactedReplicator /// /// Provides a reliable dictionary, persisted in a COMPACTED Kafka topic and shared among applications /// - /// The type of keys in the dictionary - /// The type of values in the dictionary. Must be a nullable type - public class KNetCompactedReplicator : IKNetCompactedReplicator - where TValue : class + /// The type of keys in the dictionary + /// The type of values in the dictionary. Must be a nullable type + /// The JVM type of + /// The JVM type of + public class KNetCompactedReplicator : IKNetCompactedReplicator + where V : class { const long InitialLagState = -2; const long NotPresentLagState = -1; @@ -310,7 +314,7 @@ interface ILocalDataStorage bool HasOffset { get; set; } Int64 Offset { get; set; } bool HasValue { get; set; } - TValue Value { get; set; } + V Value { get; set; } } struct LocalDataStorage : ILocalDataStorage @@ -328,20 +332,20 @@ public LocalDataStorage() public bool HasOffset { get; set; } public long Offset { get; set; } public bool HasValue { get; set; } - public TValue Value { get; set; } + public V Value { get; set; } } #endregion #region Local Enumerator - class LocalDataStorageEnumerator : IEnumerator> + class LocalDataStorageEnumerator : IEnumerator> { - private IEnumerator> _enumerator; - private readonly ConcurrentDictionary _dictionary; - private readonly IConsumer _consumer = null; + private IEnumerator> _enumerator; + private readonly ConcurrentDictionary _dictionary; + private readonly IConsumer _consumer = null; private readonly string _topic; - public LocalDataStorageEnumerator(ConcurrentDictionary dictionary, IConsumer consumer, string topic) + public LocalDataStorageEnumerator(ConcurrentDictionary dictionary, IConsumer consumer, string topic) { _dictionary = dictionary; _consumer = consumer; @@ -349,8 +353,8 @@ public LocalDataStorageEnumerator(ConcurrentDictionary _enumerator = _dictionary.GetEnumerator(); } - KeyValuePair? _current = null; - public KeyValuePair Current + KeyValuePair? _current = null; + public KeyValuePair Current { get { @@ -366,7 +370,7 @@ public KeyValuePair Current { OnDemandRetrieve(_consumer, _topic, localCurrent.Key, data); } - _current = new KeyValuePair(localCurrent.Key, localCurrent.Value.Value); + _current = new KeyValuePair(localCurrent.Key, localCurrent.Value.Value); } } return _current.Value; @@ -395,9 +399,9 @@ public void Reset() _enumerator.Reset(); } - public System.Collections.Generic.ICollection Values() + public System.Collections.Generic.ICollection Values() { - System.Collections.Generic.List values = new System.Collections.Generic.List(); + System.Collections.Generic.List values = new System.Collections.Generic.List(); while (this.MoveNext()) { values.Add(this.Current.Value); @@ -405,7 +409,7 @@ public System.Collections.Generic.ICollection Values() return values; } - public bool TryGetValue(TKey key, out TValue value) + public bool TryGetValue(K key, out V value) { value = default; if (_dictionary.TryGetValue(key, out var data)) @@ -420,7 +424,7 @@ public bool TryGetValue(TKey key, out TValue value) return false; } - public bool Contains(KeyValuePair item) + public bool Contains(KeyValuePair item) { if (this.TryGetValue(item.Key, out var data)) { @@ -429,19 +433,19 @@ public bool Contains(KeyValuePair item) return false; } - public void CopyTo(KeyValuePair[] array, int arrayIndex) + public void CopyTo(KeyValuePair[] array, int arrayIndex) { - var values = new System.Collections.Generic.List>(); + var values = new System.Collections.Generic.List>(); while (this.MoveNext()) { - values.Add(new KeyValuePair(this.Current.Key, this.Current.Value)); + values.Add(new KeyValuePair(this.Current.Key, this.Current.Value)); } Array.Copy(values.ToArray(), 0, array, arrayIndex, values.Count); } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - static void OnDemandRetrieve(IConsumer consumer, string topic, TKey key, ILocalDataStorage data) + static void OnDemandRetrieve(IConsumer consumer, string topic, K key, ILocalDataStorage data) { var topicPartition = new Org.Apache.Kafka.Common.TopicPartition(topic, data.Partition); var topics = Java.Util.Collections.SingletonList(topicPartition); @@ -512,11 +516,11 @@ public override void OnPartitionsLost(Java.Util.Collection _dictionary = new ConcurrentDictionary(); + private ConcurrentDictionary _dictionary = new ConcurrentDictionary(); private KNetCompactedConsumerRebalanceListener[] _consumerListeners = null; - private IConsumer[] _consumers = null; - private IConsumer _onTheFlyConsumer = null; - private IProducer _producer = null; + private IConsumer[] _consumers = null; + private IConsumer _onTheFlyConsumer = null; + private IProducer _producer = null; private string _bootstrapServers = null; private string _stateName = string.Empty; private string _groupId = Guid.NewGuid().ToString(); @@ -527,20 +531,20 @@ public override void OnPartitionsLost(Java.Util.Collection, bool, KeyValuePair, bool> _onDelayedStore = null; + private Func, bool, KeyValuePair, bool> _onDelayedStore = null; private AccessRightsType _accessrights = AccessRightsType.ReadWrite; private UpdateModeTypes _updateMode = UpdateModeTypes.OnDelivery; - private Tuple _OnConsumeSyncWaiter = null; + private Tuple _OnConsumeSyncWaiter = null; private System.Collections.Generic.Dictionary> _consumerAssociatedPartition = new(); private ManualResetEvent[] _assignmentWaiters; private bool[] _assignmentWaitersStatus; private long[] _lastPartitionLags = null; private Type _KNetKeySerDes = null; - private ISerDes _keySerDes = null; + private ISerDes _keySerDes = null; private bool _disposeKeySerDes = false; private Type _KNetValueSerDes = null; - private ISerDes _valueSerDes = null; + private ISerDes _valueSerDes = null; private bool _disposeValueSerDes = false; private bool _started = false; @@ -549,26 +553,26 @@ public override void OnPartitionsLost(Java.Util.Collection - public event Action, KeyValuePair> OnRemoteAdd; + /// + public event Action, KeyValuePair> OnRemoteAdd; - /// - public event Action, KeyValuePair> OnRemoteUpdate; + /// + public event Action, KeyValuePair> OnRemoteUpdate; - /// - public event Action, KeyValuePair> OnRemoteRemove; + /// + public event Action, KeyValuePair> OnRemoteRemove; - /// - public event Action, KeyValuePair> OnLocalAdd; + /// + public event Action, KeyValuePair> OnLocalAdd; - /// - public event Action, KeyValuePair> OnLocalUpdate; + /// + public event Action, KeyValuePair> OnLocalUpdate; - /// - public event Action, KeyValuePair> OnLocalRemove; + /// + public event Action, KeyValuePair> OnLocalRemove; - /// - public Func, bool, KeyValuePair, bool> OnDelayedStore + /// + public Func, bool, KeyValuePair, bool> OnDelayedStore { get { return _onDelayedStore; } set { CheckStarted(); _onDelayedStore = value; } @@ -577,43 +581,43 @@ public Func, bool, KeyValuePair + /// public AccessRightsType AccessRights { get { return _accessrights; } set { CheckStarted(); _accessrights = value; } } - /// + /// public UpdateModeTypes UpdateMode { get { return _updateMode; } set { CheckStarted(); _updateMode = value; } } - /// + /// public string BootstrapServers { get { return _bootstrapServers; } set { CheckStarted(); _bootstrapServers = value; } } - /// + /// public string StateName { get { return _stateName; } set { CheckStarted(); _stateName = value; } } - /// + /// public string GroupId { get { return _groupId; } set { CheckStarted(); _groupId = value; } } - /// + /// public int Partitions { get { return _partitions; } set { CheckStarted(); _partitions = value; } } - /// + /// public int? ConsumerInstances { get { return _consumerInstances.HasValue ? _consumerInstances.Value : _partitions; } set { CheckStarted(); _consumerInstances = value; } } - /// + /// public short ReplicationFactor { get { return _replicationFactor; } set { CheckStarted(); _replicationFactor = value; } } - /// + /// public long ConsumePollTimeout { get { return _consumePollTimeout; } set { CheckStarted(); _consumePollTimeout = value; } } - /// + /// public TopicConfigBuilder TopicConfig { get { return _topicConfig; } set { CheckStarted(); _topicConfig = value; } } - /// + /// public ConsumerConfigBuilder ConsumerConfig { get { return _consumerConfig; } set { CheckStarted(); _consumerConfig = value; } } - /// + /// public ProducerConfigBuilder ProducerConfig { get { return _producerConfig; } set { CheckStarted(); _producerConfig = value; } } - /// + /// public Type KNetKeySerDes { get { return _KNetKeySerDes; } @@ -630,7 +634,7 @@ public Type KNetKeySerDes var keyT = value.GetGenericArguments(); if (keyT.Length != 1) { throw new ArgumentException($"{value.Name} does not contains a single generic argument and cannot be used because it is not a valid Serializer type"); } var t = value.GetGenericTypeDefinition(); - if (t.GetInterface(typeof(ISerDes<>).Name) == null) + if (t.GetInterface(typeof(ISerDes<,>).Name) == null) { throw new ArgumentException($"{value.Name} does not implement IKNetSerDes<> and cannot be used because it is not a valid Serializer type"); } @@ -640,10 +644,10 @@ public Type KNetKeySerDes } } - /// - public ISerDes KeySerDes { get { return _keySerDes; } set { CheckStarted(); _keySerDes = value; } } + /// + public ISerDes KeySerDes { get { return _keySerDes; } set { CheckStarted(); _keySerDes = value; } } - /// + /// public Type KNetValueSerDes { get { return _KNetValueSerDes; } @@ -660,7 +664,7 @@ public Type KNetValueSerDes var keyT = value.GetGenericArguments(); if (keyT.Length != 1) { throw new ArgumentException($"{value.Name} does not contains a single generic argument and cannot be used because it is not a valid Serializer type"); } var t = value.GetGenericTypeDefinition(); - if (t.GetInterface(typeof(ISerDes<>).Name) == null) + if (t.GetInterface(typeof(ISerDes<,>).Name) == null) { throw new ArgumentException($"{value.Name} does not implement IKNetSerDes<> and cannot be used because it is not a valid Serializer type"); } @@ -670,22 +674,22 @@ public Type KNetValueSerDes } } - /// - public ISerDes ValueSerDes { get { return _valueSerDes; } set { CheckStarted(); _valueSerDes = value; } } + /// + public ISerDes ValueSerDes { get { return _valueSerDes; } set { CheckStarted(); _valueSerDes = value; } } #if NET7_0_OR_GREATER - /// - public bool IsPrefecth { get; private set; } = !(typeof(TKey).IsValueType && typeof(TValue).IsValueType); + /// + public bool IsPrefecth { get; private set; } = !(typeof(K).IsValueType && typeof(V).IsValueType); - /// + /// public int PrefetchThreshold { get; private set; } = 10; #endif - /// + /// public bool IsStarted => _started; - /// + /// public bool IsAssigned => _assignmentWaiters.All((o) => o.WaitOne(0)); - /// + /// public IReadOnlyDictionary CurrentPartitionLags { get @@ -700,7 +704,7 @@ public IReadOnlyDictionary CurrentPartitionLags } } - /// + /// public IReadOnlyDictionary CurrentConsumersSyncState { get @@ -738,12 +742,12 @@ int ConsumersToAllocate() bool UpdateModeDelayed => UpdateMode.HasFlag(UpdateModeTypes.Delayed); - private void OnMessage(ConsumerRecord record) + private void OnMessage(ConsumerRecord record) { if (record.Value == null) { _dictionary.TryRemove(record.Key, out var data); - OnRemoteRemove?.Invoke(this, new KeyValuePair(record.Key, data.Value)); + OnRemoteRemove?.Invoke(this, new KeyValuePair(record.Key, data.Value)); } else { @@ -763,7 +767,7 @@ private void OnMessage(ConsumerRecord record) bool storeValue = UpdateModeDelayed ? false : true; if (OnDelayedStore != null) { - storeValue = OnDelayedStore.Invoke(this, storeValue, new KeyValuePair(record.Key, record.Value)); + storeValue = OnDelayedStore.Invoke(this, storeValue, new KeyValuePair(record.Key, record.Value)); } if (storeValue) { @@ -773,11 +777,11 @@ private void OnMessage(ConsumerRecord record) } if (containsKey) { - OnRemoteUpdate?.Invoke(this, new KeyValuePair(record.Key, record.Value)); + OnRemoteUpdate?.Invoke(this, new KeyValuePair(record.Key, record.Value)); } else { - OnRemoteAdd?.Invoke(this, new KeyValuePair(record.Key, record.Value)); + OnRemoteAdd?.Invoke(this, new KeyValuePair(record.Key, record.Value)); } } @@ -842,7 +846,7 @@ private void OnTopicPartitionsLost(KNetCompactedConsumerRebalanceListener listen } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - private void AddOrUpdate(TKey key, TValue value) + private void AddOrUpdate(K key, V value) { ValidateAccessRights(AccessRightsType.Write); ValidateStarted(); @@ -873,7 +877,7 @@ private void AddOrUpdate(TKey key, TValue value) } }) { - _producer.Produce(new ProducerRecord(_stateName, key, value), cb); + _producer.Produce(new ProducerRecord(_stateName, key, value), cb); deliverySemaphore.WaitOne(); if (exception != null) throw exception; } @@ -882,7 +886,7 @@ private void AddOrUpdate(TKey key, TValue value) if (value == null) { _dictionary.TryRemove(key, out var data); - OnLocalRemove?.Invoke(this, new KeyValuePair(key, data.Value)); + OnLocalRemove?.Invoke(this, new KeyValuePair(key, data.Value)); } else { @@ -902,7 +906,7 @@ private void AddOrUpdate(TKey key, TValue value) bool storeValue = UpdateModeDelayed ? false : true; if (OnDelayedStore != null) { - storeValue = OnDelayedStore.Invoke(this, storeValue, new KeyValuePair(key, value)); + storeValue = OnDelayedStore.Invoke(this, storeValue, new KeyValuePair(key, value)); } if (storeValue) { @@ -912,11 +916,11 @@ private void AddOrUpdate(TKey key, TValue value) } if (containsKey) { - OnLocalUpdate?.Invoke(this, new KeyValuePair(key, value)); + OnLocalUpdate?.Invoke(this, new KeyValuePair(key, value)); } else { - OnLocalAdd?.Invoke(this, new KeyValuePair(key, value)); + OnLocalAdd?.Invoke(this, new KeyValuePair(key, value)); } } } @@ -925,7 +929,7 @@ private void AddOrUpdate(TKey key, TValue value) _producer.Produce(StateName, key, value, (Org.Apache.Kafka.Clients.Producer.Callback)null); if (UpdateModeOnConsumeSync) { - _OnConsumeSyncWaiter = new Tuple(key, new ManualResetEvent(false)); + _OnConsumeSyncWaiter = new Tuple(key, new ManualResetEvent(false)); _OnConsumeSyncWaiter.Item2.WaitOne(); _OnConsumeSyncWaiter.Item2.Dispose(); } @@ -962,18 +966,18 @@ void BuildConsumers() { ConsumerConfig.KNetKeySerDes = KNetKeySerDes; } - else if (KeySerDes == null) throw new InvalidOperationException($"{typeof(TKey)} needs an external deserializer, set KNetKeySerDes or KeySerDes."); + else if (KeySerDes == null) throw new InvalidOperationException($"{typeof(K)} needs an external deserializer, set KNetKeySerDes or KeySerDes."); if (KNetValueSerDes != null) { ConsumerConfig.KNetValueSerDes = KNetValueSerDes; } - else if (ValueSerDes == null) throw new InvalidOperationException($"{typeof(TValue)} needs an external deserializer, set KNetValueSerDes or ValueSerDes."); + else if (ValueSerDes == null) throw new InvalidOperationException($"{typeof(V)} needs an external deserializer, set KNetValueSerDes or ValueSerDes."); _assignmentWaiters = new ManualResetEvent[Partitions]; _assignmentWaitersStatus = new bool[Partitions]; _lastPartitionLags = new long[Partitions]; - _consumers = new KNetConsumer[ConsumersToAllocate()]; + _consumers = new KNetConsumer[ConsumersToAllocate()]; _consumerListeners = new KNetCompactedConsumerRebalanceListener[ConsumersToAllocate()]; for (int i = 0; i < Partitions; i++) @@ -986,7 +990,8 @@ void BuildConsumers() for (int i = 0; i < ConsumersToAllocate(); i++) { _consumerAssociatedPartition.Add(i, new System.Collections.Generic.List()); - _consumers[i] = (KNetKeySerDes != null || KNetValueSerDes != null) ? new KNetConsumer(ConsumerConfig) : new KNetConsumer(ConsumerConfig, KeySerDes, ValueSerDes); + _consumers[i] = (KNetKeySerDes != null || KNetValueSerDes != null) ? new KNetConsumer(ConsumerConfig) + : new KNetConsumer(ConsumerConfig, KeySerDes, ValueSerDes); #if NET7_0_OR_GREATER _consumers[i].ApplyPrefetch(IsPrefecth, PrefetchThreshold); #endif @@ -1008,7 +1013,8 @@ void BuildOnTheFlyConsumer() ConsumerConfigBuilder consumerConfigBuilder = ConsumerConfigBuilder.CreateFrom(_consumerConfig); consumerConfigBuilder.WithEnableAutoCommit(false).WithGroupId(Guid.NewGuid().ToString()); - _onTheFlyConsumer = (KNetKeySerDes != null || KNetValueSerDes != null) ? new KNetConsumer(consumerConfigBuilder) : new KNetConsumer(consumerConfigBuilder, KeySerDes, ValueSerDes); + _onTheFlyConsumer = (KNetKeySerDes != null || KNetValueSerDes != null) ? new KNetConsumer(consumerConfigBuilder) + : new KNetConsumer(consumerConfigBuilder, KeySerDes, ValueSerDes); } } [System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] @@ -1024,15 +1030,16 @@ void BuildProducer() { ProducerConfig.KNetKeySerDes = KNetKeySerDes; } - else if (KeySerDes == null) throw new InvalidOperationException($"{typeof(TKey)} needs an external serializer, set KNetKeySerDes or KeySerDes."); + else if (KeySerDes == null) throw new InvalidOperationException($"{typeof(K)} needs an external serializer, set KNetKeySerDes or KeySerDes."); if (KNetValueSerDes != null) { ProducerConfig.KNetValueSerDes = KNetValueSerDes; } - else if (ValueSerDes == null) throw new InvalidOperationException($"{typeof(TValue)} needs an external serializer, set KNetValueSerDes or ValueSerDes."); + else if (ValueSerDes == null) throw new InvalidOperationException($"{typeof(V)} needs an external serializer, set KNetValueSerDes or ValueSerDes."); - _producer = (KNetKeySerDes != null || KNetValueSerDes != null) ? new KNetProducer(ProducerConfig) : new KNetProducer(ProducerConfig, KeySerDes, ValueSerDes); + _producer = (KNetKeySerDes != null || KNetValueSerDes != null) ? new KNetProducer(ProducerConfig) + : new KNetProducer(ProducerConfig, KeySerDes, ValueSerDes); } void ConsumerPollHandler(object o) @@ -1095,18 +1102,18 @@ bool CheckConsumerSyncState(int index) return _consumers[index].IsEmpty && !_consumers[index].IsCompleting && lagInSync; } -#endregion + #endregion #region Public methods #if NET7_0_OR_GREATER - /// + /// public void ApplyPrefetch(bool enablePrefetch = true, int prefetchThreshold = 10) { IsPrefecth = enablePrefetch; PrefetchThreshold = IsPrefecth ? prefetchThreshold : 10; } #endif - /// + /// public void Start() { if (string.IsNullOrWhiteSpace(BootstrapServers)) throw new InvalidOperationException("BootstrapServers must be set before start."); @@ -1157,15 +1164,15 @@ public void Start() finally { topic?.Dispose(); } } _disposeKeySerDes = false; - if (KNetKeySerDes == null && KeySerDes == null && KNetSerialization.IsInternalManaged()) + if (KNetKeySerDes == null && KeySerDes == null && KNetSerialization.IsInternalManaged()) { - KeySerDes = new SerDes(); + KeySerDes = new SerDes(); _disposeKeySerDes = true; } _disposeValueSerDes = false; - if (KNetValueSerDes == null && ValueSerDes == null && KNetSerialization.IsInternalManaged()) + if (KNetValueSerDes == null && ValueSerDes == null && KNetSerialization.IsInternalManaged()) { - ValueSerDes = new SerDes(); + ValueSerDes = new SerDes(); _disposeValueSerDes = true; } @@ -1204,7 +1211,7 @@ public void Start() _started = true; } - /// + /// public bool StartAndWait(int timeout = Timeout.Infinite) { ValidateAccessRights(AccessRightsType.Read); @@ -1213,7 +1220,7 @@ public bool StartAndWait(int timeout = Timeout.Infinite) return SyncWait(timeout); } - /// + /// public bool WaitForStateAssignment(int timeout = Timeout.Infinite) { ValidateAccessRights(AccessRightsType.Read); @@ -1231,7 +1238,7 @@ public bool WaitForStateAssignment(int timeout = Timeout.Infinite) return status; } - /// + /// public bool SyncWait(int timeout = Timeout.Infinite) { ValidateAccessRights(AccessRightsType.Read); @@ -1250,7 +1257,7 @@ public bool SyncWait(int timeout = Timeout.Infinite) return sync; } - /// + /// public void Flush() { ValidateAccessRights(AccessRightsType.Write); @@ -1258,13 +1265,13 @@ public void Flush() _producer?.Flush(); } - /// + /// public Java.Util.Map ProducerMetrics() where TMetric : Org.Apache.Kafka.Common.Metric { ValidateStarted(); return _producer.Metrics(); } - /// + /// public IReadOnlyDictionary> ConsumerMetrics() where TMetric : Org.Apache.Kafka.Common.Metric { ValidateStarted(); @@ -1280,7 +1287,7 @@ public void Flush() #endregion - #region IDictionary + #region IDictionary /// /// Gets or sets the element with the specified keyy. value removes the specified key @@ -1291,7 +1298,7 @@ public void Flush() /// The call is set, and the provided do not include the flag /// is null /// The call is get and is not found - public TValue this[TKey key] + public V this[K key] { get { @@ -1308,11 +1315,11 @@ public TValue this[TKey key] } /// - /// Gets an containing the keys of this + /// Gets an containing the keys of this /// - /// containing the keys of this + /// containing the keys of this /// The provided do not include the flag - public System.Collections.Generic.ICollection Keys + public System.Collections.Generic.ICollection Keys { get { @@ -1323,11 +1330,11 @@ public System.Collections.Generic.ICollection Keys } /// - /// Gets an containing the values of this + /// Gets an containing the values of this /// - /// containing the values of this + /// containing the values of this /// The provided do not include the flag - public System.Collections.Generic.ICollection Values + public System.Collections.Generic.ICollection Values { get { @@ -1339,9 +1346,9 @@ public System.Collections.Generic.ICollection Values } /// - /// Gets the number of elements contained in this + /// Gets the number of elements contained in this /// - /// The number of elements contained in this + /// The number of elements contained in this /// The provided do not include the flag public int Count { @@ -1362,30 +1369,30 @@ public bool IsReadOnly } /// - /// Adds or updates the in this and others in the way defined by the provided + /// Adds or updates the in this and others in the way defined by the provided /// /// The object to use as the key of the element to add /// The object to use as the value of the element to add. null means remove /// is null /// The provided do not include the flag - public void Add(TKey key, TValue value) + public void Add(K key, V value) { AddOrUpdate(key, value); } /// - /// Adds or updates the in this and others in the way defined by the provided + /// Adds or updates the in this and others in the way defined by the provided /// /// The item to add or updates. Value == null means remove key /// .Key is null /// The provided do not include the flag - public void Add(KeyValuePair item) + public void Add(KeyValuePair item) { AddOrUpdate(item.Key, item.Value); } /// - /// Clears this , resetting all partitions' sync + /// Clears this , resetting all partitions' sync /// /// The provided do not include the flag public void Clear() @@ -1396,13 +1403,13 @@ public void Clear() } /// - /// Determines whether this contains the specified item + /// Determines whether this contains the specified item /// - /// The item to locate in this - /// if this contains an element ; otherwise, + /// The item to locate in this + /// if this contains an element ; otherwise, /// .Key is /// The provided do not include the flag - public bool Contains(KeyValuePair item) + public bool Contains(KeyValuePair item) { ValidateAccessRights(AccessRightsType.Read); ValidateStarted(); @@ -1411,13 +1418,13 @@ public bool Contains(KeyValuePair item) } /// - /// Determines whether this contains an element with the specified key + /// Determines whether this contains an element with the specified key /// - /// The key to locate in this - /// if this contains an element with ; otherwise, + /// The key to locate in this + /// if this contains an element with ; otherwise, /// is /// The provided do not include the flag - public bool ContainsKey(TKey key) + public bool ContainsKey(K key) { ValidateAccessRights(AccessRightsType.Read); ValidateStarted(); @@ -1425,18 +1432,18 @@ public bool ContainsKey(TKey key) } /// - /// Copies the elements of this to an , starting at a particular index + /// Copies the elements of this to an , starting at a particular index /// /// The one-dimensional that is the destination of the elements copied - /// from this . The must have zero-based indexing + /// from this . The must have zero-based indexing /// The zero-based index in array at which copying beginsù /// is null /// is less than zero /// is multidimensional. - /// -or- The number of elements in the source is greater than the available space from to the end of the destination . - /// -or- The type of the source cannot be cast automatically to the type of the destination + /// -or- The number of elements in the source is greater than the available space from to the end of the destination . + /// -or- The type of the source cannot be cast automatically to the type of the destination /// The provided do not include the flag - public void CopyTo(KeyValuePair[] array, int arrayIndex) + public void CopyTo(KeyValuePair[] array, int arrayIndex) { ValidateAccessRights(AccessRightsType.Read); ValidateStarted(); @@ -1445,11 +1452,11 @@ public void CopyTo(KeyValuePair[] array, int arrayIndex) } /// - /// Returns an enumerator that iterates through this + /// Returns an enumerator that iterates through this /// - /// An enumerator for this + /// An enumerator for this /// The provided do not include the flag - public IEnumerator> GetEnumerator() + public IEnumerator> GetEnumerator() { ValidateAccessRights(AccessRightsType.Read); ValidateStarted(); @@ -1458,13 +1465,13 @@ public IEnumerator> GetEnumerator() } /// - /// Removes the from this and others in the way defined by the provided + /// Removes the from this and others in the way defined by the provided /// /// The key of the element to remove - /// if the removal request is delivered to the others + /// if the removal request is delivered to the others /// is /// The provided do not include the flag - public bool Remove(TKey key) + public bool Remove(K key) { AddOrUpdate(key, null); @@ -1472,13 +1479,13 @@ public bool Remove(TKey key) } /// - /// Removes the from this and others in the way defined by the provided + /// Removes the from this and others in the way defined by the provided /// /// Item to be removed - /// if the removal request is delivered to the others + /// if the removal request is delivered to the others /// .Key is /// The provided do not include the flag - public bool Remove(KeyValuePair item) + public bool Remove(KeyValuePair item) { AddOrUpdate(item.Key, null); @@ -1486,15 +1493,15 @@ public bool Remove(KeyValuePair item) } /// - /// Attempts to get the value associated with the specified from this + /// Attempts to get the value associated with the specified from this /// /// The key of the value to get - /// When this method returns, contains the object from this + /// When this method returns, contains the object from this /// that has the specified , or the default value of the type if the operation failed - /// if the was found in this ; otherwise, + /// if the was found in this ; otherwise, /// is /// The provided do not include the flag - public bool TryGetValue(TKey key, out TValue value) + public bool TryGetValue(K key, out V value) { ValidateAccessRights(AccessRightsType.Read); ValidateStarted(); @@ -1583,5 +1590,29 @@ public override string ToString() #endregion } -#endregion + #endregion + + #region KNetCompactedReplicatorBuffered + /// + /// Provides a reliable dictionary, persisted in a COMPACTED Kafka topic and shared among applications, extends using array of + /// + /// The type of keys in the dictionary + /// The type of values in the dictionary. Must be a nullable type + public class KNetCompactedReplicator : KNetCompactedReplicator + where V : class + { + } + #endregion + + #region KNetCompactedReplicatorBuffered + /// + /// Provides a reliable dictionary, persisted in a COMPACTED Kafka topic and shared among applications, extends using + /// + /// The type of keys in the dictionary + /// The type of values in the dictionary. Must be a nullable type + public class KNetCompactedReplicatorBuffered : KNetCompactedReplicator + where V : class + { + } + #endregion } diff --git a/src/net/KNet/Specific/Serialization/IDeserializer.cs b/src/net/KNet/Specific/Serialization/IDeserializer.cs index 6fa80dfab3..e71b0a8cd9 100644 --- a/src/net/KNet/Specific/Serialization/IDeserializer.cs +++ b/src/net/KNet/Specific/Serialization/IDeserializer.cs @@ -30,25 +30,34 @@ namespace MASES.KNet.Serialization public interface IDeserializer : IDisposable { /// - /// The to use in Apache Kafka + /// The to use in Apache Kafka /// Deserializer KafkaDeserializer { get; } /// - /// if are used + /// if are used /// bool UseHeaders { get; } + /// + /// Set to in implementing class if the implementation shall use the support of direct buffer exchange + /// + bool IsDirectBuffered { get; } + /// + /// Set to in implementing class if the implementation shall use the deserializer of Apache Kafka, default is + /// + /// When this option is set to there is better compatibility with data managed from Apache Kafka, but there is a performance impact + bool UseKafkaClassForSupportedTypes { get; set; } /// - T Deserialize(string topic, byte[] data); + T Deserialize(string topic, TJVMT data); /// - T DeserializeWithHeaders(string topic, Headers headers, byte[] data); + T DeserializeWithHeaders(string topic, Headers headers, TJVMT data); } - /// - /// KNet interface for deserializers based on array JVM type - /// - /// The .NET type - public interface IDeserializer : IDeserializer - { + ///// + ///// KNet interface for deserializers based on array JVM type + ///// + ///// The .NET type + //public interface IDeserializer : IDeserializer + //{ - } + //} } diff --git a/src/net/KNet/Specific/Serialization/IGenericSerDesFactory.cs b/src/net/KNet/Specific/Serialization/IGenericSerDesFactory.cs index ef3c2ab5c8..78000d4d04 100644 --- a/src/net/KNet/Specific/Serialization/IGenericSerDesFactory.cs +++ b/src/net/KNet/Specific/Serialization/IGenericSerDesFactory.cs @@ -26,44 +26,35 @@ namespace MASES.KNet.Serialization public interface IGenericSerDesFactory { /// - /// The used to create an instance of for keys with + /// Set to to automatically fallback to when the JVM type is + /// + /// The property is by default to optimized data flow between CLR and JVM + bool AutoSelectBuffered { get; } + /// + /// The used to create an instance of for keys with /// Type KNetKeySerDes { get; } /// - /// The used to create an instance of for values with + /// The used to create an instance of for values with /// Type KNetValueSerDes { get; } /// - /// Builds an instance of using the defined in + /// Builds an instance of using the defined in /// /// The type of the key /// The JVM type of the key - /// An instance of + /// An instance of /// If is ISerDes BuildKeySerDes(); /// - /// Builds an instance of using the defined in - /// - /// The type of the key - /// An instance of - /// If is - ISerDes BuildKeySerDes(); - /// - /// Builds an instance of using the defined in + /// Builds an instance of using the defined in /// /// The type of the key /// The JVM type of the key - /// An instance of + /// An instance of /// If is ISerDes BuildValueSerDes(); /// - /// Builds an instance of using the defined in - /// - /// The type of the key - /// An instance of - /// If is - ISerDes BuildValueSerDes(); - /// /// Clear the current factory /// void Clear(); diff --git a/src/net/KNet/Specific/Serialization/ISerializer.cs b/src/net/KNet/Specific/Serialization/ISerializer.cs index 386a6aca51..afea9e7126 100644 --- a/src/net/KNet/Specific/Serialization/ISerializer.cs +++ b/src/net/KNet/Specific/Serialization/ISerializer.cs @@ -34,21 +34,30 @@ public interface ISerializer : IDisposable /// public Serializer KafkaSerializer { get; } /// - /// if are used + /// if are used /// bool UseHeaders { get; } + /// + /// Set to in implementing class if the implementation shall use the support of direct buffer exchange + /// + bool IsDirectBuffered { get; } + /// + /// Set to in implementing class if the implementation shall use the serializer of Apache Kafka, default is + /// + /// When this option is set to there is better compatibility with data managed from Apache Kafka, but there is a performance impact + bool UseKafkaClassForSupportedTypes { get; set; } /// - byte[] Serialize(string topic, T data); + TJVMT Serialize(string topic, T data); /// - byte[] SerializeWithHeaders(string topic, Headers headers, T data); + TJVMT SerializeWithHeaders(string topic, Headers headers, T data); } - /// - /// KNet interface for serializers based on array JVM type - /// - /// The .NET type - public interface ISerializer : ISerializer - { + ///// + ///// KNet interface for serializers based on array JVM type + ///// + ///// The .NET type + //public interface ISerializer : ISerializer + //{ - } + //} } diff --git a/src/net/KNet/Specific/Serialization/KNetSerialization.cs b/src/net/KNet/Specific/Serialization/KNetSerialization.cs index 6511b8435b..1fc92e9052 100644 --- a/src/net/KNet/Specific/Serialization/KNetSerialization.cs +++ b/src/net/KNet/Specific/Serialization/KNetSerialization.cs @@ -237,15 +237,16 @@ public static SerializationType InternalJVMSerDesType(Type type) /// /// Serialize a /// - public static byte[] SerializeBoolean(string topic, bool data) + public static byte[] SerializeBoolean(bool fallbackToKafka, string topic, bool data) { - return _BooleanSerializer.Serialize(topic, data); + if (fallbackToKafka) return _BooleanSerializer.Serialize(topic, data); + return BitConverter.GetBytes(data); } /// /// Serialize a /// - public static byte[] SerializeByteArray(string topic, byte[] data) + public static byte[] SerializeByteArray(bool fallbackToKafka, string topic, byte[] data) { return data; } @@ -254,16 +255,17 @@ public static byte[] SerializeByteArray(string topic, byte[] data) /// /// Serialize a /// - public static byte[] SerializeByteBuffer(string topic, ByteBuffer data) + public static byte[] SerializeByteBuffer(bool fallbackToKafka, string topic, ByteBuffer data) { - return _ByteBufferSerializer.Serialize(topic, data); + if (fallbackToKafka) return _ByteBufferSerializer.Serialize(topic, data); + return data.ToArray(true); } static readonly BytesSerializer _BytesSerializer = new BytesSerializer(); /// /// Serialize a /// - public static byte[] SerializeBytes(string topic, Bytes data) + public static byte[] SerializeBytes(bool fallbackToKafka, string topic, Bytes data) { return _BytesSerializer.Serialize(topic, data); } @@ -272,38 +274,43 @@ public static byte[] SerializeBytes(string topic, Bytes data) /// /// Serialize a /// - public static byte[] SerializeDouble(string topic, double data) + public static byte[] SerializeDouble(bool fallbackToKafka, string topic, double data) { - return _DoubleSerializer.Serialize(topic, data); + if (fallbackToKafka) return _DoubleSerializer.Serialize(topic, data); + return BitConverter.GetBytes(data); } static readonly FloatSerializer _FloatSerializer = new FloatSerializer(); /// /// Serialize a /// - public static byte[] SerializeFloat(string topic, float data) + public static byte[] SerializeFloat(bool fallbackToKafka, string topic, float data) { - return _FloatSerializer.Serialize(topic, data); + if (fallbackToKafka) return _FloatSerializer.Serialize(topic, data); + return BitConverter.GetBytes(data); } static readonly IntegerSerializer _IntSerializer = new IntegerSerializer(); /// /// Serialize a /// - public static byte[] SerializeInt(string topic, int data) + public static byte[] SerializeInt(bool fallbackToKafka, string topic, int data) { - return _IntSerializer.Serialize(topic, data); + if (fallbackToKafka) return _IntSerializer.Serialize(topic, data); + return BitConverter.GetBytes(data); + // the following generates an error in container //return new byte[] { (byte)(data >>> 24), (byte)(data >>> 16), (byte)(data >>> 8), ((byte)data) }; } - static readonly Serializer _LongSerializer = new LongSerializer(); + static readonly LongSerializer _LongSerializer = new LongSerializer(); /// /// Serialize a /// - public static byte[] SerializeLong(string topic, long data) + public static byte[] SerializeLong(bool fallbackToKafka, string topic, long data) { - return _LongSerializer.Serialize(topic, data); + if (fallbackToKafka) return _LongSerializer.Serialize(topic, data); + return BitConverter.GetBytes(data); // the following generates an error in container //return new byte[] { (byte)((int)(data >>> 56)), (byte)((int)(data >>> 48)), (byte)((int)(data >>> 40)), (byte)((int)(data >>> 32)), (byte)((int)(data >>> 24)), (byte)((int)(data >>> 16)), (byte)((int)(data >>> 8)), ((byte)data) }; } @@ -312,30 +319,31 @@ public static byte[] SerializeLong(string topic, long data) /// /// Serialize a /// - public static byte[] SerializeShort(string topic, short data) + public static byte[] SerializeShort(bool fallbackToKafka, string topic, short data) { - return _ShortSerializer.Serialize(topic, data); + if (fallbackToKafka) return _ShortSerializer.Serialize(topic, data); + return BitConverter.GetBytes(data); // the following generates an error in container //return new byte[] { (byte)(data >>> 8), ((byte)data) }; } /// /// Serialize a /// - public static byte[] SerializeString(string topic, string data) + public static byte[] SerializeString(bool fallbackToKafka, string topic, string data) { return Encoding.UTF8.GetBytes(data); } /// /// Serialize a /// - public static byte[] SerializeGuid(string topic, Guid data) + public static byte[] SerializeGuid(bool fallbackToKafka, string topic, Guid data) { return data.ToByteArray(); } /// /// Serialize a /// - public static byte[] SerializeVoid(string topic, Java.Lang.Void data) + public static byte[] SerializeVoid(bool fallbackToKafka, string topic, Java.Lang.Void data) { return null; } @@ -344,20 +352,25 @@ public static byte[] SerializeVoid(string topic, Java.Lang.Void data) /// /// Deserialize a /// - public static bool DeserializeBoolean(string topic, byte[] data) + public static bool DeserializeBoolean(bool fallbackToKafka, string topic, byte[] data) { - var result = _BooleanDeserializer.Deserialize(topic, data); - if (result is IJavaObject ijo) + if (data == null) return default; + if (fallbackToKafka) { - return JVMBridgeBase.Wraps(ijo); + var result = _BooleanDeserializer.Deserialize(topic, data); + if (result is IJavaObject ijo) + { + return JVMBridgeBase.WrapsDirect(ijo); + } + return (bool)result; } - return (bool)result; + return BitConverter.ToBoolean(data, 0); } /// /// Deserialize a /// - public static byte[] DeserializeByteArray(string topic, byte[] data) + public static byte[] DeserializeByteArray(bool fallbackToKafka, string topic, byte[] data) { return data; } @@ -366,60 +379,77 @@ public static byte[] DeserializeByteArray(string topic, byte[] data) /// /// Deserialize a /// - public static ByteBuffer DeserializeByteBuffer(string topic, byte[] data) + public static ByteBuffer DeserializeByteBuffer(bool fallbackToKafka, string topic, byte[] data) { - return JVMBridgeBase.Wraps(_ByteBufferDeserializer.Deserialize(topic, data) as IJavaObject); + if (data == null) return default; + return JVMBridgeBase.WrapsDirect(_ByteBufferDeserializer.Deserialize(topic, data) as IJavaObject); } static readonly BytesDeserializer _BytesDeserializer = new BytesDeserializer(); /// /// Deserialize a /// - public static Bytes DeserializeBytes(string topic, byte[] data) + public static Bytes DeserializeBytes(bool fallbackToKafka, string topic, byte[] data) { - return JVMBridgeBase.Wraps(_BytesDeserializer.Deserialize(topic, data) as IJavaObject); + if (data == null) return default; + return JVMBridgeBase.WrapsDirect(_BytesDeserializer.Deserialize(topic, data) as IJavaObject); } static readonly DoubleDeserializer _DoubleDeserializer = new DoubleDeserializer(); /// /// Deserialize a /// - public static double DeserializeDouble(string topic, byte[] data) + public static double DeserializeDouble(bool fallbackToKafka, string topic, byte[] data) { - var result = _DoubleDeserializer.Deserialize(topic, data); - if (result is IJavaObject ijo) + if (data == null) return default; + if (fallbackToKafka) { - return JVMBridgeBase.Wraps(ijo); + var result = _DoubleDeserializer.Deserialize(topic, data); + if (result is IJavaObject ijo) + { + return JVMBridgeBase.WrapsDirect(ijo); + } + return (double)result; } - return (double)result; + return BitConverter.ToDouble(data, 0); } static readonly FloatDeserializer _FloatDeserializer = new FloatDeserializer(); /// /// Deserialize a /// - public static float DeserializeFloat(string topic, byte[] data) + public static float DeserializeFloat(bool fallbackToKafka, string topic, byte[] data) { - var result = _FloatDeserializer.Deserialize(topic, data); - if (result is IJavaObject ijo) + if (data == null) return default; + if (fallbackToKafka) { - return JVMBridgeBase.Wraps(ijo); + var result = _FloatDeserializer.Deserialize(topic, data); + if (result is IJavaObject ijo) + { + return JVMBridgeBase.WrapsDirect(ijo); + } + return (float)result; } - return (float)result; + return BitConverter.ToSingle(data, 0); } static readonly IntegerDeserializer _IntDeserializer = new IntegerDeserializer(); /// /// Deserialize a /// - public static int DeserializeInt(string topic, byte[] data) + public static int DeserializeInt(bool fallbackToKafka, string topic, byte[] data) { - var result = _IntDeserializer.Deserialize(topic, data); - if (result is IJavaObject ijo) + if (data == null) return default; + if (fallbackToKafka) { - return JVMBridgeBase.Wraps(ijo); + var result = _IntDeserializer.Deserialize(topic, data); + if (result is IJavaObject ijo) + { + return JVMBridgeBase.WrapsDirect(ijo); + } + return (int)result; } - return (int)result; + return BitConverter.ToInt32(data, 0); //if (data == null) //{ @@ -451,14 +481,19 @@ public static int DeserializeInt(string topic, byte[] data) /// /// Deserialize a /// - public static long DeserializeLong(string topic, byte[] data) + public static long DeserializeLong(bool fallbackToKafka, string topic, byte[] data) { - var result = _LongDeserializer.Deserialize(topic, data); - if (result is IJavaObject ijo) + if (data == null) return default; + if (fallbackToKafka) { - return JVMBridgeBase.Wraps(ijo); + var result = _LongDeserializer.Deserialize(topic, data); + if (result is IJavaObject ijo) + { + return JVMBridgeBase.WrapsDirect(ijo); + } + return (long)result; } - return (long)result; + return BitConverter.ToInt64(data, 0); //if (data == null) //{ @@ -490,14 +525,19 @@ public static long DeserializeLong(string topic, byte[] data) /// /// Deserialize a /// - public static short DeserializeShort(string topic, byte[] data) + public static short DeserializeShort(bool fallbackToKafka, string topic, byte[] data) { - var result = _ShortDeserializer.Deserialize(topic, data); - if (result is IJavaObject ijo) + if (data == null) return default; + if (fallbackToKafka) { - return JVMBridgeBase.Wraps(ijo); + var result = _ShortDeserializer.Deserialize(topic, data); + if (result is IJavaObject ijo) + { + return JVMBridgeBase.WrapsDirect(ijo); + } + return (short)result; } - return (short)result; + return BitConverter.ToInt16(data, 0); //if (data == null) //{ @@ -527,21 +567,23 @@ public static short DeserializeShort(string topic, byte[] data) /// /// Deserialize a /// - public static string DeserializeString(string topic, byte[] data) + public static string DeserializeString(bool fallbackToKafka, string topic, byte[] data) { + if (data == null) return default; return Encoding.UTF8.GetString(data); } /// /// Deserialize a /// - public static Guid DeserializeGuid(string topic, byte[] data) + public static Guid DeserializeGuid(bool fallbackToKafka, string topic, byte[] data) { + if (data == null) return Guid.Empty; return new Guid(data); } /// /// Deserialize a /// - public static Java.Lang.Void DeserializeVoid(string topic, byte[] data) + public static Java.Lang.Void DeserializeVoid(bool fallbackToKafka, string topic, byte[] data) { if (data != null) { From b1144239ef9fd5e0e8bec74cf491d4145ceda559 Mon Sep 17 00:00:00 2001 From: masesdevelopers <94312179+masesdevelopers@users.noreply.github.com> Date: Sun, 12 May 2024 17:41:04 +0200 Subject: [PATCH 3/6] Updates to JCOBridge 2.5.13 --- src/net/Common/Common.props | 2 +- .../Apache/Kafka/Clients/Consumer/InvalidOffsetException.cs | 3 +-- .../Apache/Kafka/Clients/Consumer/LogTruncationException.cs | 2 +- .../Kafka/Clients/Consumer/OffsetOutOfRangeException.cs | 2 +- .../Org/Apache/Kafka/Common/Errors/InvalidTopicException.cs | 2 +- .../KNet/Developed/Org/Apache/Kafka/Common/Header/Header.cs | 4 ++-- .../Developed/Org/Apache/Kafka/Common/Header/Headers.cs | 6 +++--- src/net/KNet/Specific/PrefetchableEnumeratorSettings.cs | 3 +++ 8 files changed, 13 insertions(+), 11 deletions(-) diff --git a/src/net/Common/Common.props b/src/net/Common/Common.props index a09eafad65..353cf3973d 100644 --- a/src/net/Common/Common.props +++ b/src/net/Common/Common.props @@ -22,7 +22,7 @@ true - net462;net6.0;net7.0;net8.0 + net462;net6.0;net8.0 false diff --git a/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/InvalidOffsetException.cs b/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/InvalidOffsetException.cs index 429b0d4e49..c9e2842706 100644 --- a/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/InvalidOffsetException.cs +++ b/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/InvalidOffsetException.cs @@ -20,7 +20,6 @@ using MASES.JCOBridge.C2JBridge.JVMInterop; using Org.Apache.Kafka.Common; using Java.Util; -using static System.Net.WebRequestMethods; namespace Org.Apache.Kafka.Clients.Consumer { @@ -29,6 +28,6 @@ public partial class InvalidOffsetException /// /// /// - public Set Partitions => JVMBridgeBase.Wraps>(BridgeInstance.Invoke("partitions") as IJavaObject); + public Set Partitions => JVMBridgeBase.WrapsDirect>(BridgeInstance.Invoke("partitions") as IJavaObject); } } diff --git a/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/LogTruncationException.cs b/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/LogTruncationException.cs index b77c4e15b9..f4a25505c8 100644 --- a/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/LogTruncationException.cs +++ b/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/LogTruncationException.cs @@ -29,6 +29,6 @@ public partial class LogTruncationException /// /// /// - public Map DivergentOffsets => JVMBridgeBase.Wraps>(BridgeInstance.Invoke("divergentOffsets") as IJavaObject); + public Map DivergentOffsets => JVMBridgeBase.WrapsDirect>(BridgeInstance.Invoke("divergentOffsets") as IJavaObject); } } diff --git a/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/OffsetOutOfRangeException.cs b/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/OffsetOutOfRangeException.cs index 0a02f6f10f..3ae0210f9d 100644 --- a/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/OffsetOutOfRangeException.cs +++ b/src/net/KNet/Developed/Org/Apache/Kafka/Clients/Consumer/OffsetOutOfRangeException.cs @@ -29,6 +29,6 @@ public partial class OffsetOutOfRangeException /// /// /// - public Map OffsetOutOfRangePartitions => JVMBridgeBase.Wraps>(BridgeInstance.Invoke("offsetOutOfRangePartitions") as IJavaObject); + public Map OffsetOutOfRangePartitions => JVMBridgeBase.WrapsDirect>(BridgeInstance.Invoke("offsetOutOfRangePartitions") as IJavaObject); } } diff --git a/src/net/KNet/Developed/Org/Apache/Kafka/Common/Errors/InvalidTopicException.cs b/src/net/KNet/Developed/Org/Apache/Kafka/Common/Errors/InvalidTopicException.cs index eb99c46823..bef8e4144c 100644 --- a/src/net/KNet/Developed/Org/Apache/Kafka/Common/Errors/InvalidTopicException.cs +++ b/src/net/KNet/Developed/Org/Apache/Kafka/Common/Errors/InvalidTopicException.cs @@ -30,7 +30,7 @@ public partial class InvalidTopicException /// public Set InvalidTopics() { - return JVMBridgeBase.Wraps>(BridgeInstance.Invoke("invalidTopics") as IJavaObject); + return JVMBridgeBase.WrapsDirect>(BridgeInstance.Invoke("invalidTopics") as IJavaObject); } } } diff --git a/src/net/KNet/Developed/Org/Apache/Kafka/Common/Header/Header.cs b/src/net/KNet/Developed/Org/Apache/Kafka/Common/Header/Header.cs index ce712a75cf..f9d05f5900 100644 --- a/src/net/KNet/Developed/Org/Apache/Kafka/Common/Header/Header.cs +++ b/src/net/KNet/Developed/Org/Apache/Kafka/Common/Header/Header.cs @@ -29,7 +29,7 @@ public partial class Header public static Header Create(string key, byte[] value) { var obj = MASES.JCOBridge.C2JBridge.JCOBridge.Global.JVM.New("org.apache.kafka.common.header.internals.RecordHeader", key, value) as IJavaObject; - return Wraps
(obj); + return WrapsDirect
(obj); } /// /// Helper to create @@ -37,7 +37,7 @@ public static Header Create(string key, byte[] value) public static Header Create(ByteBuffer keyBuffer, ByteBuffer valueBuffer) { var obj = MASES.JCOBridge.C2JBridge.JCOBridge.Global.JVM.New("org.apache.kafka.common.header.internals.RecordHeader", keyBuffer, valueBuffer) as IJavaObject; - return Wraps
(obj); + return WrapsDirect
(obj); } } } diff --git a/src/net/KNet/Developed/Org/Apache/Kafka/Common/Header/Headers.cs b/src/net/KNet/Developed/Org/Apache/Kafka/Common/Header/Headers.cs index cd175fb25d..dc557f04dc 100644 --- a/src/net/KNet/Developed/Org/Apache/Kafka/Common/Header/Headers.cs +++ b/src/net/KNet/Developed/Org/Apache/Kafka/Common/Header/Headers.cs @@ -29,7 +29,7 @@ public partial class Headers public static Headers Create() { var obj = MASES.JCOBridge.C2JBridge.JCOBridge.Global.JVM.New("org.apache.kafka.common.header.internals.RecordHeaders") as IJavaObject; - return Wraps(obj); + return WrapsDirect(obj); } /// /// Helper to create @@ -37,7 +37,7 @@ public static Headers Create() public static Headers Create(Header[] headers) { var obj = MASES.JCOBridge.C2JBridge.JCOBridge.Global.JVM.New("org.apache.kafka.common.header.internals.RecordHeaders", headers) as IJavaObject; - return Wraps(obj); + return WrapsDirect(obj); } /// /// Helper to create @@ -45,7 +45,7 @@ public static Headers Create(Header[] headers) public static Headers Create(Iterable
headers) { var obj = MASES.JCOBridge.C2JBridge.JCOBridge.Global.JVM.New("org.apache.kafka.common.header.internals.RecordHeaders", headers) as IJavaObject; - return Wraps(obj); + return WrapsDirect(obj); } } } diff --git a/src/net/KNet/Specific/PrefetchableEnumeratorSettings.cs b/src/net/KNet/Specific/PrefetchableEnumeratorSettings.cs index b619f79eac..2bbf2ec5ad 100644 --- a/src/net/KNet/Specific/PrefetchableEnumeratorSettings.cs +++ b/src/net/KNet/Specific/PrefetchableEnumeratorSettings.cs @@ -17,6 +17,7 @@ */ using MASES.JCOBridge.C2JBridge; +using System.Threading; namespace MASES.KNet { @@ -26,9 +27,11 @@ public PrefetchableEnumeratorSettings() { UsePrefetch = true; UseThread = true; + ThreadPriority = ThreadPriority.AboveNormal; } public bool UsePrefetch { get; set; } public bool UseThread { get; set; } + public ThreadPriority ThreadPriority { get; set; } public IConverterBridge ConverterBridge { get; set; } } } From 1aa0d4eb3d4978227e1d59c63ae5b13106f2d875 Mon Sep 17 00:00:00 2001 From: masesdevelopers <94312179+masesdevelopers@users.noreply.github.com> Date: Wed, 15 May 2024 03:39:20 +0200 Subject: [PATCH 4/6] Added ByteBuffer based classes to optimize high volume of data between JVM and CLR --- .../serialization/ByteBufferDeserializer.java | 41 +++ .../serialization/ByteBufferSerializer.java | 74 ++++ .../knet/common/serialization/Serdes.java | 40 +++ src/net/KNet.Serialization.Avro/AvroSerDes.cs | 337 ++++++++++++++++-- src/net/KNet.Serialization.Json/JsonSerDes.cs | 313 ++++++++++++++-- .../MessagePackSerDes.cs | 139 +++++++- .../ProtobufSerDes.cs | 127 ++++++- .../Serialization/ByteBufferSupport.cs | 102 ++++++ src/net/KNet/Specific/Serialization/SerDes.cs | 221 ++++++++---- 9 files changed, 1241 insertions(+), 153 deletions(-) create mode 100644 src/jvm/knet/src/main/java/org/mases/knet/common/serialization/ByteBufferDeserializer.java create mode 100644 src/jvm/knet/src/main/java/org/mases/knet/common/serialization/ByteBufferSerializer.java create mode 100644 src/jvm/knet/src/main/java/org/mases/knet/common/serialization/Serdes.java create mode 100644 src/net/KNet/Specific/Serialization/ByteBufferSupport.cs diff --git a/src/jvm/knet/src/main/java/org/mases/knet/common/serialization/ByteBufferDeserializer.java b/src/jvm/knet/src/main/java/org/mases/knet/common/serialization/ByteBufferDeserializer.java new file mode 100644 index 0000000000..4b201a22cf --- /dev/null +++ b/src/jvm/knet/src/main/java/org/mases/knet/common/serialization/ByteBufferDeserializer.java @@ -0,0 +1,41 @@ +/* + * Copyright 2024 MASES s.r.l. + * + * Licensed 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. + * + * Refer to LICENSE for more information. + */ + +package org.mases.knet.common.serialization; + +import org.apache.kafka.common.serialization.Deserializer; +import org.mases.jcobridge.JCSharedBuffer; + +import java.io.IOException; +import java.nio.ByteBuffer; + +public class ByteBufferDeserializer implements Deserializer { + + @Override + public ByteBuffer deserialize(String topic, byte[] data) { + if (data == null) + return null; + + try { + return JCSharedBuffer.Create(data); + } catch (IOException e) { + // fallback to non buffered version + return ByteBuffer.wrap(data); + } + } +} diff --git a/src/jvm/knet/src/main/java/org/mases/knet/common/serialization/ByteBufferSerializer.java b/src/jvm/knet/src/main/java/org/mases/knet/common/serialization/ByteBufferSerializer.java new file mode 100644 index 0000000000..345260e081 --- /dev/null +++ b/src/jvm/knet/src/main/java/org/mases/knet/common/serialization/ByteBufferSerializer.java @@ -0,0 +1,74 @@ +/* + * Copyright 2024 MASES s.r.l. + * + * Licensed 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. + * + * Refer to LICENSE for more information. + */ + +package org.mases.knet.common.serialization; + +import org.apache.kafka.common.serialization.Serializer; +import org.mases.jcobridge.JCSharedBuffer; + +import java.io.IOException; +import java.nio.ByteBuffer; + +/** + * {@code ByteBufferSerializer} always {@link ByteBuffer#rewind() rewinds} the position of the input buffer to zero for + * serialization. A manual rewind is not necessary. + *

+ * Note: any existing buffer position is ignored. + *

+ * The position is also rewound back to zero before {@link #serialize(String, ByteBuffer)} + * returns. + */ +public class ByteBufferSerializer implements Serializer { + public byte[] serialize(String topic, ByteBuffer data) { + if (data == null) + return null; + + try { + try (JCSharedBuffer sb = JCSharedBuffer.Create(data)) { + sb.rewind(); + + if (sb.hasArray()) { + byte[] arr = sb.array(); + if (sb.arrayOffset() == 0 && arr.length == sb.remaining()) { + return arr; + } + } + + byte[] ret = new byte[data.remaining()]; + sb.get(ret, 0, ret.length); + sb.rewind(); + return ret; + } + } catch (IOException iae) { + // fallback to non buffered version + data.rewind(); + + if (data.hasArray()) { + byte[] arr = data.array(); + if (data.arrayOffset() == 0 && arr.length == data.remaining()) { + return arr; + } + } + + byte[] ret = new byte[data.remaining()]; + data.get(ret, 0, ret.length); + data.rewind(); + return ret; + } + } +} diff --git a/src/jvm/knet/src/main/java/org/mases/knet/common/serialization/Serdes.java b/src/jvm/knet/src/main/java/org/mases/knet/common/serialization/Serdes.java new file mode 100644 index 0000000000..97bedf1aca --- /dev/null +++ b/src/jvm/knet/src/main/java/org/mases/knet/common/serialization/Serdes.java @@ -0,0 +1,40 @@ +/* + * Copyright 2024 MASES s.r.l. + * + * Licensed 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. + * + * Refer to LICENSE for more information. + */ + +package org.mases.knet.common.serialization; + +import org.apache.kafka.common.serialization.Serde; + +import java.nio.ByteBuffer; + +public class Serdes { + static public final class ByteBufferSerde extends org.apache.kafka.common.serialization.Serdes.WrapperSerde { + public ByteBufferSerde() { + super(new ByteBufferSerializer(), new ByteBufferDeserializer()); + } + } + + /** + * A serde for nullable {@code ByteBuffer} type. + * + * @return {@link Serde} of {@link ByteBuffer} + */ + static public Serde ByteBuffer() { + return new ByteBufferSerde(); + } +} diff --git a/src/net/KNet.Serialization.Avro/AvroSerDes.cs b/src/net/KNet.Serialization.Avro/AvroSerDes.cs index 2099547a94..a8c425aadc 100644 --- a/src/net/KNet.Serialization.Avro/AvroSerDes.cs +++ b/src/net/KNet.Serialization.Avro/AvroSerDes.cs @@ -19,6 +19,7 @@ using global::Avro; using global::Avro.IO; using global::Avro.Specific; +using Java.Nio; using Org.Apache.Kafka.Common.Header; using System; using System.IO; @@ -27,7 +28,7 @@ namespace MASES.KNet.Serialization.Avro { ///

- /// Base class to define extensions of for Avro, for example + /// Base class to define extensions of for Avro, for example /// public static class AvroSerDes { @@ -70,15 +71,15 @@ public static void BuildSchemaClassesFromFiles(string outputFolder, params strin } /// - /// Base class to define Key extensions of , for example + /// Base class to define Key extensions of , for example /// public static class Key { /// - /// Avro Key extension of for Binary encoding, for example + /// Avro Key extension of for Binary encoding, for example /// /// - public class Binary : SerDes where T : global::Avro.Specific.ISpecificRecord, new() + public class BinaryRaw : SerDes where T : global::Avro.Specific.ISpecificRecord, new() { global::Avro.Schema _schema; /// @@ -98,14 +99,14 @@ private set SpecificDefaultWriter SpecificWriter = null; SpecificDefaultReader SpecificReader = null; - readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(Binary<>).ToAssemblyQualified()); + readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(BinaryRaw<>).ToAssemblyQualified()); readonly byte[] keyTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); /// public override bool UseHeaders => true; /// /// Default initializer /// - public Binary() + public BinaryRaw() { var tRecord = new T(); Schema = tRecord.Schema; @@ -126,12 +127,12 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat SpecificWriter.Write(data, encoder); return memStream.ToArray(); } - /// + /// public override T Deserialize(string topic, byte[] data) { return DeserializeWithHeaders(topic, null, data); } - /// + /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { if (data == null) return default; @@ -144,10 +145,10 @@ public override T DeserializeWithHeaders(string topic, Headers headers, byte[] d } } /// - /// Avro Key extension of for Json encoding, for example + /// Avro Key extension of for Binary encoding, for example /// /// - public class Json : SerDes where T : global::Avro.Specific.ISpecificRecord, new() + public class BinaryBuffered : SerDes where T : global::Avro.Specific.ISpecificRecord, new() { global::Avro.Schema _schema; /// @@ -167,14 +168,84 @@ private set SpecificDefaultWriter SpecificWriter = null; SpecificDefaultReader SpecificReader = null; - readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(Json<>).ToAssemblyQualified()); + readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(BinaryBuffered<>).ToAssemblyQualified()); readonly byte[] keyTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); /// public override bool UseHeaders => true; + /// + public override bool IsDirectBuffered => true; /// /// Default initializer /// - public Json() + public BinaryBuffered() + { + var tRecord = new T(); + Schema = tRecord.Schema; + } + /// + public override Java.Nio.ByteBuffer Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } + /// + public override Java.Nio.ByteBuffer SerializeWithHeaders(string topic, Headers headers, T data) + { + headers?.Add(KNetSerialization.KeyTypeIdentifier, keyTypeName); + headers?.Add(KNetSerialization.KeySerializerIdentifier, keySerDesName); + + MemoryStream memStream = new(); + BinaryEncoder encoder = new(memStream); + SpecificWriter.Write(data, encoder); + return ByteBuffer.From(memStream); + } + /// + public override T Deserialize(string topic, Java.Nio.ByteBuffer data) + { + return DeserializeWithHeaders(topic, null, data); + } + /// + public override T DeserializeWithHeaders(string topic, Headers headers, Java.Nio.ByteBuffer data) + { + if (data == null) return default; + + BinaryDecoder decoder = new(data.ToStream()); + T t = new T(); + t = SpecificReader.Read(t!, decoder); + return t; + } + } + /// + /// Avro Key extension of for Json encoding, for example + /// + /// + public class JsonRaw : SerDes where T : global::Avro.Specific.ISpecificRecord, new() + { + global::Avro.Schema _schema; + /// + /// Use this property to get the of + /// + public global::Avro.Schema Schema + { + get { return _schema; } + private set + { + _schema = value; + SpecificWriter = new SpecificDefaultWriter(_schema); + SpecificReader = new SpecificDefaultReader(_schema, _schema); + } + } + + SpecificDefaultWriter SpecificWriter = null; + SpecificDefaultReader SpecificReader = null; + + readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(JsonRaw<>).ToAssemblyQualified()); + readonly byte[] keyTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); + /// + public override bool UseHeaders => true; + /// + /// Default initializer + /// + public JsonRaw() { var tRecord = new T(); Schema = tRecord.Schema; @@ -195,12 +266,12 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat SpecificWriter.Write(data, encoder); return memStream.ToArray(); } - /// + /// public override T Deserialize(string topic, byte[] data) { return DeserializeWithHeaders(topic, null, data); } - /// + /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { if (data == null) return default; @@ -212,18 +283,88 @@ public override T DeserializeWithHeaders(string topic, Headers headers, byte[] d return t; } } + /// + /// Avro Key extension of for Json encoding, for example + /// + /// + public class JsonBuffered : SerDes where T : global::Avro.Specific.ISpecificRecord, new() + { + global::Avro.Schema _schema; + /// + /// Use this property to get the of + /// + public global::Avro.Schema Schema + { + get { return _schema; } + private set + { + _schema = value; + SpecificWriter = new SpecificDefaultWriter(_schema); + SpecificReader = new SpecificDefaultReader(_schema, _schema); + } + } + + SpecificDefaultWriter SpecificWriter = null; + SpecificDefaultReader SpecificReader = null; + + readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(JsonBuffered<>).ToAssemblyQualified()); + readonly byte[] keyTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); + /// + public override bool UseHeaders => true; + /// + public override bool IsDirectBuffered => true; + /// + /// Default initializer + /// + public JsonBuffered() + { + var tRecord = new T(); + Schema = tRecord.Schema; + } + /// + public override Java.Nio.ByteBuffer Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } + /// + public override Java.Nio.ByteBuffer SerializeWithHeaders(string topic, Headers headers, T data) + { + headers?.Add(KNetSerialization.KeyTypeIdentifier, keyTypeName); + headers?.Add(KNetSerialization.KeySerializerIdentifier, keySerDesName); + + MemoryStream memStream = new(); + JsonEncoder encoder = new(Schema, memStream); + SpecificWriter.Write(data, encoder); + return ByteBuffer.From(memStream); + } + /// + public override T Deserialize(string topic, Java.Nio.ByteBuffer data) + { + return DeserializeWithHeaders(topic, null, data); + } + /// + public override T DeserializeWithHeaders(string topic, Headers headers, Java.Nio.ByteBuffer data) + { + if (data == null) return default; + + JsonDecoder decoder = new(Schema, data.ToStream()); + T t = new T(); + t = SpecificReader.Read(t!, decoder); + return t; + } + } } /// - /// Base class to define Value extensions of , for example + /// Base class to define Value extensions of , for example /// public static class Value { /// - /// Avro Value extension of for Binary encoding, for example + /// Avro Value extension of for Binary encoding, for example /// /// - public class Binary : SerDes where T : global::Avro.Specific.ISpecificRecord, new() + public class BinaryRaw : SerDes where T : global::Avro.Specific.ISpecificRecord, new() { global::Avro.Schema _schema; /// @@ -243,14 +384,14 @@ private set SpecificDefaultWriter SpecificWriter = null; SpecificDefaultReader SpecificReader = null; - readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(Binary<>).ToAssemblyQualified()); + readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(BinaryRaw<>).ToAssemblyQualified()); readonly byte[] valueTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); /// public override bool UseHeaders => true; /// /// Default initializer /// - public Binary() + public BinaryRaw() { var tRecord = new T(); Schema = tRecord.Schema; @@ -266,17 +407,17 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat headers?.Add(KNetSerialization.ValueSerializerIdentifier, valueSerDesName); headers?.Add(KNetSerialization.ValueTypeIdentifier, valueTypeName); - using MemoryStream memStream = new(); + MemoryStream memStream = new(); BinaryEncoder encoder = new(memStream); SpecificWriter.Write(data, encoder); return memStream.ToArray(); } - /// + /// public override T Deserialize(string topic, byte[] data) { return DeserializeWithHeaders(topic, null, data); } - /// + /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { if (data == null) return default; @@ -289,10 +430,10 @@ public override T DeserializeWithHeaders(string topic, Headers headers, byte[] d } } /// - /// Avro Value extension of for Json encoding, for example + /// Avro Value extension of for Binary encoding, for example /// /// - public class Json : SerDes where T : global::Avro.Specific.ISpecificRecord, new() + public class BinaryBuffered : SerDes where T : global::Avro.Specific.ISpecificRecord, new() { global::Avro.Schema _schema; /// @@ -312,14 +453,84 @@ private set SpecificDefaultWriter SpecificWriter = null; SpecificDefaultReader SpecificReader = null; - readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(Json<>).ToAssemblyQualified()); + readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(BinaryBuffered<>).ToAssemblyQualified()); + readonly byte[] valueTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); + /// + public override bool UseHeaders => true; + /// + public override bool IsDirectBuffered => true; + /// + /// Default initializer + /// + public BinaryBuffered() + { + var tRecord = new T(); + Schema = tRecord.Schema; + } + /// + public override Java.Nio.ByteBuffer Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } + /// + public override Java.Nio.ByteBuffer SerializeWithHeaders(string topic, Headers headers, T data) + { + headers?.Add(KNetSerialization.ValueSerializerIdentifier, valueSerDesName); + headers?.Add(KNetSerialization.ValueTypeIdentifier, valueTypeName); + + MemoryStream memStream = new(); + BinaryEncoder encoder = new(memStream); + SpecificWriter.Write(data, encoder); + return ByteBuffer.From(memStream); + } + /// + public override T Deserialize(string topic, Java.Nio.ByteBuffer data) + { + return DeserializeWithHeaders(topic, null, data); + } + /// + public override T DeserializeWithHeaders(string topic, Headers headers, Java.Nio.ByteBuffer data) + { + if (data == null) return default; + + BinaryDecoder decoder = new(data.ToStream()); + T t = new T(); + t = SpecificReader.Read(t!, decoder); + return t; + } + } + /// + /// Avro Value extension of for Json encoding, for example + /// + /// + public class JsonRaw : SerDes where T : global::Avro.Specific.ISpecificRecord, new() + { + global::Avro.Schema _schema; + /// + /// Use this property to get the of + /// + public global::Avro.Schema Schema + { + get { return _schema; } + private set + { + _schema = value; + SpecificWriter = new SpecificDefaultWriter(_schema); + SpecificReader = new SpecificDefaultReader(_schema, _schema); + } + } + + SpecificDefaultWriter SpecificWriter = null; + SpecificDefaultReader SpecificReader = null; + + readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(JsonRaw<>).ToAssemblyQualified()); readonly byte[] valueTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); /// public override bool UseHeaders => true; /// /// Default initializer /// - public Json() + public JsonRaw() { var tRecord = new T(); Schema = tRecord.Schema; @@ -340,12 +551,12 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat SpecificWriter.Write(data, encoder); return memStream.ToArray(); } - /// + /// public override T Deserialize(string topic, byte[] data) { return DeserializeWithHeaders(topic, null, data); } - /// + /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { if (data == null) return default; @@ -357,6 +568,76 @@ public override T DeserializeWithHeaders(string topic, Headers headers, byte[] d return t; } } + /// + /// Avro Value extension of for Json encoding, for example + /// + /// + public class JsonBuffered : SerDes where T : global::Avro.Specific.ISpecificRecord, new() + { + global::Avro.Schema _schema; + /// + /// Use this property to get the of + /// + public global::Avro.Schema Schema + { + get { return _schema; } + private set + { + _schema = value; + SpecificWriter = new SpecificDefaultWriter(_schema); + SpecificReader = new SpecificDefaultReader(_schema, _schema); + } + } + + SpecificDefaultWriter SpecificWriter = null; + SpecificDefaultReader SpecificReader = null; + + readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(JsonBuffered<>).ToAssemblyQualified()); + readonly byte[] valueTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); + /// + public override bool UseHeaders => true; + /// + public override bool IsDirectBuffered => true; + /// + /// Default initializer + /// + public JsonBuffered() + { + var tRecord = new T(); + Schema = tRecord.Schema; + } + /// + public override Java.Nio.ByteBuffer Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } + /// + public override Java.Nio.ByteBuffer SerializeWithHeaders(string topic, Headers headers, T data) + { + headers?.Add(KNetSerialization.ValueSerializerIdentifier, valueSerDesName); + headers?.Add(KNetSerialization.ValueTypeIdentifier, valueTypeName); + + MemoryStream memStream = new(); + JsonEncoder encoder = new(Schema, memStream); + SpecificWriter.Write(data, encoder); + return ByteBuffer.From(memStream); + } + /// + public override T Deserialize(string topic, Java.Nio.ByteBuffer data) + { + return DeserializeWithHeaders(topic, null, data); + } + /// + public override T DeserializeWithHeaders(string topic, Headers headers, Java.Nio.ByteBuffer data) + { + if (data == null) return default; + + JsonDecoder decoder = new(Schema, data.ToStream()); + T t = new T(); + t = SpecificReader.Read(t!, decoder); + return t; + } + } } } } diff --git a/src/net/KNet.Serialization.Json/JsonSerDes.cs b/src/net/KNet.Serialization.Json/JsonSerDes.cs index 9828873667..fda92c6e44 100644 --- a/src/net/KNet.Serialization.Json/JsonSerDes.cs +++ b/src/net/KNet.Serialization.Json/JsonSerDes.cs @@ -16,36 +16,55 @@ * Refer to LICENSE for more information. */ +using Java.Nio; using Org.Apache.Kafka.Common.Header; using System; +using System.Diagnostics.Eventing.Reader; +using System.IO; using System.Text; +#if NET462_OR_GREATER +using Newtonsoft.Json; +#else +using System.Text.Json; +#endif namespace MASES.KNet.Serialization.Json { /// - /// Base class to define extensions of for Json, for example + /// Base class to define extensions of for Json, for example /// public static class JsonSerDes { /// - /// Json extension of for Key, for example + /// Json extension of for Key, for example /// /// - public class Key : SerDes + public class KeyRaw : SerDes { - readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(Key<>).ToAssemblyQualified()); + readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(KeyRaw<>).ToAssemblyQualified()); readonly byte[] keyTypeName = null; - readonly ISerDes _defaultSerDes = default!; + readonly ISerDes _defaultSerDes = default!; +#if NET462_OR_GREATER + /// + /// Settings used from and + /// + public JsonSerializerSettings Options { get; set; } = new JsonSerializerSettings(); +#else + /// + /// Settings used from and + /// + public JsonSerializerOptions Options { get; set; } = new JsonSerializerOptions(); +#endif /// public override bool UseHeaders => true; /// /// Default initializer /// - public Key() + public KeyRaw() { if (KNetSerialization.IsInternalManaged()) { - _defaultSerDes = new SerDes(); + _defaultSerDes = new SerDes(); keyTypeName = Encoding.UTF8.GetBytes(typeof(T).FullName!); } else @@ -67,51 +86,178 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat if (_defaultSerDes != null) return _defaultSerDes.SerializeWithHeaders(topic, headers, data); #if NET462_OR_GREATER - var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.None); + var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(data, Options); return Encoding.UTF8.GetBytes(jsonStr); #else - var jsonStr = System.Text.Json.JsonSerializer.Serialize(data); + var jsonStr = System.Text.Json.JsonSerializer.Serialize(data, Options); return Encoding.UTF8.GetBytes(jsonStr); #endif } - /// + /// public override T Deserialize(string topic, byte[] data) { return DeserializeWithHeaders(topic, null, data); } - /// + /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { if (_defaultSerDes != null) return _defaultSerDes.DeserializeWithHeaders(topic, headers, data); if (data == null) return default; #if NET462_OR_GREATER var jsonStr = Encoding.UTF8.GetString(data); - return Newtonsoft.Json.JsonConvert.DeserializeObject(jsonStr); + return Newtonsoft.Json.JsonConvert.DeserializeObject(jsonStr, Options); +#else + return System.Text.Json.JsonSerializer.Deserialize(data, Options)!; +#endif + } + } + + /// + /// Json extension of for Key, for example + /// + /// + public class KeyBuffered : SerDes + { +#if NET462_OR_GREATER + readonly Newtonsoft.Json.JsonSerializer _serializer; +#endif + readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(KeyBuffered<>).ToAssemblyQualified()); + readonly byte[] keyTypeName = null; + readonly ISerDes _defaultSerDes = default!; +#if NET462_OR_GREATER + /// + /// When set to the oprion forces to use with to reduce memory copy + /// + /// Added specifically to .NET Framework because NewtonSoft JSon seems to have problems with large streams + public bool UseStreamWithByteBuffer { get; set; } = true; + /// + /// Settings used from and + /// + public JsonSerializerSettings Options { get; set; } = new JsonSerializerSettings(); +#else + /// + /// Settings used from and + /// + public JsonSerializerOptions Options { get; set; } = new JsonSerializerOptions(); +#endif + /// + public override bool UseHeaders => true; + /// + public override bool IsDirectBuffered => true; + /// + /// Default initializer + /// + public KeyBuffered() + { + if (KNetSerialization.IsInternalManaged()) + { + _defaultSerDes = new SerDes(); + keyTypeName = Encoding.UTF8.GetBytes(typeof(T).FullName!); + } + else + { +#if NET462_OR_GREATER + _serializer = new Newtonsoft.Json.JsonSerializer(); + _serializer.Formatting = Newtonsoft.Json.Formatting.None; +#endif + keyTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); + } + } + /// + public override Java.Nio.ByteBuffer Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } + /// + public override Java.Nio.ByteBuffer SerializeWithHeaders(string topic, Headers headers, T data) + { + headers?.Add(KNetSerialization.KeyTypeIdentifier, keyTypeName); + headers?.Add(KNetSerialization.KeySerializerIdentifier, keySerDesName); + + if (_defaultSerDes != null) return _defaultSerDes.SerializeWithHeaders(topic, headers, data); + +#if NET462_OR_GREATER + if (UseStreamWithByteBuffer) + { + var ms = new MemoryStream(); + using (StreamWriter sw = new StreamWriter(ms, new UTF8Encoding(false), 128, true)) + using (Newtonsoft.Json.JsonWriter writer = new Newtonsoft.Json.JsonTextWriter(sw)) + { + _serializer.Serialize(writer, data); + } + return ByteBuffer.From(ms); + } + else + { + var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(data, Options); + return ByteBuffer.From(Encoding.UTF8.GetBytes(jsonStr)); + } +#else + var ms = new MemoryStream(); + System.Text.Json.JsonSerializer.Serialize(ms, data, Options); + return ByteBuffer.From(ms); +#endif + } + /// + public override T Deserialize(string topic, Java.Nio.ByteBuffer data) + { + return DeserializeWithHeaders(topic, null, data); + } + /// + public override T DeserializeWithHeaders(string topic, Headers headers, Java.Nio.ByteBuffer data) + { + if (_defaultSerDes != null) return _defaultSerDes.DeserializeWithHeaders(topic, headers, data); + if (data == null) return default; +#if NET462_OR_GREATER + if (UseStreamWithByteBuffer) + { + using (StreamReader sw = new StreamReader(data.ToStream())) + using (Newtonsoft.Json.JsonReader reader = new Newtonsoft.Json.JsonTextReader(sw)) + { + return _serializer.Deserialize(reader); + } + } + else + { + var jsonStr = Encoding.UTF8.GetString((byte[])data); + return Newtonsoft.Json.JsonConvert.DeserializeObject(jsonStr, Options); + } #else - return System.Text.Json.JsonSerializer.Deserialize(data)!; + return System.Text.Json.JsonSerializer.Deserialize(data.ToStream(), Options)!; #endif } } /// - /// Json extension of for Value, for example + /// Json extension of for Value, for example /// /// - public class Value : SerDes + public class ValueRaw : SerDes { - readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(Value<>).ToAssemblyQualified()); + readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(ValueRaw<>).ToAssemblyQualified()); readonly byte[] valueTypeName = null!; - readonly ISerDes _defaultSerDes = default!; + readonly ISerDes _defaultSerDes = default!; +#if NET462_OR_GREATER + /// + /// Settings used from and + /// + public JsonSerializerSettings Options { get; set; } = new JsonSerializerSettings(); +#else + /// + /// Settings used from and + /// + public JsonSerializerOptions Options { get; set; } = new JsonSerializerOptions(); +#endif /// public override bool UseHeaders => true; /// /// Default initializer /// - public Value() + public ValueRaw() { if (KNetSerialization.IsInternalManaged()) { - _defaultSerDes = new SerDes(); + _defaultSerDes = new SerDes(); valueTypeName = Encoding.UTF8.GetBytes(typeof(T).FullName!); } else @@ -133,19 +279,19 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat if (_defaultSerDes != null) return _defaultSerDes.SerializeWithHeaders(topic, headers, data); #if NET462_OR_GREATER - var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(data, Newtonsoft.Json.Formatting.None); + var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(data, Options); return Encoding.UTF8.GetBytes(jsonStr); #else - var jsonStr = System.Text.Json.JsonSerializer.Serialize(data); + var jsonStr = System.Text.Json.JsonSerializer.Serialize(data, Options); return Encoding.UTF8.GetBytes(jsonStr); #endif } - /// + /// public override T Deserialize(string topic, byte[] data) { return DeserializeWithHeaders(topic, null, data); } - /// + /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { if (_defaultSerDes != null) return _defaultSerDes.DeserializeWithHeaders(topic, headers, data); @@ -153,9 +299,126 @@ public override T DeserializeWithHeaders(string topic, Headers headers, byte[] d if (data == null) return default; #if NET462_OR_GREATER var jsonStr = Encoding.UTF8.GetString(data); - return Newtonsoft.Json.JsonConvert.DeserializeObject(jsonStr); + return Newtonsoft.Json.JsonConvert.DeserializeObject(jsonStr, Options); +#else + return System.Text.Json.JsonSerializer.Deserialize(data, Options)!; +#endif + } + } + + /// + /// Json extension of for Value, for example + /// + /// + public class ValueBuffered : SerDes + { +#if NET462_OR_GREATER + readonly Newtonsoft.Json.JsonSerializer _serializer; +#endif + readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(ValueBuffered<>).ToAssemblyQualified()); + readonly byte[] valueTypeName = null!; + readonly ISerDes _defaultSerDes = default!; +#if NET462_OR_GREATER + /// + /// When set to the oprion forces to use with to reduce memory copy + /// + /// Added specifically to .NET Framework because NewtonSoft JSon seems to have problems with large streams + public bool UseByteBufferWithStream { get; set; } = true; + /// + /// Settings used from and + /// + public JsonSerializerSettings Options { get; set; } = new JsonSerializerSettings(); +#else + /// + /// Settings used from and + /// + public JsonSerializerOptions Options { get; set; } = new JsonSerializerOptions(); +#endif + /// + public override bool UseHeaders => true; + /// + public override bool IsDirectBuffered => true; + /// + /// Default initializer + /// + public ValueBuffered() + { + if (KNetSerialization.IsInternalManaged()) + { + _defaultSerDes = new SerDes(); + valueTypeName = Encoding.UTF8.GetBytes(typeof(T).FullName!); + } + else + { +#if NET462_OR_GREATER + _serializer = new Newtonsoft.Json.JsonSerializer(); + _serializer.Formatting = Newtonsoft.Json.Formatting.None; +#endif + valueTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); + } + } + /// + public override Java.Nio.ByteBuffer Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } + /// + public override Java.Nio.ByteBuffer SerializeWithHeaders(string topic, Headers headers, T data) + { + headers?.Add(KNetSerialization.ValueSerializerIdentifier, valueSerDesName); + headers?.Add(KNetSerialization.ValueTypeIdentifier, valueTypeName); + + if (_defaultSerDes != null) return _defaultSerDes.SerializeWithHeaders(topic, headers, data); + +#if NET462_OR_GREATER + if (UseByteBufferWithStream) + { + var ms = new MemoryStream(); + using (StreamWriter sw = new StreamWriter(ms, new UTF8Encoding(false), 128, true)) + using (Newtonsoft.Json.JsonWriter writer = new Newtonsoft.Json.JsonTextWriter(sw)) + { + _serializer.Serialize(writer, data); + } + return ByteBuffer.From(ms); + } + else + { + var jsonStr = Newtonsoft.Json.JsonConvert.SerializeObject(data, Options); + return ByteBuffer.From(Encoding.UTF8.GetBytes(jsonStr)); + } +#else + var ms = new MemoryStream(); + System.Text.Json.JsonSerializer.Serialize(ms, data, Options); + return ByteBuffer.From(ms); +#endif + } + /// + public override T Deserialize(string topic, Java.Nio.ByteBuffer data) + { + return DeserializeWithHeaders(topic, null, data); + } + /// + public override T DeserializeWithHeaders(string topic, Headers headers, Java.Nio.ByteBuffer data) + { + if (_defaultSerDes != null) return _defaultSerDes.DeserializeWithHeaders(topic, headers, data); + + if (data == null) return default; +#if NET462_OR_GREATER + if (UseByteBufferWithStream) + { + using (StreamReader sw = new StreamReader(data.ToStream())) + using (Newtonsoft.Json.JsonReader reader = new Newtonsoft.Json.JsonTextReader(sw)) + { + return _serializer.Deserialize(reader); + } + } + else + { + var jsonStr = Encoding.UTF8.GetString((byte[])data); + return Newtonsoft.Json.JsonConvert.DeserializeObject(jsonStr, Options); + } #else - return System.Text.Json.JsonSerializer.Deserialize(data)!; + return System.Text.Json.JsonSerializer.Deserialize(data.ToStream(), Options)!; #endif } } diff --git a/src/net/KNet.Serialization.MessagePack/MessagePackSerDes.cs b/src/net/KNet.Serialization.MessagePack/MessagePackSerDes.cs index d216d2780e..84022673fd 100644 --- a/src/net/KNet.Serialization.MessagePack/MessagePackSerDes.cs +++ b/src/net/KNet.Serialization.MessagePack/MessagePackSerDes.cs @@ -21,21 +21,22 @@ using System.IO; using System.Text; using System; +using Java.Nio; namespace MASES.KNet.Serialization.MessagePack { /// - /// Base class to define extensions of for MessagePack, for example + /// Base class to define extensions of for MessagePack, for example /// public static class MessagePackSerDes { /// - /// MessagePack extension of for Key, for example + /// MessagePack extension of for Key, for example /// /// - public class Key : SerDes + public class KeyRaw : SerDes { - readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(Key<>).ToAssemblyQualified()); + readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(KeyRaw<>).ToAssemblyQualified()); readonly byte[] keyTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); /// /// Get or set the to be used, default is @@ -46,11 +47,11 @@ public class Key : SerDes /// /// Default initializer /// - public Key() + public KeyRaw() { if (KNetSerialization.IsInternalManaged()) { - throw new InvalidOperationException($"{typeof(T).Name} is a type managed from basic serializer, do not use {typeof(Key).FullName}"); + throw new InvalidOperationException($"{typeof(T).Name} is a type managed from basic serializer, do not use {typeof(KeyRaw).FullName}"); } } /// @@ -66,12 +67,12 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat return MessagePackSerializer.Serialize(data, MessagePackSerializerOptions); } - /// + /// public override T Deserialize(string topic, byte[] data) { return DeserializeWithHeaders(topic, null, data); } - /// + /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { if (data == null) return default; @@ -83,12 +84,66 @@ public override T DeserializeWithHeaders(string topic, Headers headers, byte[] d } /// - /// MessagePack extension of for Value, for example + /// MessagePack extension of for Key, for example /// /// - public class Value : SerDes + public class KeyBuffered : SerDes { - readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(Value<>).ToAssemblyQualified()); + readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(KeyBuffered<>).ToAssemblyQualified()); + readonly byte[] keyTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); + /// + /// Get or set the to be used, default is + /// + public MessagePackSerializerOptions MessagePackSerializerOptions { get; set; } = null; + /// + public override bool UseHeaders => true; + /// + public override bool IsDirectBuffered => true; + /// + /// Default initializer + /// + public KeyBuffered() + { + if (KNetSerialization.IsInternalManaged()) + { + throw new InvalidOperationException($"{typeof(T).Name} is a type managed from basic serializer, do not use {typeof(KeyBuffered).FullName}"); + } + } + /// + public override Java.Nio.ByteBuffer Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } + /// + public override Java.Nio.ByteBuffer SerializeWithHeaders(string topic, Headers headers, T data) + { + headers?.Add(KNetSerialization.KeyTypeIdentifier, keyTypeName); + headers?.Add(KNetSerialization.KeySerializerIdentifier, keySerDesName); + + var ms = new MemoryStream(); + MessagePackSerializer.Serialize(ms, data, MessagePackSerializerOptions); + return ByteBuffer.From(ms); + } + /// + public override T Deserialize(string topic, Java.Nio.ByteBuffer data) + { + return DeserializeWithHeaders(topic, null, data); + } + /// + public override T DeserializeWithHeaders(string topic, Headers headers, Java.Nio.ByteBuffer data) + { + if (data == null) return default; + return MessagePackSerializer.Deserialize(data.ToStream(), MessagePackSerializerOptions); + } + } + + /// + /// MessagePack extension of for Value, for example + /// + /// + public class ValueRaw : SerDes + { + readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(ValueRaw<>).ToAssemblyQualified()); readonly byte[] valueTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); /// /// Get or set the to be used, default is @@ -99,11 +154,11 @@ public class Value : SerDes /// /// Default initializer /// - public Value() + public ValueRaw() { if (KNetSerialization.IsInternalManaged()) { - throw new InvalidOperationException($"{typeof(T).Name} is a type managed from basic serializer, do not use {typeof(Key).FullName}"); + throw new InvalidOperationException($"{typeof(T).Name} is a type managed from basic serializer, do not use {typeof(ValueRaw).FullName}"); } } /// @@ -119,12 +174,12 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat return MessagePackSerializer.Serialize(data, MessagePackSerializerOptions); } - /// + /// public override T Deserialize(string topic, byte[] data) { return DeserializeWithHeaders(topic, null, data); } - /// + /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { if (data == null) return default; @@ -134,5 +189,59 @@ public override T DeserializeWithHeaders(string topic, Headers headers, byte[] d } } } + + /// + /// MessagePack extension of for Value, for example + /// + /// + public class ValueBuffered : SerDes + { + readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(ValueBuffered<>).ToAssemblyQualified()); + readonly byte[] valueTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); + /// + /// Get or set the to be used, default is + /// + public MessagePackSerializerOptions MessagePackSerializerOptions { get; set; } = null; + /// + public override bool UseHeaders => true; + /// + public override bool IsDirectBuffered => true; + /// + /// Default initializer + /// + public ValueBuffered() + { + if (KNetSerialization.IsInternalManaged()) + { + throw new InvalidOperationException($"{typeof(T).Name} is a type managed from basic serializer, do not use {typeof(ValueBuffered).FullName}"); + } + } + /// + public override Java.Nio.ByteBuffer Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } + /// + public override Java.Nio.ByteBuffer SerializeWithHeaders(string topic, Headers headers, T data) + { + headers?.Add(KNetSerialization.ValueSerializerIdentifier, valueSerDesName); + headers?.Add(KNetSerialization.ValueTypeIdentifier, valueTypeName); + + var ms = new MemoryStream(); + MessagePackSerializer.Serialize(ms, data, MessagePackSerializerOptions); + return ByteBuffer.From(ms); + } + /// + public override T Deserialize(string topic, Java.Nio.ByteBuffer data) + { + return DeserializeWithHeaders(topic, null, data); + } + /// + public override T DeserializeWithHeaders(string topic, Headers headers, Java.Nio.ByteBuffer data) + { + if (data == null) return default; + return MessagePackSerializer.Deserialize(data.ToStream(), MessagePackSerializerOptions); + } + } } } diff --git a/src/net/KNet.Serialization.Protobuf/ProtobufSerDes.cs b/src/net/KNet.Serialization.Protobuf/ProtobufSerDes.cs index ed93d4f992..7f1762bac3 100644 --- a/src/net/KNet.Serialization.Protobuf/ProtobufSerDes.cs +++ b/src/net/KNet.Serialization.Protobuf/ProtobufSerDes.cs @@ -17,6 +17,7 @@ */ using Google.Protobuf; +using Java.Nio; using Org.Apache.Kafka.Common.Header; using System; using System.IO; @@ -26,25 +27,25 @@ namespace MASES.KNet.Serialization.Protobuf { /// - /// Base class to define extensions of for Protobuf, for example + /// Base class to define extensions of for Protobuf, for example /// public static class ProtobufSerDes { /// - /// Protobuf extension of for Key, for example + /// Protobuf extension of for Key, for example /// /// - public class Key : SerDes where T : IMessage, new() + public class KeyRaw : SerDes where T : IMessage, new() { readonly MessageParser _parser = new MessageParser(() => new T()); - readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(Key<>).ToAssemblyQualified()); + readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(KeyRaw<>).ToAssemblyQualified()); readonly byte[] keyTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); /// public override bool UseHeaders => true; /// /// Default initializer /// - public Key() + public KeyRaw() { } @@ -65,12 +66,12 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat return stream.ToArray(); } } - /// + /// public override T Deserialize(string topic, byte[] data) { return DeserializeWithHeaders(topic, null, data); } - /// + /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { if (data == null) return default; @@ -79,20 +80,70 @@ public override T DeserializeWithHeaders(string topic, Headers headers, byte[] d } /// - /// Protobuf extension of for Value, for example + /// Protobuf extension of for Key, for example /// /// - public class Value : SerDes where T : IMessage, new() + public class KeyBuffered : SerDes where T : IMessage, new() { readonly MessageParser _parser = new MessageParser(() => new T()); - readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(Value<>).ToAssemblyQualified()); + readonly byte[] keySerDesName = Encoding.UTF8.GetBytes(typeof(KeyBuffered<>).ToAssemblyQualified()); + readonly byte[] keyTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); + /// + public override bool UseHeaders => true; + /// + public override bool IsDirectBuffered => true; + /// + /// Default initializer + /// + public KeyBuffered() + { + + } + /// + public override Java.Nio.ByteBuffer Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } + /// + public override Java.Nio.ByteBuffer SerializeWithHeaders(string topic, Headers headers, T data) + { + headers?.Add(KNetSerialization.KeyTypeIdentifier, keyTypeName); + headers?.Add(KNetSerialization.KeySerializerIdentifier, keySerDesName); + + MemoryStream stream = new MemoryStream(); + { + data.WriteTo(stream); + return ByteBuffer.From(stream); + } + } + /// + public override T Deserialize(string topic, Java.Nio.ByteBuffer data) + { + return DeserializeWithHeaders(topic, null, data); + } + /// + public override T DeserializeWithHeaders(string topic, Headers headers, Java.Nio.ByteBuffer data) + { + if (data == null) return default; + return _parser.ParseFrom(data.ToStream()); + } + } + + /// + /// Protobuf extension of for Value, for example + /// + /// + public class ValueRaw : SerDes where T : IMessage, new() + { + readonly MessageParser _parser = new MessageParser(() => new T()); + readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(ValueRaw<>).ToAssemblyQualified()); readonly byte[] valueTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); /// public override bool UseHeaders => true; /// /// Default initializer /// - public Value() + public ValueRaw() { } @@ -113,17 +164,67 @@ public override byte[] SerializeWithHeaders(string topic, Headers headers, T dat return stream.ToArray(); } } - /// + /// public override T Deserialize(string topic, byte[] data) { return DeserializeWithHeaders(topic, null, data); } - /// + /// public override T DeserializeWithHeaders(string topic, Headers headers, byte[] data) { if (data == null) return default; return _parser.ParseFrom(data); } } + + /// + /// Protobuf extension of for Value, for example + /// + /// + public class ValueBuffered : SerDes where T : IMessage, new() + { + readonly MessageParser _parser = new MessageParser(() => new T()); + readonly byte[] valueSerDesName = Encoding.UTF8.GetBytes(typeof(ValueBuffered<>).ToAssemblyQualified()); + readonly byte[] valueTypeName = Encoding.UTF8.GetBytes(typeof(T).ToAssemblyQualified()); + /// + public override bool UseHeaders => true; + /// + public override bool IsDirectBuffered => true; + /// + /// Default initializer + /// + public ValueBuffered() + { + + } + /// + public override Java.Nio.ByteBuffer Serialize(string topic, T data) + { + return SerializeWithHeaders(topic, null, data); + } + /// + public override Java.Nio.ByteBuffer SerializeWithHeaders(string topic, Headers headers, T data) + { + headers?.Add(KNetSerialization.ValueSerializerIdentifier, valueSerDesName); + headers?.Add(KNetSerialization.ValueTypeIdentifier, valueTypeName); + + MemoryStream stream = new MemoryStream(); + { + data.WriteTo(stream); + return ByteBuffer.From(stream); + } + } + /// + public override T Deserialize(string topic, Java.Nio.ByteBuffer data) + { + return DeserializeWithHeaders(topic, null, data); + } + /// + public override T DeserializeWithHeaders(string topic, Headers headers, Java.Nio.ByteBuffer data) + { + if (data == null) return default; + return _parser.ParseFrom(data.ToStream()); + } + } } } diff --git a/src/net/KNet/Specific/Serialization/ByteBufferSupport.cs b/src/net/KNet/Specific/Serialization/ByteBufferSupport.cs new file mode 100644 index 0000000000..9ff30b9664 --- /dev/null +++ b/src/net/KNet/Specific/Serialization/ByteBufferSupport.cs @@ -0,0 +1,102 @@ +/* +* Copyright 2024 MASES s.r.l. +* +* Licensed 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. +* +* Refer to LICENSE for more information. +*/ + +using MASES.JCOBridge.C2JBridge; +using MASES.JCOBridge.C2JBridge.JVMInterop; + +namespace MASES.KNet.Serialization +{ + /// + /// KNet specific class for org.mases.knet.common.serialization.ByteBufferDeserializer + /// + public class KNetByteBufferDeserializer : JVMBridgeBase + { + /// + public override string BridgeClassName => "org.mases.knet.common.serialization.ByteBufferDeserializer"; + } + + /// + /// KNet specific class for org.mases.knet.common.serialization.ByteBufferSerializer + /// + public class KNetByteBufferSerializer : JVMBridgeBase + { + /// + public override string BridgeClassName => "org.mases.knet.common.serialization.ByteBufferSerializer"; + } + + /// + /// KNet specific class for org.mases.knet.common.serialization.Serdes + /// + public class KNetSerdes : JVMBridgeBase + { + /// + public override string BridgeClassName => "org.mases.knet.common.serialization.Serdes"; + /// + /// Returns of + /// + /// of + public static Org.Apache.Kafka.Common.Serialization.Serde ByteBuffer() + { + return SExecuteWithSignature>("ByteBuffer", "()Lorg/apache/kafka/common/serialization/Serde;"); + } + + #region ByteBufferSerde + /// + /// + /// + public partial class ByteBufferSerde : Org.Apache.Kafka.Common.Serialization.Serdes.WrapperSerde + { + const string _bridgeClassName = "org.mases.knet.common.serialization.Serdes$ByteBufferSerde"; + /// + /// Default constructor: even if the corresponding Java class does not have one, it is mandatory for JCOBridge + /// + public ByteBufferSerde() { } + /// + /// Generic constructor: it is useful for JCOBridge when there is a derived class which needs to pass arguments to the highest JVMBridgeBase class + /// + public ByteBufferSerde(params object[] args) : base(args) { } + + private static readonly IJavaType LocalBridgeClazz = ClazzOf(_bridgeClassName); + + /// + /// + /// + public override string BridgeClassName => _bridgeClassName; + /// + /// + /// + public override bool IsBridgeAbstract => false; + /// + /// + /// + public override bool IsBridgeCloseable => false; + /// + /// + /// + public override bool IsBridgeInterface => false; + /// + /// + /// + public override bool IsBridgeStatic => true; + + // TODO: complete the class + + } + #endregion + } +} diff --git a/src/net/KNet/Specific/Serialization/SerDes.cs b/src/net/KNet/Specific/Serialization/SerDes.cs index 7fc7697db8..2d0d84093e 100644 --- a/src/net/KNet/Specific/Serialization/SerDes.cs +++ b/src/net/KNet/Specific/Serialization/SerDes.cs @@ -17,6 +17,7 @@ */ using Java.Nio; +using Javax.Xml.Crypto; using MASES.JCOBridge.C2JBridge; using Org.Apache.Kafka.Common.Header; using Org.Apache.Kafka.Common.Serialization; @@ -37,14 +38,14 @@ public interface ISerDes : ISerializer, IDeserializer KafkaSerde { get; } } - /// - /// KNet common serializer/deserializer based on array JVM type - /// - /// The type to serialize/deserialize - public interface ISerDes : ISerDes, ISerializer, IDeserializer - { + ///// + ///// KNet common serializer/deserializer based on array JVM type + ///// + ///// The type to serialize/deserialize + //public interface ISerDes : ISerDes, ISerializer, IDeserializer + //{ - } + //} /// /// Common serializer/deserializer @@ -56,7 +57,6 @@ public class SerDes : ISerDes #region private fields readonly KNetSerialization.SerializationType _SerializationType; readonly KNetSerialization.SerializationType _JVMSerializationType; - Serdes.WrapperSerde _KafkaWrapperSerde; Serde _KafkaSerde; Serializer _KafkaSerializer; Deserializer _KafkaDeserializer; @@ -75,8 +75,9 @@ public SerDes() throw new ArgumentException($"Cannot manage {typeof(TJVMT).FullName} into TJVMT generic parameter"); } - if (_SerializationType == KNetSerialization.SerializationType.External && - _JVMSerializationType != KNetSerialization.SerializationType.ByteArray) + if (_SerializationType == KNetSerialization.SerializationType.External + && (IsDirectBuffered ? _JVMSerializationType != KNetSerialization.SerializationType.ByteBuffer + : _JVMSerializationType != KNetSerialization.SerializationType.ByteArray)) { throw new InvalidOperationException($"Serialization of {typeof(T).Name} can only be managed with TJVMT set to byte[]."); } @@ -84,9 +85,10 @@ public SerDes() switch (_SerializationType) { case KNetSerialization.SerializationType.External: - if (_JVMSerializationType != KNetSerialization.SerializationType.ByteArray) + if (IsDirectBuffered ? _JVMSerializationType != KNetSerialization.SerializationType.ByteBuffer + : _JVMSerializationType != KNetSerialization.SerializationType.ByteArray) { - throw new InvalidOperationException($"Serialization of {typeof(T).Name} can only be managed with TJVMT set to byte[]."); + throw new InvalidOperationException($"Serialization of {typeof(T).Name} can only be managed with TJVMT set to byte[] or Java.Lang.ByteBuffer."); } break; case KNetSerialization.SerializationType.Boolean: @@ -101,7 +103,9 @@ public SerDes() case KNetSerialization.SerializationType.String: case KNetSerialization.SerializationType.Guid: case KNetSerialization.SerializationType.Void: - if (_JVMSerializationType != _SerializationType && _JVMSerializationType != KNetSerialization.SerializationType.ByteArray) + if (_JVMSerializationType != _SerializationType + && (IsDirectBuffered ? _JVMSerializationType != KNetSerialization.SerializationType.ByteBuffer + : _JVMSerializationType != KNetSerialization.SerializationType.ByteArray)) { throw new InvalidOperationException($"{typeof(T).Name} is incompatible with {typeof(TJVMT).Name}."); } @@ -110,28 +114,81 @@ public SerDes() throw new InvalidOperationException($"{_SerializationType} is not valid."); } - var kafkaSerde = _JVMSerializationType switch + if (IsDirectBuffered) { - KNetSerialization.SerializationType.Boolean => Serdes.Boolean().Cast>(), - KNetSerialization.SerializationType.ByteArray => Serdes.ByteArray().Cast>(), - KNetSerialization.SerializationType.ByteBuffer => Serdes.ByteBuffer().Cast>(), - KNetSerialization.SerializationType.Bytes => Serdes.Bytes().Cast>(), - KNetSerialization.SerializationType.Double => Serdes.Double().Cast>(), - KNetSerialization.SerializationType.Float => Serdes.Float().Cast>(), - KNetSerialization.SerializationType.Integer => Serdes.Integer().Cast>(), - KNetSerialization.SerializationType.Long => Serdes.Long().Cast>(), - KNetSerialization.SerializationType.Short => Serdes.Short().Cast>(), - KNetSerialization.SerializationType.String => Serdes.String().Cast>(), - KNetSerialization.SerializationType.Guid => Serdes.UUID().Cast>(), - KNetSerialization.SerializationType.Void => Serdes.Void().Cast>(), - KNetSerialization.SerializationType.External => throw new InvalidOperationException($"{typeof(T)} needs an external serializer: set {nameof(OnSerialize)} or {nameof(OnSerializeWithHeaders)}."), - _ => default, - }; - - _KafkaSerializer = kafkaSerde.Serializer(); - _KafkaDeserializer = kafkaSerde.Deserializer(); - - _KafkaSerde = kafkaSerde; + _KafkaSerializer = new KNetByteBufferSerializer().CastDirect>(); + _KafkaDeserializer = new KNetByteBufferDeserializer().CastDirect>(); + _KafkaSerde = new KNetSerdes.ByteBufferSerde().CastDirect>(); + } + else + { + switch (_JVMSerializationType) + { + case KNetSerialization.SerializationType.Boolean: + _KafkaSerializer = new BooleanSerializer().CastDirect>(); + _KafkaDeserializer = new BooleanDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.BooleanSerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.ByteArray: + _KafkaSerializer = new ByteArraySerializer().CastDirect>(); + _KafkaDeserializer = new ByteArrayDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.ByteArraySerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.ByteBuffer: + _KafkaSerializer = new ByteBufferSerializer().CastDirect>(); + _KafkaDeserializer = new ByteBufferDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.ByteBufferSerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.Bytes: + _KafkaSerializer = new BytesSerializer().CastDirect>(); + _KafkaDeserializer = new BytesDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.BytesSerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.Double: + _KafkaSerializer = new DoubleSerializer().CastDirect>(); + _KafkaDeserializer = new DoubleDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.DoubleSerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.Float: + _KafkaSerializer = new FloatSerializer().CastDirect>(); + _KafkaDeserializer = new FloatDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.FloatSerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.Integer: + _KafkaSerializer = new IntegerSerializer().CastDirect>(); + _KafkaDeserializer = new IntegerDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.IntegerSerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.Long: + _KafkaSerializer = new LongSerializer().CastDirect>(); + _KafkaDeserializer = new LongDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.LongSerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.Short: + _KafkaSerializer = new ShortSerializer().CastDirect>(); + _KafkaDeserializer = new ShortDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.ShortSerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.String: + _KafkaSerializer = new StringSerializer().CastDirect>(); + _KafkaDeserializer = new StringDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.StringSerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.Guid: + _KafkaSerializer = new UUIDSerializer().CastDirect>(); + _KafkaDeserializer = new UUIDDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.UUIDSerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.Void: + _KafkaSerializer = new VoidSerializer().CastDirect>(); + _KafkaDeserializer = new VoidDeserializer().CastDirect>(); + _KafkaSerde = new Serdes.VoidSerde().CastDirect>(); + break; + case KNetSerialization.SerializationType.External: + default: + throw new InvalidOperationException($"{typeof(T)} needs an external serializer: set {nameof(OnSerialize)} or {nameof(OnSerializeWithHeaders)}."); + } + } } /// /// Finalizer @@ -147,7 +204,6 @@ public void Dispose() _KafkaSerde = null; _KafkaSerializer = null; _KafkaDeserializer = null; - _KafkaWrapperSerde = null; } #endregion @@ -155,19 +211,19 @@ public void Dispose() /// /// External serialization function /// - public Func OnSerialize { get; set; } + public Func OnSerialize { get; set; } /// /// External serialization function using /// - public Func OnSerializeWithHeaders { get; set; } + public Func OnSerializeWithHeaders { get; set; } /// /// External deserialization function /// - public Func OnDeserialize { get; set; } + public Func OnDeserialize { get; set; } /// /// External deserialization function using /// - public Func OnDeserializeWithHeaders { get; set; } + public Func OnDeserializeWithHeaders { get; set; } /// public Serde KafkaSerde => _KafkaSerde; /// @@ -176,33 +232,39 @@ public void Dispose() public Deserializer KafkaDeserializer => _KafkaDeserializer; /// public virtual bool UseHeaders => false; + /// + public virtual bool IsDirectBuffered => false; + /// + public virtual bool UseKafkaClassForSupportedTypes { get; set; } = false; /// - public virtual byte[] Serialize(string topic, T data) + public virtual TJVMT Serialize(string topic, T data) { if (OnSerialize != null) { return OnSerialize.Invoke(topic, data); } - return _SerializationType switch + var newData = _SerializationType switch { - KNetSerialization.SerializationType.Boolean => KNetSerialization.SerializeBoolean(topic, (bool)Convert.ChangeType(data, typeof(bool))), - KNetSerialization.SerializationType.ByteArray => KNetSerialization.SerializeByteArray(topic, data as byte[]), - KNetSerialization.SerializationType.ByteBuffer => KNetSerialization.SerializeByteBuffer(topic, data as ByteBuffer), - KNetSerialization.SerializationType.Bytes => KNetSerialization.SerializeBytes(topic, data as Org.Apache.Kafka.Common.Utils.Bytes), - KNetSerialization.SerializationType.Double => KNetSerialization.SerializeDouble(topic, (double)Convert.ChangeType(data, typeof(double))), - KNetSerialization.SerializationType.Float => KNetSerialization.SerializeFloat(topic, (float)Convert.ChangeType(data, typeof(float))), - KNetSerialization.SerializationType.Integer => KNetSerialization.SerializeInt(topic, (int)Convert.ChangeType(data, typeof(int))), - KNetSerialization.SerializationType.Long => KNetSerialization.SerializeLong(topic, (long)Convert.ChangeType(data, typeof(long))), - KNetSerialization.SerializationType.Short => KNetSerialization.SerializeShort(topic, (short)Convert.ChangeType(data, typeof(short))), - KNetSerialization.SerializationType.String => KNetSerialization.SerializeString(topic, data as string), - KNetSerialization.SerializationType.Guid => KNetSerialization.SerializeGuid(topic, (Guid)Convert.ChangeType(data, typeof(Guid))), - KNetSerialization.SerializationType.Void => KNetSerialization.SerializeVoid(topic, data as Java.Lang.Void), + KNetSerialization.SerializationType.Boolean => KNetSerialization.SerializeBoolean(UseKafkaClassForSupportedTypes, topic, (bool)Convert.ChangeType(data, typeof(bool))), + KNetSerialization.SerializationType.ByteArray => KNetSerialization.SerializeByteArray(UseKafkaClassForSupportedTypes, topic, data as byte[]), + KNetSerialization.SerializationType.ByteBuffer => KNetSerialization.SerializeByteBuffer(UseKafkaClassForSupportedTypes, topic, data as ByteBuffer), + KNetSerialization.SerializationType.Bytes => KNetSerialization.SerializeBytes(UseKafkaClassForSupportedTypes, topic, data as Org.Apache.Kafka.Common.Utils.Bytes), + KNetSerialization.SerializationType.Double => KNetSerialization.SerializeDouble(UseKafkaClassForSupportedTypes, topic, (double)Convert.ChangeType(data, typeof(double))), + KNetSerialization.SerializationType.Float => KNetSerialization.SerializeFloat(UseKafkaClassForSupportedTypes, topic, (float)Convert.ChangeType(data, typeof(float))), + KNetSerialization.SerializationType.Integer => KNetSerialization.SerializeInt(UseKafkaClassForSupportedTypes, topic, (int)Convert.ChangeType(data, typeof(int))), + KNetSerialization.SerializationType.Long => KNetSerialization.SerializeLong(UseKafkaClassForSupportedTypes, topic, (long)Convert.ChangeType(data, typeof(long))), + KNetSerialization.SerializationType.Short => KNetSerialization.SerializeShort(UseKafkaClassForSupportedTypes, topic, (short)Convert.ChangeType(data, typeof(short))), + KNetSerialization.SerializationType.String => KNetSerialization.SerializeString(UseKafkaClassForSupportedTypes, topic, data as string), + KNetSerialization.SerializationType.Guid => KNetSerialization.SerializeGuid(UseKafkaClassForSupportedTypes, topic, (Guid)Convert.ChangeType(data, typeof(Guid))), + KNetSerialization.SerializationType.Void => KNetSerialization.SerializeVoid(UseKafkaClassForSupportedTypes, topic, data as Java.Lang.Void), KNetSerialization.SerializationType.External => throw new InvalidOperationException($"{typeof(T)} needs an external serializer: set {nameof(OnSerialize)} or {nameof(OnSerializeWithHeaders)}."), _ => default, }; + return (IsDirectBuffered && _JVMSerializationType == KNetSerialization.SerializationType.ByteBuffer) ? (TJVMT)(object)(Java.Nio.ByteBuffer)newData + : (TJVMT)(object)newData; } /// - public virtual byte[] SerializeWithHeaders(string topic, Headers headers, T data) + public virtual TJVMT SerializeWithHeaders(string topic, Headers headers, T data) { if (OnSerializeWithHeaders != null) { @@ -211,32 +273,37 @@ public virtual byte[] SerializeWithHeaders(string topic, Headers headers, T data return Serialize(topic, data); } - /// - public virtual T Deserialize(string topic, byte[] data) + /// + public virtual T Deserialize(string topic, TJVMT data) { if (OnDeserialize != null) { return OnDeserialize.Invoke(topic, data); } + byte[] newData = data as byte[]; + if (IsDirectBuffered && _JVMSerializationType == KNetSerialization.SerializationType.ByteBuffer && data is Java.Nio.ByteBuffer nioBuffer) + { + newData = nioBuffer.ToArray(); + } return _SerializationType switch { - KNetSerialization.SerializationType.Boolean => (T)(object)KNetSerialization.DeserializeBoolean(topic, data), - KNetSerialization.SerializationType.ByteArray => (T)(object)KNetSerialization.DeserializeByteArray(topic, data), - KNetSerialization.SerializationType.ByteBuffer => (T)(object)KNetSerialization.DeserializeByteBuffer(topic, data), - KNetSerialization.SerializationType.Bytes => (T)(object)KNetSerialization.DeserializeBytes(topic, data), - KNetSerialization.SerializationType.Double => (T)(object)KNetSerialization.DeserializeDouble(topic, data), - KNetSerialization.SerializationType.Float => (T)(object)KNetSerialization.DeserializeFloat(topic, data), - KNetSerialization.SerializationType.Integer => (T)(object)KNetSerialization.DeserializeInt(topic, data), - KNetSerialization.SerializationType.Long => (T)(object)KNetSerialization.DeserializeLong(topic, data), - KNetSerialization.SerializationType.String => (T)(object)KNetSerialization.DeserializeString(topic, data), - KNetSerialization.SerializationType.Guid => (T)(object)KNetSerialization.DeserializeGuid(topic, data), - KNetSerialization.SerializationType.Void => (T)(object)KNetSerialization.DeserializeVoid(topic, data), + KNetSerialization.SerializationType.Boolean => (T)(object)KNetSerialization.DeserializeBoolean(UseKafkaClassForSupportedTypes, topic, newData), + KNetSerialization.SerializationType.ByteArray => (T)(object)KNetSerialization.DeserializeByteArray(UseKafkaClassForSupportedTypes, topic, newData), + KNetSerialization.SerializationType.ByteBuffer => (T)(object)KNetSerialization.DeserializeByteBuffer(UseKafkaClassForSupportedTypes, topic, newData), + KNetSerialization.SerializationType.Bytes => (T)(object)KNetSerialization.DeserializeBytes(UseKafkaClassForSupportedTypes, topic, newData), + KNetSerialization.SerializationType.Double => (T)(object)KNetSerialization.DeserializeDouble(UseKafkaClassForSupportedTypes, topic, newData), + KNetSerialization.SerializationType.Float => (T)(object)KNetSerialization.DeserializeFloat(UseKafkaClassForSupportedTypes, topic, newData), + KNetSerialization.SerializationType.Integer => (T)(object)KNetSerialization.DeserializeInt(UseKafkaClassForSupportedTypes, topic, newData), + KNetSerialization.SerializationType.Long => (T)(object)KNetSerialization.DeserializeLong(UseKafkaClassForSupportedTypes, topic, newData), + KNetSerialization.SerializationType.String => (T)(object)KNetSerialization.DeserializeString(UseKafkaClassForSupportedTypes, topic, newData), + KNetSerialization.SerializationType.Guid => (T)(object)KNetSerialization.DeserializeGuid(UseKafkaClassForSupportedTypes, topic, newData), + KNetSerialization.SerializationType.Void => (T)(object)KNetSerialization.DeserializeVoid(UseKafkaClassForSupportedTypes, topic, newData), KNetSerialization.SerializationType.External => throw new InvalidOperationException($"{typeof(T)} needs an external deserializer: set {nameof(OnDeserialize)} or {nameof(OnDeserializeWithHeaders)}."), _ => default, }; } - /// - public virtual T DeserializeWithHeaders(string topic, Headers headers, byte[] data) + /// + public virtual T DeserializeWithHeaders(string topic, Headers headers, TJVMT data) { if (OnDeserializeWithHeaders != null) { @@ -249,12 +316,22 @@ public virtual T DeserializeWithHeaders(string topic, Headers headers, byte[] da } /// - /// Common serializer/deserializer + /// Common serializer/deserializer based on array /// - /// The type to serialize/deserialize - public class SerDes : SerDes, ISerDes + /// The to serialize/deserialize + public class SerDesRaw : SerDes + { + } + /// + /// Common serializer/deserializer based on + /// + /// The to serialize/deserialize + public class SerDesBuffered : SerDes { + /// + public override bool IsDirectBuffered => true; } + /// /// Sets of predefined between specific types /// From 3520d576426d18f37ec8ec9204018a1419507770 Mon Sep 17 00:00:00 2001 From: masesdevelopers <94312179+masesdevelopers@users.noreply.github.com> Date: Wed, 15 May 2024 03:39:42 +0200 Subject: [PATCH 5/6] Test alignment --- tests/net/Common/SharedKNetCore.cs | 7 + tests/net/KNetBenchmark/ProgramKNet.cs | 30 +- .../KNetCompactedReplicatorTest/Program.cs | 6 +- tests/net/KNetTest/Program.cs | 417 ++++++++++++++++-- 4 files changed, 399 insertions(+), 61 deletions(-) diff --git a/tests/net/Common/SharedKNetCore.cs b/tests/net/Common/SharedKNetCore.cs index 04b4052237..0788af0950 100644 --- a/tests/net/Common/SharedKNetCore.cs +++ b/tests/net/Common/SharedKNetCore.cs @@ -16,9 +16,16 @@ * Refer to LICENSE for more information. */ +using System; + namespace MASES.KNet.TestCommon { internal class SharedKNetCore : KNetCore { + public override bool LogClassPath => false; + + public long CurrentJNICalls => JVMStats.TotalJNICalls; + + public TimeSpan CurrentTimeSpentInJNICalls => JVMStats.TotalTimeInJNICalls; } } diff --git a/tests/net/KNetBenchmark/ProgramKNet.cs b/tests/net/KNetBenchmark/ProgramKNet.cs index 8ace4ca249..ae51359362 100644 --- a/tests/net/KNetBenchmark/ProgramKNet.cs +++ b/tests/net/KNetBenchmark/ProgramKNet.cs @@ -32,11 +32,11 @@ namespace MASES.KNet.Benchmark { partial class Program { - static KNet.Producer.IProducer knetProducer = null; - static SerDes knetKeySerializer = null; - static SerDes knetValueSerializer = null; + static KNet.Producer.IProducer knetProducer = null; + static SerDes knetKeySerializer = null; + static SerDes knetValueSerializer = null; - static KNet.Producer.IProducer KNetProducer() + static KNet.Producer.IProducer KNetProducer() { if (knetProducer == null || !SharedObjects) { @@ -50,11 +50,9 @@ static KNet.Producer.IProducer KNetProducer() .WithEnableIdempotence(false) .WithSendBuffer(SocketSendBufferBytes) .WithReceiveBuffer(SocketReceiveBufferBytes) - .WithBufferMemory(128 * 1024 * 1024) - .WithKeySerializerClass("org.apache.kafka.common.serialization.LongSerializer") - .WithValueSerializerClass("org.apache.kafka.common.serialization.ByteArraySerializer"); + .WithBufferMemory(128 * 1024 * 1024); - knetKeySerializer = new SerDes() + knetKeySerializer = new SerDes() { OnSerializeWithHeaders = (topic, headers, data) => { @@ -62,7 +60,7 @@ static KNet.Producer.IProducer KNetProducer() return key; } }; - knetValueSerializer = new SerDes() + knetValueSerializer = new SerDes() { OnSerializeWithHeaders = (topic, headers, data) => { @@ -176,11 +174,11 @@ static Stopwatch ProduceKNet(string topicName, int length, int numpacket, byte[] } } - static SerDes knetKeyDeserializer = null; - static SerDes knetValueDeserializer = null; - static KNet.Consumer.IConsumer knetConsumer = null; + static SerDes knetKeyDeserializer = null; + static SerDes knetValueDeserializer = null; + static KNet.Consumer.IConsumer knetConsumer = null; - static KNet.Consumer.IConsumer KNetConsumer() + static KNet.Consumer.IConsumer KNetConsumer() { if (knetConsumer == null || !SharedObjects) { @@ -192,12 +190,10 @@ static KNet.Consumer.IConsumer KNetConsumer() .WithSendBuffer(SocketSendBufferBytes) .WithReceiveBuffer(SocketReceiveBufferBytes) .WithFetchMinBytes(FetchMinBytes) - .WithKeyDeserializerClass("org.apache.kafka.common.serialization.LongDeserializer") - .WithValueDeserializerClass("org.apache.kafka.common.serialization.ByteArrayDeserializer") .WithAutoOffsetReset(ConsumerConfigBuilder.AutoOffsetResetTypes.EARLIEST); if (UseSerdes) { - knetKeyDeserializer = new SerDes() + knetKeyDeserializer = new SerDes() { OnDeserialize = (topic, data) => { @@ -205,7 +201,7 @@ static KNet.Consumer.IConsumer KNetConsumer() return key; } }; - knetValueDeserializer = new SerDes() + knetValueDeserializer = new SerDes() { OnDeserialize = (topic, data) => { diff --git a/tests/net/KNetCompactedReplicatorTest/Program.cs b/tests/net/KNetCompactedReplicatorTest/Program.cs index 5173a9101d..55162e43c1 100644 --- a/tests/net/KNetCompactedReplicatorTest/Program.cs +++ b/tests/net/KNetCompactedReplicatorTest/Program.cs @@ -102,7 +102,7 @@ private static void TestValues(string topicName, int length, UpdateModeTypes typ UpdateMode = type, BootstrapServers = serverToUse, StateName = topicName, - KNetValueSerDes = typeof(JsonSerDes.Value<>), + KNetValueSerDes = typeof(JsonSerDes.ValueRaw<>), //ValueSerDes = new JsonSerDes.Value(), }) { @@ -131,7 +131,7 @@ private static void Test(string topicName, int length, UpdateModeTypes type, int UpdateMode = type, BootstrapServers = serverToUse, StateName = topicName, - KNetValueSerDes = typeof(JsonSerDes.Value<>), + KNetValueSerDes = typeof(JsonSerDes.ValueRaw<>), // ValueSerDes = new JsonSerDes.Value(), }) { @@ -160,7 +160,7 @@ private static void TestOnlyRead(string topicName, int length, UpdateModeTypes t UpdateMode = type, BootstrapServers = serverToUse, StateName = topicName, - ValueSerDes = new JsonSerDes.Value(), + ValueSerDes = new JsonSerDes.ValueRaw(), }) { replicator.StartAndWait(); diff --git a/tests/net/KNetTest/Program.cs b/tests/net/KNetTest/Program.cs index 374f376373..0d43e3f453 100644 --- a/tests/net/KNetTest/Program.cs +++ b/tests/net/KNetTest/Program.cs @@ -31,30 +31,72 @@ using MASES.KNet.Consumer; using MASES.KNet.Common; using System.Diagnostics; +using Org.Apache.Kafka.Common.Errors; namespace MASES.KNetTest { class Program { - static bool useCallback = true; + static bool withBigExtraValue = false; + static bool withBigBigExtraValue = false; + static bool consoleOutput = System.Diagnostics.Debugger.IsAttached ? true : false; + static bool runBuffered = false; + static bool useCallback = false; + static bool onlyProduce = false; + static bool flushWhileSend = false; + static bool withAck = false; + static bool runInParallel = false; const string theServer = "localhost:9092"; const string theTopic = "myTopic"; + static int NonParallelLimit = 100000; + static long _firstOffset = -1; + static string serverToUse = theServer; static string topicToUse = theTopic; static readonly ManualResetEvent resetEvent = new(false); public class TestType { - public TestType(int i) + static byte[] _bigExtraValue = null; + static byte[] _bigBigExtraValue = null; + static TestType() + { + _bigExtraValue = new byte[100000]; + for (int i = 0; i < _bigExtraValue.LongLength; i++) + { + _bigExtraValue[i] = (byte)(i % byte.MaxValue); + } + _bigBigExtraValue = new byte[1000000]; + for (int i = 0; i < _bigBigExtraValue.LongLength; i++) + { + _bigBigExtraValue[i] = (byte)(i % byte.MaxValue); + } + } + + public TestType() + { + + } + + public TestType(int i, bool withBigExtraValue, bool bigBigExtraValue) { name = description = value = i.ToString(); + if (withBigExtraValue) + { + extraValue = _bigExtraValue; + } + else if (bigBigExtraValue) + { + extraValue = _bigBigExtraValue; + } } - public string name; - public string description; - public string value; + public string name { get; set; } + public string description { get; set; } + public string value { get; set; } + public byte[] extraValue { get; set; } public override string ToString() { @@ -70,37 +112,86 @@ static void Main(string[] args) if (appArgs.Length != 0) { serverToUse = args[0]; + if (args.Length > 1) + { + for (int i = 1; i < args.Length; i++) + { + if (args[i] == "runBuffered") { runBuffered = true; continue; } + if (args[i] == "consoleOutput") { consoleOutput = true; continue; } + if (args[i] == "useCallback") { useCallback = true; continue; } + if (args[i] == "withBigExtraValue") { withBigExtraValue = true; NonParallelLimit /= 10; continue; } + if (args[i] == "withBigBigExtraValue") { withBigBigExtraValue = true; NonParallelLimit /= 100; continue; } + if (args[i] == "onlyProduce") { onlyProduce = true; continue; } + if (args[i] == "flushWhileSend") { flushWhileSend = true; continue; } + if (args[i] == "withAck") { withAck = true; continue; } + if (args[i] == "runInParallel") { runInParallel = true; continue; } + Console.WriteLine($"Unknown {args[i]}"); + } + } } - SerDes serializer = new SerDes() + SerDesRaw serializer = new SerDesRaw() { OnSerialize = (topic, type) => { return Array.Empty(); } }; - SerDes deserializer = new SerDes() + SerDesRaw deserializer = new SerDesRaw() { - OnDeserialize = (topic, data) => { return new TestType(0); } + OnDeserialize = (topic, data) => { return new TestType(0, false, false); } }; CreateTopic(); - - Thread threadProduce = new(ProduceSomething) + Console.CancelKeyPress += Console_CancelKeyPress; + Console.WriteLine("Press Ctrl-C to exit"); + if (runInParallel) { - Name = "produce" - }; - threadProduce.Start(); + Thread threadProduce; + Thread threadConsume; + if (runBuffered) + { + threadProduce = new(ProduceSomethingBuffered) + { + Name = "produce buffered" + }; - Thread threadConsume = new(ConsumeSomething) - { - Name = "consume" - }; - threadConsume.Start(); + threadConsume = new(ConsumeSomethingBuffered) + { + Name = "consume buffered" + }; + } + else + { + threadProduce = new(ProduceSomething) + { + Name = "produce" + }; - Console.CancelKeyPress += Console_CancelKeyPress; - Console.WriteLine("Press Ctrl-C to exit"); - resetEvent.WaitOne(TimeSpan.FromSeconds(10)); - resetEvent.Set(); + threadConsume = new(ConsumeSomething) + { + Name = "consume" + }; + } + threadProduce.Start(); + if (!onlyProduce) threadConsume.Start(); + resetEvent.WaitOne(TimeSpan.FromSeconds(System.Diagnostics.Debugger.IsAttached ? 1000 : 60)); + resetEvent.Set(); + } + else + { + if (runBuffered) + { + ProduceSomethingBuffered(); + if (!onlyProduce) ConsumeSomethingBuffered(); + } + else + { + ProduceSomething(); + if (!onlyProduce) ConsumeSomething(); + } + } Thread.Sleep(2000); // wait the threads exit + + Console.WriteLine($"End of {(runBuffered ? "buffered" : "non buffered")} test"); } private static void Console_CancelKeyPress(object sender, ConsoleCancelEventArgs e) @@ -125,6 +216,7 @@ static void CreateTopic() topic = topic.Configs(TopicConfigBuilder.Create().WithCleanupPolicy(TopicConfigBuilder.CleanupPolicyTypes.Compact | TopicConfigBuilder.CleanupPolicyTypes.Delete) .WithDeleteRetentionMs(100) .WithMinCleanableDirtyRatio(0.01) + .WithMaxMessageBytes(100 * 1024 * 1024) .WithSegmentMs(100)); var coll = Collections.Singleton(topic); @@ -149,13 +241,14 @@ static void CreateTopic() // if creation failed the ExecutionException wraps the underlying cause. future.Get(); ********/ - admin.CreateTopic(topicName, partitions, replicationFactor); + admin.CreateTopic(topic); } } catch (Java.Util.Concurrent.ExecutionException ex) { Console.WriteLine(ex.InnerException.Message); } + catch (TopicExistsException) { } catch (Exception e) { Console.WriteLine(e.Message); @@ -176,12 +269,14 @@ static void ProduceSomething() ProducerConfigBuilder props = ProducerConfigBuilder.Create() .WithBootstrapServers(serverToUse) - .WithAcks(ProducerConfigBuilder.AcksTypes.All) + .WithAcks(withAck ? ProducerConfigBuilder.AcksTypes.All : ProducerConfigBuilder.AcksTypes.None) + .WithMaxRequestSize(10 * 1024 * 1024) .WithRetries(0) .WithLingerMs(1); - SerDes keySerializer = new SerDes(); - JsonSerDes.Value valueSerializer = new JsonSerDes.Value(); + var keySerializer = new SerDesRaw(); + var valueSerializer = new JsonSerDes.ValueRaw(); + Stopwatch watcher = new Stopwatch(); try { using (var producer = new KNetProducer(props, keySerializer, valueSerializer)) @@ -195,22 +290,45 @@ static void ProduceSomething() OnOnCompletion = (o1, o2) => { if (o2 != null) Console.WriteLine(o2.ToString()); - else Console.WriteLine($"Produced on topic {o1.Topic()} at offset {o1.Offset()}"); + else if (consoleOutput) Console.WriteLine($"Produced on topic {o1.Topic()} at offset {o1.Offset()}"); } }; } + var baseJNICalls = SharedKNetCore.GlobalInstance.CurrentJNICalls; try { - while (!resetEvent.WaitOne(0)) + while (runInParallel ? !resetEvent.WaitOne(0) : i < NonParallelLimit) { - var record = new KNet.Producer.ProducerRecord(topicToUse, i.ToString(), new TestType(i)); + watcher.Start(); + var record = producer.NewRecord(topicToUse, i.ToString(), new TestType(i, withBigExtraValue, withBigBigExtraValue)); var result = useCallback ? producer.Send(record, callback) : producer.Send(record); - Console.WriteLine($"Producing: {record} with result: {result.Get()}"); - producer.Flush(); + if (!runInParallel && _firstOffset == -1) + { + _firstOffset = result.Get().Offset(); + } + watcher.Stop(); + if (consoleOutput) Console.WriteLine($"Producing: {record}"); + if (flushWhileSend) + { + watcher.Start(); + producer.Flush(); + watcher.Stop(); + } i++; } + if (!flushWhileSend) + { + watcher.Start(); + producer.Flush(); + watcher.Stop(); + } + baseJNICalls = SharedKNetCore.GlobalInstance.CurrentJNICalls - baseJNICalls; + } + finally + { + if (useCallback) callback.Dispose(); + if (i != 0) Console.WriteLine($"Flushed {i} elements in {watcher.Elapsed}, produce mean time is {TimeSpan.FromTicks(watcher.ElapsedTicks / i)} with mean JNI Calls {baseJNICalls / i}"); } - finally { if (useCallback) callback.Dispose(); } } } finally @@ -243,12 +361,13 @@ static void ConsumeSomething() ConsumerConfigBuilder props = ConsumerConfigBuilder.Create() .WithBootstrapServers(serverToUse) - .WithGroupId("test") + .WithGroupId(Guid.NewGuid().ToString()) + .WithAutoOffsetReset(ConsumerConfigBuilder.AutoOffsetResetTypes.LATEST) .WithEnableAutoCommit(true) .WithAutoCommitIntervalMs(1000); - SerDes keyDeserializer = new SerDes(); - SerDes valueDeserializer = new JsonSerDes.Value(); + SerDesRaw keyDeserializer = new SerDesRaw(); + var valueDeserializer = new JsonSerDes.ValueRaw(); ConsumerRebalanceListener rebalanceListener = null; KNetConsumer consumer = null; @@ -275,10 +394,26 @@ static void ConsumeSomething() { using (consumer = new KNetConsumer(props, keyDeserializer, valueDeserializer)) { - if (useCallback) consumer.Subscribe(topics, rebalanceListener); - else consumer.Subscribe(topics); + if (runInParallel) + { + if (useCallback) consumer.Subscribe(topics, rebalanceListener); + else consumer.Subscribe(topics); + } + else + { + var tp = new Org.Apache.Kafka.Common.TopicPartition(topicToUse, 0); + consumer.Assign(Collections.Singleton(tp)); + if (_firstOffset != -1) + { + consumer.Seek(tp, _firstOffset); + } + else + { + consumer.SeekToBeginning(Collections.Singleton(tp)); + } + } - while (!resetEvent.WaitOne(0)) + while (runInParallel ? !resetEvent.WaitOne(0) : elements < NonParallelLimit) { var records = consumer.Poll((long)TimeSpan.FromMilliseconds(200).TotalMilliseconds); watcherTotal.Start(); @@ -289,13 +424,213 @@ static void ConsumeSomething() #endif { elements++; - watcher.Start(); + watcherTotal.Start(); var str = $"Consuming from Offset = {item.Offset}, Key = {item.Key}, Value = {item.Value}"; + watcherTotal.Stop(); + watcher.Start(); + if (consoleOutput) Console.WriteLine(str); + watcher.Stop(); + } + } + watcherTotal.Stop(); + } + } + finally + { + keyDeserializer?.Dispose(); + valueDeserializer?.Dispose(); + topics?.Dispose(); + if (elements != 0) Console.WriteLine($"Total mean time is {TimeSpan.FromTicks(watcherTotal.ElapsedTicks / elements)}, console write mean time is {TimeSpan.FromTicks(watcher.ElapsedTicks / elements)}"); + } + } + catch (Java.Util.Concurrent.ExecutionException ex) + { + Console.WriteLine("Consumer ended with error: {0}", ex.InnerException.Message); + } + catch (Exception ex) + { + Console.WriteLine("Consumer ended with error: {0}", ex.Message); + } + } + + static void ProduceSomethingBuffered() + { + try + { + /**** Direct mode ****** + Properties props = new Properties(); + props.Put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, serverToUse); + props.Put(ProducerConfig.ACKS_CONFIG, "all"); + props.Put(ProducerConfig.RETRIES_CONFIG, 0); + props.Put(ProducerConfig.LINGER_MS_CONFIG, 1); + ******/ + + ProducerConfigBuilder props = ProducerConfigBuilder.Create() + .WithBootstrapServers(serverToUse) + .WithAcks(withAck ? ProducerConfigBuilder.AcksTypes.All : ProducerConfigBuilder.AcksTypes.None) + .WithMaxRequestSize(10 * 1024 * 1024) + .WithRetries(0) + .WithLingerMs(1); + + var keySerializer = new SerDesRaw(); // standard serDes for string + var valueSerializer = new JsonSerDes.ValueBuffered(); + Stopwatch watcher = new Stopwatch(); + try + { + using (var producer = new KNetProducerValueBuffered(props, keySerializer, valueSerializer)) + { + int i = 0; + Callback callback = null; + if (useCallback) + { + callback = new Callback() + { + OnOnCompletion = (o1, o2) => + { + if (o2 != null) Console.WriteLine(o2.ToString()); + else if (consoleOutput) Console.WriteLine($"Produced on topic {o1.Topic()} at offset {o1.Offset()}"); + } + }; + } + var baseJNICalls = SharedKNetCore.GlobalInstance.CurrentJNICalls; + try + { + while (runInParallel ? !resetEvent.WaitOne(0) : i < NonParallelLimit) + { + watcher.Start(); + var record = producer.NewRecord(topicToUse, i.ToString(), new TestType(i, withBigExtraValue, withBigBigExtraValue)); + var result = useCallback ? producer.Send(record, callback) : producer.Send(record); + if (!runInParallel && _firstOffset == -1) + { + _firstOffset = result.Get().Offset(); + } + watcher.Stop(); + if (consoleOutput) Console.WriteLine($"Producing: {record}"); + if (flushWhileSend) + { + watcher.Start(); + producer.Flush(); + watcher.Stop(); + } + i++; + } + if (!flushWhileSend) + { + watcher.Start(); + producer.Flush(); watcher.Stop(); + } + baseJNICalls = SharedKNetCore.GlobalInstance.CurrentJNICalls - baseJNICalls; + } + finally + { + if (useCallback) callback.Dispose(); + if (i != 0) Console.WriteLine($"Flushed {i} elements in {watcher.Elapsed}, produce mean time is {TimeSpan.FromTicks(watcher.ElapsedTicks / i)} with mean JNI Calls {baseJNICalls / i}"); + } + } + } + finally + { + keySerializer?.Dispose(); + valueSerializer?.Dispose(); + } + } + catch (Java.Util.Concurrent.ExecutionException ex) + { + Console.WriteLine("Producer ended with error: {0}", ex.InnerException.Message); + } + catch (Exception ex) + { + Console.WriteLine("Producer ended with error: {0}", ex.Message); + } + } + + static void ConsumeSomethingBuffered() + { + try + { + /**** Direct mode ****** + Properties props = new Properties(); + props.Put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, serverToUse); + props.Put(ConsumerConfig.GROUP_ID_CONFIG, "test"); + props.Put(ConsumerConfig.ENABLE_AUTO_COMMIT_CONFIG, "true"); + props.Put(ConsumerConfig.AUTO_COMMIT_INTERVAL_MS_CONFIG, "1000"); + *******/ + + ConsumerConfigBuilder props = ConsumerConfigBuilder.Create() + .WithBootstrapServers(serverToUse) + .WithGroupId(Guid.NewGuid().ToString()) + .WithAutoOffsetReset(ConsumerConfigBuilder.AutoOffsetResetTypes.LATEST) + .WithEnableAutoCommit(true) + .WithAutoCommitIntervalMs(1000); + + var keyDeserializer = new SerDesRaw(); + var valueDeserializer = new JsonSerDes.ValueBuffered(); + ConsumerRebalanceListener rebalanceListener = null; + KNetConsumerValueBuffered consumer = null; + + if (useCallback) + { + rebalanceListener = new ConsumerRebalanceListener() + { + OnOnPartitionsRevoked = (o) => + { + Console.WriteLine("Revoked: {0}", o.ToString()); + }, + OnOnPartitionsAssigned = (o) => + { + Console.WriteLine("Assigned: {0}", o.ToString()); + } + }; + } + const bool withPrefetch = true; + long elements = 0; + Stopwatch watcherTotal = new Stopwatch(); + Stopwatch watcher = new Stopwatch(); + var topics = Collections.Singleton((Java.Lang.String)topicToUse); + try + { + using (consumer = new KNetConsumerValueBuffered(props, keyDeserializer, valueDeserializer)) + { + if (runInParallel) + { + if (useCallback) consumer.Subscribe(topics, rebalanceListener); + else consumer.Subscribe(topics); + } + else + { + var tp = new Org.Apache.Kafka.Common.TopicPartition(topicToUse, 0); + consumer.Assign(Collections.Singleton(tp)); + if (_firstOffset != -1) + { + consumer.Seek(tp, _firstOffset); + } + else + { + consumer.SeekToBeginning(Collections.Singleton(tp)); + } + } + + while (runInParallel ? !resetEvent.WaitOne(0) : elements < NonParallelLimit) + { + var records = consumer.Poll((long)TimeSpan.FromMilliseconds(200).TotalMilliseconds); + watcherTotal.Start(); +#if NET7_0_OR_GREATER + foreach (var item in records.ApplyPrefetch(withPrefetch, prefetchThreshold: 0)) +#else + foreach (var item in records) +#endif + { + elements++; + watcherTotal.Start(); + var str = $"Consuming from Offset = {item.Offset}, Key = {item.Key}, Value = {item.Value}"; watcherTotal.Stop(); - Console.WriteLine(str); + watcher.Start(); + if (consoleOutput) Console.WriteLine(str); + watcher.Stop(); } } + watcherTotal.Stop(); } } finally @@ -303,7 +638,7 @@ static void ConsumeSomething() keyDeserializer?.Dispose(); valueDeserializer?.Dispose(); topics?.Dispose(); - if (elements != 0) Console.WriteLine($"Total mean time is {TimeSpan.FromTicks(watcherTotal.ElapsedTicks / elements)}, write mean time is {TimeSpan.FromTicks(watcher.ElapsedTicks / elements)}"); + if (elements != 0) Console.WriteLine($"Total mean time is {TimeSpan.FromTicks(watcherTotal.ElapsedTicks / elements)}, console write mean time is {TimeSpan.FromTicks(watcher.ElapsedTicks / elements)}"); } } catch (Java.Util.Concurrent.ExecutionException ex) From 13a95720405bccfb3425ae2ad8539bba80f2aeb0 Mon Sep 17 00:00:00 2001 From: masesdevelopers <94312179+masesdevelopers@users.noreply.github.com> Date: Wed, 15 May 2024 04:01:42 +0200 Subject: [PATCH 6/6] Merge fix --- .../KNet/Specific/Serialization/IDeserializer.cs | 14 -------------- src/net/KNet/Specific/Serialization/ISerializer.cs | 14 -------------- src/net/KNet/Specific/Serialization/SerDes.cs | 2 -- 3 files changed, 30 deletions(-) diff --git a/src/net/KNet/Specific/Serialization/IDeserializer.cs b/src/net/KNet/Specific/Serialization/IDeserializer.cs index 23422b68e8..0efd3662e2 100644 --- a/src/net/KNet/Specific/Serialization/IDeserializer.cs +++ b/src/net/KNet/Specific/Serialization/IDeserializer.cs @@ -46,23 +46,9 @@ public interface IDeserializer : IDisposable /// Set to in implementing class if the implementation shall use the support of direct buffer exchange /// bool IsDirectBuffered { get; } - /// - /// Set to in implementing class if the implementation shall use the deserializer of Apache Kafka, default is - /// - /// When this option is set to there is better compatibility with data managed from Apache Kafka, but there is a performance impact - bool UseKafkaClassForSupportedTypes { get; set; } /// T Deserialize(string topic, TJVMT data); /// T DeserializeWithHeaders(string topic, Headers headers, TJVMT data); } - - ///// - ///// KNet interface for deserializers based on array JVM type - ///// - ///// The .NET type - //public interface IDeserializer : IDeserializer - //{ - - //} } diff --git a/src/net/KNet/Specific/Serialization/ISerializer.cs b/src/net/KNet/Specific/Serialization/ISerializer.cs index dede6b1986..17f76ce0ce 100644 --- a/src/net/KNet/Specific/Serialization/ISerializer.cs +++ b/src/net/KNet/Specific/Serialization/ISerializer.cs @@ -46,23 +46,9 @@ public interface ISerializer : IDisposable /// Set to in implementing class if the implementation shall use the support of direct buffer exchange /// bool IsDirectBuffered { get; } - /// - /// Set to in implementing class if the implementation shall use the serializer of Apache Kafka, default is - /// - /// When this option is set to there is better compatibility with data managed from Apache Kafka, but there is a performance impact - bool UseKafkaClassForSupportedTypes { get; set; } /// TJVMT Serialize(string topic, T data); /// TJVMT SerializeWithHeaders(string topic, Headers headers, T data); } - - ///// - ///// KNet interface for serializers based on array JVM type - ///// - ///// The .NET type - //public interface ISerializer : ISerializer - //{ - - //} } diff --git a/src/net/KNet/Specific/Serialization/SerDes.cs b/src/net/KNet/Specific/Serialization/SerDes.cs index 1f3f51f191..129df1889a 100644 --- a/src/net/KNet/Specific/Serialization/SerDes.cs +++ b/src/net/KNet/Specific/Serialization/SerDes.cs @@ -236,8 +236,6 @@ public void Dispose() public virtual bool UseKafkaClassForSupportedTypes { get; set; } = false; /// public virtual bool IsDirectBuffered => false; - /// - public virtual bool UseKafkaClassForSupportedTypes { get; set; } = false; /// public virtual TJVMT Serialize(string topic, T data) {