@@ -21,6 +21,7 @@ use std::fmt;
2121use std:: os:: raw:: c_char;
2222use std:: ptr;
2323use std:: sync:: { Arc , Once } ;
24+ use tokio:: runtime:: Handle ;
2425use tokio:: sync:: Mutex ;
2526use tracing:: { debug, error, info, trace} ;
2627use tracing_subscriber:: fmt:: format:: FmtSpan ;
@@ -134,16 +135,16 @@ impl fmt::Debug for EventWriterPool {
134135}
135136
136137pub struct NvDsPravegaClientHandle {
137- pub client_factory : ClientFactory ,
138+ pub runtime_handle : Handle ,
138139 pub writer_pool : EventWriterPool ,
139140 pub routing_key_method : RoutingKeyMethod ,
140141}
141142
142143impl NvDsPravegaClientHandle {
143144 pub fn new ( client_factory : ClientFactory , routing_key_method : RoutingKeyMethod ) -> Self {
144145 NvDsPravegaClientHandle {
145- client_factory : client_factory. clone ( ) ,
146- writer_pool : EventWriterPool :: new ( client_factory. clone ( ) ) ,
146+ runtime_handle : client_factory. runtime_handle ( ) ,
147+ writer_pool : EventWriterPool :: new ( client_factory) ,
147148 routing_key_method,
148149 }
149150 }
@@ -255,13 +256,12 @@ pub extern "C" fn nvds_msgapi_send(h_ptr: *mut NvDsPravegaClientHandle, topic: *
255256 let payload_string = String :: from_utf8_lossy ( payload) ;
256257 trace ! ( "nvds_msgapi_send: payload_string={}" , payload_string) ;
257258 let scoped_stream = client_handle. resolve_topic ( topic) . unwrap ( ) ;
258- let runtime = client_handle. client_factory . runtime ( ) ;
259259 let routing_key_method = client_handle. routing_key_method . clone ( ) ;
260260 let routing_key = match routing_key_method {
261261 RoutingKeyMethod :: Fixed { routing_key } => routing_key,
262262 } ;
263263 debug ! ( "nvds_msgapi_send: routing_key={:?}" , routing_key) ;
264- let result = runtime . block_on ( async {
264+ let result = client_handle . runtime_handle . block_on ( async {
265265 // Get a reference to the writer for this topic from the writer pool.
266266 let writer = client_handle. writer_pool . get_or_create ( scoped_stream) . await ;
267267 // Get the mutex for this writer so we can use it.
@@ -312,15 +312,14 @@ pub extern "C" fn nvds_msgapi_send_async(
312312 // Convert unsafe payload to a vector. This also copies the payload which is critical to avoid memory corruption.
313313 let event = payload. to_vec ( ) ;
314314 let scoped_stream = client_handle. resolve_topic ( topic) . unwrap ( ) ;
315- let runtime = client_handle. client_factory . runtime ( ) ;
316315 let routing_key_method = client_handle. routing_key_method . clone ( ) ;
317316 let routing_key = match routing_key_method {
318317 RoutingKeyMethod :: Fixed { routing_key } => routing_key,
319318 } ;
320319 debug ! ( "nvds_msgapi_send_async: routing_key={:?}" , routing_key) ;
321320 // Spawn a task in the Tokio runtime that will write the event, wait for it to be durably persisted,
322321 // and then call the callback function.
323- runtime . spawn ( async move {
322+ client_handle . runtime_handle . spawn ( async move {
324323 // Get a reference to the writer for this topic from the writer pool.
325324 let writer = client_handle. writer_pool . get_or_create ( scoped_stream) . await ;
326325 // Get the mutex for this writer so we can use it.
0 commit comments