Skip to content

Commit

Permalink
Fix id caching
Browse files Browse the repository at this point in the history
  • Loading branch information
Bret Ambrose committed Dec 10, 2024
1 parent 45b2490 commit 8d8bdbf
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

package software.amazon.awssdk.crt.iot;

import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* The type of change to the state of a streaming operation subscription
*/
Expand All @@ -28,7 +33,35 @@ public enum SubscriptionStatusEventType {

private final int type;

private SubscriptionStatusEventType(int value) {
SubscriptionStatusEventType(int value) {
type = value;
}


/**
* @return the native enum integer value associated with this Java enum value
*/
public int getValue() {
return type;
}

/**
* Creates a Java SubscriptionStatusEventType enum value from a native integer value
* @param value native integer value to convert to a SubscriptionStatusEventType instance
* @return a SubscriptionStatusEventType value
*/
public static SubscriptionStatusEventType getEnumValueFromInteger(int value) {
SubscriptionStatusEventType enumValue = enumMapping.get(value);
if (enumValue != null) {
return enumValue;
}
throw new RuntimeException("Illegal SubscriptionStatusEventType");
}

private static Map<Integer, SubscriptionStatusEventType> buildEnumMapping() {
return Stream.of(SubscriptionStatusEventType.values())
.collect(Collectors.toMap(SubscriptionStatusEventType::getValue, Function.identity()));
}

private final static Map<Integer, SubscriptionStatusEventType> enumMapping = buildEnumMapping();
}
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@
"name": "software.amazon.awssdk.crt.iot.SubscriptionStatusEventType",
"methods": [
{
"name": "<init>",
"name": "getEnumValueFromInteger",
"parameterTypes": [
"int"
]
Expand Down
13 changes: 8 additions & 5 deletions src/native/java_class_ids.c
Original file line number Diff line number Diff line change
Expand Up @@ -2414,9 +2414,12 @@ static void s_cache_subscription_status_event_type_properties(JNIEnv *env) {

subscription_status_event_type_properties.subscription_status_event_type_class = (*env)->NewGlobalRef(env, cls);

subscription_status_event_type_properties.constructor_method_id = (*env)->GetMethodID(
env, subscription_status_event_type_properties.subscription_status_event_type_class, "<init>", "(I)V");
AWS_FATAL_ASSERT(subscription_status_event_type_properties.constructor_method_id);
subscription_status_event_type_properties.get_enum_value_from_integer_method_id = (*env)->GetStaticMethodID(
env,
subscription_status_event_type_properties.subscription_status_event_type_class,
"getEnumValueFromInteger",
"(I)Lsoftware/amazon/awssdk/crt/iot/SubscriptionStatusEventType;");
AWS_FATAL_ASSERT(subscription_status_event_type_properties.get_enum_value_from_integer_method_id);
}

struct java_subscription_status_event_properties subscription_status_event_properties;
Expand Down Expand Up @@ -2454,11 +2457,11 @@ static void s_cache_streaming_operation_options_properties(JNIEnv *env) {
AWS_FATAL_ASSERT(streaming_operation_options_properties.topic_field_id);

streaming_operation_options_properties.incoming_publish_event_callback_field_id =
(*env)->GetFieldID(env, cls, "incomingPublishEventCallback", "Ljava.util.function.Consumer;");
(*env)->GetFieldID(env, cls, "incomingPublishEventCallback", "Ljava/util/function/Consumer;");
AWS_FATAL_ASSERT(streaming_operation_options_properties.incoming_publish_event_callback_field_id);

streaming_operation_options_properties.subscription_status_event_callback_field_id =
(*env)->GetFieldID(env, cls, "subscriptionStatusEventCallback", "Ljava.util.function.Consumer;");
(*env)->GetFieldID(env, cls, "subscriptionStatusEventCallback", "Ljava/util/function/Consumer;");
AWS_FATAL_ASSERT(streaming_operation_options_properties.subscription_status_event_callback_field_id);
}

Expand Down
2 changes: 1 addition & 1 deletion src/native/java_class_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -1010,7 +1010,7 @@ extern struct java_incoming_publish_event_properties incoming_publish_event_prop
/* SubscriptionStatusEventType */
struct java_subscription_status_event_type_properties {
jclass subscription_status_event_type_class;
jmethodID constructor_method_id;
jmethodID get_enum_value_from_integer_method_id;
};
extern struct java_subscription_status_event_type_properties subscription_status_event_type_properties;

Expand Down

0 comments on commit 8d8bdbf

Please sign in to comment.