-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
18aa570
commit 87cd45f
Showing
12 changed files
with
465 additions
and
333 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright 2023 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 System; | ||
using Org.Apache.Kafka.Clients.Consumer; | ||
using MASES.KNet.Serialization; | ||
|
||
namespace MASES.KNet.Consumer | ||
{ | ||
interface IKNetConsumerCallback<K, V> : IJVMBridgeBase | ||
{ | ||
void RecordReady(KNetConsumerRecord<K, V> message); | ||
} | ||
|
||
class KNetConsumerCallback<K, V> : JVMBridgeListener, IKNetConsumerCallback<K, V> | ||
{ | ||
readonly IKNetDeserializer<K> _keyDeserializer; | ||
readonly IKNetDeserializer<V> _valueDeserializer; | ||
/// <summary> | ||
/// <see href="https://www.jcobridge.com/api-clr/html/P_MASES_JCOBridge_C2JBridge_JVMBridgeListener_BridgeClassName.htm"/> | ||
/// </summary> | ||
public sealed override string BridgeClassName => "org.mases.knet.clients.consumer.KNetConsumerCallback"; | ||
|
||
readonly Action<KNetConsumerRecord<K, V>> recordReadyFunction = null; | ||
public virtual Action<KNetConsumerRecord<K, V>> OnRecordReady { get { return recordReadyFunction; } } | ||
public KNetConsumerCallback(Action<KNetConsumerRecord<K, V>> recordReady, IKNetDeserializer<K> keyDeserializer, IKNetDeserializer<V> valueDeserializer) | ||
{ | ||
if (recordReady != null) recordReadyFunction = recordReady; | ||
else recordReadyFunction = RecordReady; | ||
|
||
_keyDeserializer = keyDeserializer; | ||
_valueDeserializer = valueDeserializer; | ||
|
||
AddEventHandler("recordReady", new EventHandler<CLRListenerEventArgs<CLREventData>>(OnRecordReadyEventHandler)); | ||
} | ||
|
||
void OnRecordReadyEventHandler(object sender, CLRListenerEventArgs<CLREventData> data) | ||
{ | ||
var record = this.BridgeInstance.Invoke<ConsumerRecord<byte[], byte[]>>("getRecord"); | ||
OnRecordReady(new KNetConsumerRecord<K, V>(record, _keyDeserializer, _valueDeserializer)); | ||
} | ||
|
||
public virtual void RecordReady(KNetConsumerRecord<K, V> message) { } | ||
} | ||
} |
Oops, something went wrong.