-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [env] Support JNI of FlinkEnv
- Loading branch information
Showing
5 changed files
with
129 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
#include "env/flink/env_flink.h" | ||
|
||
#include <jni.h> | ||
|
||
#include <vector> | ||
|
||
#include "java/rocksjni/portal.h" | ||
#include "rocksdb/env.h" | ||
|
||
/* | ||
* Class: org_rocksdb_FlinkEnv | ||
* Method: createFlinkEnv | ||
* Signature: (Ljava/lang/String;)J | ||
*/ | ||
jlong Java_org_rocksdb_FlinkEnv_createFlinkEnv(JNIEnv* env, jclass, | ||
jstring base_path) { | ||
jboolean has_exception = JNI_FALSE; | ||
auto path = | ||
ROCKSDB_NAMESPACE::JniUtil::copyStdString(env, base_path, &has_exception); | ||
if (has_exception == JNI_TRUE) { | ||
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew( | ||
env, "Could not copy jstring to std::string"); | ||
return 0; | ||
} | ||
std::unique_ptr<ROCKSDB_NAMESPACE::Env> flink_env; | ||
auto status = ROCKSDB_NAMESPACE::NewFlinkEnv(path, &flink_env); | ||
if (!status.ok()) { | ||
ROCKSDB_NAMESPACE::RocksDBExceptionJni::ThrowNew(env, status); | ||
return 0; | ||
} | ||
auto ptr_as_handle = flink_env.release(); | ||
return reinterpret_cast<jlong>(ptr_as_handle); | ||
} | ||
|
||
/* | ||
* Class: org_rocksdb_FlinkEnv | ||
* Method: disposeInternal | ||
* Signature: (J)V | ||
*/ | ||
void Java_org_rocksdb_FlinkEnv_disposeInternal(JNIEnv*, jobject, | ||
jlong jhandle) { | ||
auto* handle = reinterpret_cast<ROCKSDB_NAMESPACE::Env*>(jhandle); | ||
assert(handle != nullptr); | ||
delete handle; | ||
} |
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,41 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you 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. | ||
*/ | ||
|
||
package org.rocksdb; | ||
|
||
/** | ||
* Flink Env which proxy all filesystem access to Flink FileSystem. | ||
*/ | ||
public class FlinkEnv extends Env { | ||
/** | ||
<p>Creates a new environment that is used for Flink environment.</p> | ||
* | ||
* <p>The caller must delete the result when it is | ||
* no longer needed.</p> | ||
* | ||
* @param basePath the base path string for the given Flink file system, | ||
* formatted as "{fs-schema-supported-by-flink}://xxx" | ||
*/ | ||
public FlinkEnv(final String basePath) { | ||
super(createFlinkEnv(basePath)); | ||
} | ||
|
||
private static native long createFlinkEnv(final String basePath); | ||
|
||
@Override protected final native void disposeInternal(final long handle); | ||
} |
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