Skip to content

Commit f088eac

Browse files
committed
Java: Configure GEDS using string types.
Signed-off-by: Pascal Spörri <[email protected]>
1 parent dfa9903 commit f088eac

9 files changed

+403
-34
lines changed

src/java/CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,22 @@
77
include(UseJava)
88

99
SET(JAVA_SOURCES
10-
com/ibm/geds/GEDSFile.java
1110
com/ibm/geds/GEDS.java
11+
com/ibm/geds/GEDSConfig.java
12+
com/ibm/geds/GEDSFile.java
13+
com/ibm/geds/GEDSFileStatus.java
1214
)
1315
SET(SOURCES
1416
com_ibm_geds_GEDS.cpp
17+
com_ibm_geds_GEDSConfig.cpp
1518
com_ibm_geds_GEDSFile.cpp
1619

1720
JavaError.cpp
1821
JavaError.h
1922
Platform.cpp
2023
)
2124

22-
set(GEDS_JAVA_VERSION 1.0)
25+
set(GEDS_JAVA_VERSION 1.1)
2326

2427
set(GEDS_JAR_GROUPID "com.ibm.geds")
2528
set(CMAKE_JAR_ARTIFACT_NAME "geds")

src/java/GEDSConfigContainer.h

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
* Copyright 2023- IBM Inc. All rights reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
#pragma once
7+
8+
#include <memory>
9+
10+
#include "GEDSConfig.h"
11+
12+
struct GEDSConfigContainer {
13+
std::shared_ptr<GEDSConfig> element;
14+
};

src/java/com/ibm/geds/GEDS.java

+27-7
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ public class GEDS {
1414
}
1515

1616
private long nativePtr = 0;
17-
public final String pathPrefix;
18-
public final String metadataServiceAddress;
17+
private final GEDSConfig config;
18+
19+
public GEDS(GEDSConfig config) {
20+
this.config = config;
21+
this.nativePtr = initGEDS(this.config.getNativePtr());
22+
}
1923

2024
/**
2125
* Constructor for GEDS.
@@ -30,41 +34,57 @@ public class GEDS {
3034
* @param blockSize Block Size used for prefetching data
3135
* (Optional). `0` indicates default block size.
3236
*/
37+
@Deprecated
3338
public GEDS(String metadataServiceAddress, String pathPrefix, String hostname, int port, long blockSize) {
3439
if (port < 0 || port > 65535) {
3540
throw new IllegalArgumentException("Invalid port.");
3641
}
3742
if (blockSize < 0) {
3843
throw new IllegalArgumentException("Invalid block size");
3944
}
40-
this.metadataServiceAddress = metadataServiceAddress;
41-
this.pathPrefix = pathPrefix;
42-
this.nativePtr = initGEDS(metadataServiceAddress, pathPrefix, hostname, port, blockSize);
45+
config = new GEDSConfig(metadataServiceAddress);
46+
if (port != 0) {
47+
config.set("port", port);
48+
}
49+
if (hostname != "") {
50+
config.set("hostname", hostname);
51+
}
52+
if (pathPrefix != "") {
53+
config.set("local_storage_path", pathPrefix);
54+
}
55+
if (blockSize != 0) {
56+
config.set("cache_block_size", blockSize);
57+
}
58+
this.nativePtr = initGEDS(config.getNativePtr());
4359
}
4460

61+
@Deprecated
4562
public GEDS(String metadataServiceAddress, String pathPrefix, int port, long blockSize) {
4663
this(metadataServiceAddress, pathPrefix, "", port, blockSize);
4764
}
4865

66+
@Deprecated
4967
public GEDS(String metadataServiceAddress, String pathPrefix, long blockSize) {
5068
this(metadataServiceAddress, pathPrefix, "", 0, blockSize);
5169
}
5270

71+
@Deprecated
5372
public GEDS(String metadataServiceAddress, String pathPrefix) {
5473
this(metadataServiceAddress, pathPrefix, "", 0, 0);
5574
}
5675

76+
@Deprecated
5777
public GEDS(String metadataServiceAddress) {
5878
this(metadataServiceAddress, "", "", 0, 0);
5979
}
6080

61-
private static native long initGEDS(String metadataServiceAddress, String pathPrefix, String hostname, int port,
62-
long blockSize);
81+
private static native long initGEDS(long nativePtrConfig);
6382

6483
public void stopGEDS() {
6584
checkGEDS();
6685
nativeStopGEDS(nativePtr);
6786
}
87+
6888
private static native void nativeStopGEDS(long ptr);
6989

7090
public static native void printStatistics();

src/java/com/ibm/geds/GEDSConfig.java

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* Copyright 2023- IBM Inc. All rights reserved
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package com.ibm.geds;
7+
8+
public class GEDSConfig {
9+
static {
10+
System.loadLibrary("geds_java");
11+
}
12+
13+
private long nativePtr = 0;
14+
15+
public long getNativePtr() {
16+
return nativePtr;
17+
}
18+
19+
public final String serverAddress;
20+
21+
public GEDSConfig(String serverAddress) {
22+
this.serverAddress = serverAddress;
23+
this.nativePtr = initGEDSConfig(serverAddress);
24+
}
25+
26+
public void set(String key, String value) {
27+
nativeSetString(nativePtr, key, value);
28+
}
29+
30+
public void set(String key, int value) {
31+
nativeSetInt(nativePtr, key, value);
32+
}
33+
34+
public void set(String key, long value) {
35+
nativeSetLong(nativePtr, key, value);
36+
}
37+
38+
public String getString(String key) {
39+
return nativeGetString(nativePtr, key);
40+
}
41+
42+
public int getInt(String key) {
43+
return nativeGetInt(nativePtr, key);
44+
}
45+
46+
public long getLong(String key) {
47+
return nativeGetLong(nativePtr, key);
48+
}
49+
50+
private static native long initGEDSConfig(String serverAddress);
51+
52+
private static native void nativeSetString(long nativePtr, String key, String value);
53+
54+
private static native void nativeSetInt(long nativePtr, String key, int value);
55+
56+
private static native void nativeSetLong(long nativePtr, String key, long value);
57+
58+
private static native String nativeGetString(long nativePtr, String key);
59+
60+
private static native int nativeGetInt(long nativePtr, String key);
61+
62+
private static native long nativeGetLong(long nativePtr, String key);
63+
}

src/java/com_ibm_geds_GEDS.cpp

+15-25
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "GEDS.h"
1414
#include "GEDSConfig.h"
15+
#include "GEDSConfigContainer.h"
1516
#include "JavaError.h"
1617
#include "Logging.h"
1718
#include "Ports.h"
@@ -22,32 +23,21 @@ struct GEDSContainer {
2223
std::shared_ptr<GEDS> element;
2324
};
2425

25-
// NOLINTNEXTLINE(modernize-use-trailing-return-type)
26+
/*
27+
* Class: com_ibm_geds_GEDS
28+
* Method: initGEDS
29+
* Signature: (J)J
30+
*/
2631
JNIEXPORT jlong JNICALL Java_com_ibm_geds_GEDS_initGEDS(JNIEnv *env, jclass,
27-
jstring metadataServiceAddressJava,
28-
jstring pathPrefixJava,
29-
jstring hostnameJava, jint port,
30-
jlong blockSize) {
31-
auto hostname = env->GetStringUTFChars(hostnameJava, nullptr);
32-
auto hostnameStr = std::string{hostname};
33-
auto pathPrefix = env->GetStringUTFChars(pathPrefixJava, nullptr);
34-
auto pathPrefixStr = std::string{pathPrefix};
35-
auto metadataServiceAddress = env->GetStringUTFChars(metadataServiceAddressJava, nullptr);
36-
auto config = GEDSConfig(metadataServiceAddress);
37-
config.hostname = hostnameStr != "" ? std::make_optional(hostnameStr) : std::nullopt;
38-
if (port != 0) {
39-
config.port = port;
40-
}
41-
if (blockSize != 0) {
42-
config.cacheBlockSize = blockSize;
43-
}
44-
if (pathPrefixStr != "") {
45-
config.localStoragePath = pathPrefixStr;
46-
}
47-
auto geds = GEDS::factory(std::move(config));
48-
env->ReleaseStringUTFChars(pathPrefixJava, pathPrefix);
49-
env->ReleaseStringUTFChars(metadataServiceAddressJava, metadataServiceAddress);
50-
env->ReleaseStringUTFChars(hostnameJava, hostname);
32+
jlong nativePtrConfig) {
33+
if (nativePtrConfig == 0) {
34+
throwNullPointerException(env, "Invalid nativePtr.");
35+
return 0;
36+
}
37+
auto container = reinterpret_cast<GEDSConfigContainer *>(nativePtrConfig); // NOLINT
38+
39+
auto geds = GEDS::factory(*(container->element));
40+
5141
auto status = geds->start();
5242
if (!status.ok()) {
5343
return throwRuntimeException(env, std::string{status.message()});

0 commit comments

Comments
 (0)