Skip to content

Commit

Permalink
Ready to test
Browse files Browse the repository at this point in the history
  • Loading branch information
bretambrose committed Dec 11, 2024
1 parent 39081e2 commit bb9e272
Show file tree
Hide file tree
Showing 5 changed files with 199 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
* An event that describes a change in subscription status for a streaming operation.
*/
public class SubscriptionStatusEvent {
private SubscriptionStatusEventType type;
private Optional<Integer> error;

private SubscriptionStatusEvent(SubscriptionStatusEventType type) {
this.type = type;
this.error = Optional.empty();
}
private final SubscriptionStatusEventType type;
private final Optional<Integer> error;

private SubscriptionStatusEvent(SubscriptionStatusEventType type, int errorCode) {
this.type = type;
this.error = Optional.of(errorCode);
if (errorCode != 0) {
this.error = Optional.of(errorCode);
} else {
this.error = Optional.empty();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,17 @@
}
]
},
{
"name": "java.util.function.Consumer",
"methods": [
{
"name": "accept",
"parameterTypes": [
"java.lang.Object"
]
}
]
},
{
"name": "java.util.function.Predicate",
"methods": [
Expand Down
25 changes: 16 additions & 9 deletions src/native/java_class_ids.c
Original file line number Diff line number Diff line change
Expand Up @@ -2430,19 +2430,12 @@ static void s_cache_subscription_status_event_properties(JNIEnv *env) {

subscription_status_event_properties.subscription_status_event_class = (*env)->NewGlobalRef(env, cls);

subscription_status_event_properties.constructor_method_id1 = (*env)->GetMethodID(
env,
subscription_status_event_properties.subscription_status_event_class,
"<init>",
"(Lsoftware/amazon/awssdk/crt/iot/SubscriptionStatusEventType;)V");
AWS_FATAL_ASSERT(subscription_status_event_properties.constructor_method_id1);

subscription_status_event_properties.constructor_method_id2 = (*env)->GetMethodID(
subscription_status_event_properties.constructor_method_id = (*env)->GetMethodID(
env,
subscription_status_event_properties.subscription_status_event_class,
"<init>",
"(Lsoftware/amazon/awssdk/crt/iot/SubscriptionStatusEventType;I)V");
AWS_FATAL_ASSERT(subscription_status_event_properties.constructor_method_id2);
AWS_FATAL_ASSERT(subscription_status_event_properties.constructor_method_id);
}

struct java_streaming_operation_options_properties streaming_operation_options_properties;
Expand All @@ -2465,6 +2458,19 @@ static void s_cache_streaming_operation_options_properties(JNIEnv *env) {
AWS_FATAL_ASSERT(streaming_operation_options_properties.subscription_status_event_callback_field_id);
}

struct java_consumer_properties consumer_properties;

static void s_cache_consumer_properties(JNIEnv *env) {
jclass cls = (*env)->FindClass(env, "java/util/function/Consumer");
AWS_FATAL_ASSERT(cls);

consumer_properties.consumer_class = (*env)->NewGlobalRef(env, cls);

consumer_properties.accept_method_id =
(*env)->GetMethodID(env, consumer_properties.consumer_class, "accept", "(Ljava/lang/Object;)V");
AWS_FATAL_ASSERT(consumer_properties.accept_method_id);
}

static void s_cache_java_class_ids(void *user_data) {
JNIEnv *env = user_data;
s_cache_http_request_body_stream(env);
Expand Down Expand Up @@ -2577,6 +2583,7 @@ static void s_cache_java_class_ids(void *user_data) {
s_cache_subscription_status_event_type_properties(env);
s_cache_subscription_status_event_properties(env);
s_cache_streaming_operation_options_properties(env);
s_cache_consumer_properties(env);
}

static aws_thread_once s_cache_once_init = AWS_THREAD_ONCE_STATIC_INIT;
Expand Down
10 changes: 8 additions & 2 deletions src/native/java_class_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -1017,8 +1017,7 @@ extern struct java_subscription_status_event_type_properties subscription_status
/* SubscriptionStatusEvent */
struct java_subscription_status_event_properties {
jclass subscription_status_event_class;
jmethodID constructor_method_id1; // SubscriptionStatusEvent(SubscriptionStatusEventType type)
jmethodID constructor_method_id2; // SubscriptionStatusEvent(SubscriptionStatusEventType type, int errorCode)
jmethodID constructor_method_id;
};
extern struct java_subscription_status_event_properties subscription_status_event_properties;

Expand All @@ -1031,6 +1030,13 @@ struct java_streaming_operation_options_properties {
};
extern struct java_streaming_operation_options_properties streaming_operation_options_properties;

/* Consumer */
struct java_consumer_properties {
jclass consumer_class;
jmethodID accept_method_id;
};
extern struct java_consumer_properties consumer_properties;

/**
* All functions bound to JNI MUST call this before doing anything else.
* This caches all JNI IDs the first time it is called. Any further calls are no-op; it is thread-safe.
Expand Down
Loading

0 comments on commit bb9e272

Please sign in to comment.