Xuanwo commented on code in PR #2112:
URL:
https://github.com/apache/incubator-opendal/pull/2112#discussion_r1177511116
##########
bindings/java/src/lib.rs:
##########
@@ -57,6 +134,52 @@ pub extern "system" fn
Java_org_apache_opendal_Operator_getOperator(
}
}
+/// # Safety
+///
+/// This function should not be called before the Operator are ready.
+#[no_mangle]
+pub unsafe extern "system" fn Java_org_apache_opendal_Operator_asyncWrite(
+ mut env: JNIEnv,
+ _class: JClass,
+ ptr: *mut Operator,
+ file: JString,
+ content: JString,
+ future: JObject,
+) {
+ let op = &mut *ptr;
+
+ let file: String = env.get_string(&file).unwrap().into();
+ let content: String = env.get_string(&content).unwrap().into();
+ // keep the future alive, so that we can complete it later
+ // but this approach will be limited by global ref table size
+ let future = env.new_global_ref(future).unwrap();
+
+ let x = async move {
+ op.write(&file, content).await.unwrap();
+ JENV.with(|cell| {
+ let env_ptr = cell.borrow().unwrap();
+ let mut env = JNIEnv::from_raw(env_ptr).unwrap();
+
+ // build result
+ let boolean_class = env.find_class("java/lang/Boolean").unwrap();
+ let boolean = env
+ .get_static_field(boolean_class, "TRUE", "Ljava/lang/Boolean;")
+ .unwrap();
+
+ // complete the java future
Review Comment:
I'm a bit confused that we need to call java's API instead rust code. Can we
avoid that? I expect to build and return a java future to java side.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]