Skip to content

Commit

Permalink
feat: generate java configs (#5503)
Browse files Browse the repository at this point in the history
  • Loading branch information
tisonkun authored Jan 3, 2025
1 parent f7f9990 commit c866d4b
Show file tree
Hide file tree
Showing 18 changed files with 3,866 additions and 69 deletions.
4 changes: 2 additions & 2 deletions bindings/java/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ fn make_presigned_request<'a>(env: &mut JNIEnv<'a>, req: PresignedRequest) -> Re
}

fn make_operator_info<'a>(env: &mut JNIEnv<'a>, info: OperatorInfo) -> Result<JObject<'a>> {
let schema = env.new_string(info.scheme().to_string())?;
let scheme = env.new_string(info.scheme().to_string())?;
let root = env.new_string(info.root().to_string())?;
let name = env.new_string(info.name().to_string())?;
let full_capability_obj = make_capability(env, info.full_capability())?;
Expand All @@ -81,7 +81,7 @@ fn make_operator_info<'a>(env: &mut JNIEnv<'a>, info: OperatorInfo) -> Result<JO
"org/apache/opendal/OperatorInfo",
"(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lorg/apache/opendal/Capability;Lorg/apache/opendal/Capability;)V",
&[
JValue::Object(&schema),
JValue::Object(&scheme),
JValue::Object(&root),
JValue::Object(&name),
JValue::Object(&full_capability_obj),
Expand Down
34 changes: 27 additions & 7 deletions bindings/java/src/main/java/org/apache/opendal/AsyncOperator.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,38 @@ private static <T> CompletableFuture<T> take(long requestId) {

private final long executorHandle;

/**
* Construct an OpenDAL operator.
*
* @param config the config of the underneath service to access data from.
*/
public static AsyncOperator of(ServiceConfig config) {
return of(config, null);
}

/**
* Construct an OpenDAL operator.
*
* @param executor the underneath executor to run async operations; {@code null} to use a default global executor.
*/
public static AsyncOperator of(ServiceConfig config, AsyncExecutor executor) {
final String scheme = config.scheme();
final Map<String, String> map = config.configMap();
return of(scheme, map, executor);
}

/**
* Construct an OpenDAL operator:
*
* <p>
* You can find all possible schemes <a href="https://docs.rs/opendal/latest/opendal/enum.Scheme.html">here</a>
* and see what config options each service supports.
*
* @param schema the name of the underneath service to access data from.
* @param scheme the name of the underneath service to access data from.
* @param map a map of properties to construct the underneath operator.
*/
public static AsyncOperator of(String schema, Map<String, String> map) {
return of(schema, map, null);
public static AsyncOperator of(String scheme, Map<String, String> map) {
return of(scheme, map, null);
}

/**
Expand All @@ -127,13 +147,13 @@ public static AsyncOperator of(String schema, Map<String, String> map) {
* You can find all possible schemes <a href="https://docs.rs/opendal/latest/opendal/enum.Scheme.html">here</a>
* and see what config options each service supports.
*
* @param schema the name of the underneath service to access data from.
* @param scheme the name of the underneath service to access data from.
* @param map a map of properties to construct the underneath operator.
* @param executor the underneath executor to run async operations; {@code null} to use a default global executor.
*/
public static AsyncOperator of(String schema, Map<String, String> map, AsyncExecutor executor) {
public static AsyncOperator of(String scheme, Map<String, String> map, AsyncExecutor executor) {
final long executorHandle = executor != null ? executor.nativeHandle : 0;
final long nativeHandle = constructor(executorHandle, schema, map);
final long nativeHandle = constructor(executorHandle, scheme, map);
final OperatorInfo info = makeOperatorInfo(nativeHandle);
return new AsyncOperator(nativeHandle, executorHandle, info);
}
Expand Down Expand Up @@ -248,7 +268,7 @@ public CompletableFuture<List<Entry>> list(String path) {

private static native long duplicate(long nativeHandle);

private static native long constructor(long executorHandle, String schema, Map<String, String> map);
private static native long constructor(long executorHandle, String scheme, Map<String, String> map);

private static native long read(long nativeHandle, long executorHandle, String path);

Expand Down
17 changes: 14 additions & 3 deletions bindings/java/src/main/java/org/apache/opendal/Operator.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,29 @@
public class Operator extends NativeObject {
public final OperatorInfo info;

/**
* Construct an OpenDAL blocking operator.
*
* @param config the config of the underneath service to access data from.
*/
public static Operator of(ServiceConfig config) {
try (final AsyncOperator operator = AsyncOperator.of(config)) {
return operator.blocking();
}
}

/**
* Construct an OpenDAL blocking operator:
*
* <p>
* You can find all possible schemes <a href="https://docs.rs/opendal/latest/opendal/enum.Scheme.html">here</a>
* and see what config options each service supports.
*
* @param schema the name of the underneath service to access data from.
* @param scheme the name of the underneath service to access data from.
* @param map a map of properties to construct the underneath operator.
*/
public static Operator of(String schema, Map<String, String> map) {
try (final AsyncOperator operator = AsyncOperator.of(schema, map)) {
public static Operator of(String scheme, Map<String, String> map) {
try (final AsyncOperator operator = AsyncOperator.of(scheme, map)) {
return operator.blocking();
}
}
Expand Down
Loading

0 comments on commit c866d4b

Please sign in to comment.