Skip to content

fix: make initializeClient a pure function #498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public LambdaRuntimeApiClientImpl(String hostnameAndPort) {
Objects.requireNonNull(hostnameAndPort, "hostnameAndPort cannot be null");
this.baseUrl = "http://" + hostnameAndPort;
this.invocationEndpoint = this.baseUrl + "/2018-06-01/runtime/invocation/";
NativeClient.init();
NativeClient.init(hostnameAndPort);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@
* interactions with the Runtime API.
*/
class NativeClient {
static void init() {
static void init(String awsLambdaRuntimeApi) {
JniHelper.load();
initializeClient(USER_AGENT.getBytes());
initializeClient(USER_AGENT.getBytes(), awsLambdaRuntimeApi.getBytes());
}

static native void initializeClient(byte[] userAgent);
static native void initializeClient(byte[] userAgent, byte[] awsLambdaRuntimeApi);

static native InvocationRequest next();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ static std::string toNativeString(JNIEnv *env, jbyteArray jArray) {
return nativeString;
}

JNIEXPORT void JNICALL Java_com_amazonaws_services_lambda_runtime_api_client_runtimeapi_NativeClient_initializeClient(JNIEnv *env, jobject thisObject, jbyteArray userAgent) {
JNIEXPORT void JNICALL Java_com_amazonaws_services_lambda_runtime_api_client_runtimeapi_NativeClient_initializeClient(JNIEnv *env, jobject thisObject, jbyteArray userAgent, jbyteArray awsLambdaRuntimeApi) {
std::string user_agent = toNativeString(env, userAgent);
std::string endpoint(getenv("AWS_LAMBDA_RUNTIME_API"));
std::string endpoint = toNativeString(env, awsLambdaRuntimeApi);
CLIENT = new aws::lambda_runtime::runtime(endpoint, user_agent);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ extern "C" {
#endif

JNIEXPORT void JNICALL Java_com_amazonaws_services_lambda_runtime_api_client_runtimeapi_NativeClient_initializeClient
(JNIEnv *, jobject, jbyteArray);
(JNIEnv *, jobject, jbyteArray, jbyteArray);

JNIEXPORT jobject JNICALL Java_com_amazonaws_services_lambda_runtime_api_client_runtimeapi_NativeClient_next
(JNIEnv *, jobject);
Expand Down