From 1199f90a53c12d8e464e1d6544822a90611f37be Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Sun, 17 Nov 2024 16:42:48 +0530 Subject: [PATCH] Migrate to latest Java 21 changes --- build-config/resources/Ballerina.toml | 2 +- gradle.properties | 2 +- .../stdlib/rabbitmq/MessageDispatcher.java | 26 +++------ .../rabbitmq/RabbitMQResourceCallback.java | 2 +- .../rabbitmq/RabbitMQTypeCheckCallback.java | 55 ------------------- 5 files changed, 10 insertions(+), 77 deletions(-) delete mode 100644 native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQTypeCheckCallback.java diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index 824feb06..9cc35259 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -28,4 +28,4 @@ version = "@constraint.version@" path = "./lib/constraint-native-@constraint.native.version@.jar" [build-options] -observabilityIncluded=true +observabilityIncluded=false diff --git a/gradle.properties b/gradle.properties index a1923056..a4cdc94b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.caching=true group=io.ballerina.stdlib version=3.2.0-SNAPSHOT -ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87 +ballerinaLangVersion=2201.11.0-20241117-133400-a3054b77 amqpClientVersion=5.18.0 puppycrawlCheckstyleVersion=10.12.1 diff --git a/native/src/main/java/io/ballerina/stdlib/rabbitmq/MessageDispatcher.java b/native/src/main/java/io/ballerina/stdlib/rabbitmq/MessageDispatcher.java index c453fa79..53511fe6 100644 --- a/native/src/main/java/io/ballerina/stdlib/rabbitmq/MessageDispatcher.java +++ b/native/src/main/java/io/ballerina/stdlib/rabbitmq/MessageDispatcher.java @@ -48,13 +48,12 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Semaphore; +import static io.ballerina.runtime.api.constants.RuntimeConstants.ORG_NAME_SEPARATOR; +import static io.ballerina.runtime.api.constants.RuntimeConstants.VERSION_SEPARATOR; import static io.ballerina.runtime.api.types.TypeTags.INTERSECTION_TAG; import static io.ballerina.runtime.api.types.TypeTags.OBJECT_TYPE_TAG; import static io.ballerina.runtime.api.types.TypeTags.RECORD_TYPE_TAG; -import static io.ballerina.runtime.api.constants.RuntimeConstants.ORG_NAME_SEPARATOR; -import static io.ballerina.runtime.api.constants.RuntimeConstants.VERSION_SEPARATOR; import static io.ballerina.runtime.api.utils.TypeUtils.getReferredType; import static io.ballerina.stdlib.rabbitmq.RabbitMQConstants.CONSTRAINT_VALIDATION; import static io.ballerina.stdlib.rabbitmq.RabbitMQConstants.FUNC_ON_ERROR; @@ -285,25 +284,14 @@ private boolean isMessageType(Parameter parameter, BMap annotat private boolean invokeIsAnydataMessageTypeMethod(Type paramType) { BObject client = ValueCreator.createObjectValue(ModuleUtils.getModule(), TYPE_CHECKER_OBJECT_NAME); - Semaphore sem = new Semaphore(0); - RabbitMQTypeCheckCallback messageTypeCheckCallback = new RabbitMQTypeCheckCallback(sem); StrandMetadata strandMetadata = new StrandMetadata(true, getProperties(IS_ANYDATA_MESSAGE)); - Thread.startVirtualThread(() -> { - try { - Object result = runtime.callMethod(client, IS_ANYDATA_MESSAGE, strandMetadata, - ValueCreator.createTypedescValue(paramType)); - messageTypeCheckCallback.notifySuccess(result); - } catch (BError bError) { - messageTypeCheckCallback.notifyFailure(bError); - throw bError; - } - }); try { - sem.acquire(); - } catch (InterruptedException e) { - throw returnErrorValue(e.getMessage()); + return (boolean) runtime.callMethod(client, IS_ANYDATA_MESSAGE, strandMetadata, + ValueCreator.createTypedescValue(paramType)); + } catch (BError bError) { + bError.printStackTrace(); + throw bError; } - return messageTypeCheckCallback.getIsMessageType(); } private Map getNewObserverContextInProperties() { diff --git a/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQResourceCallback.java b/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQResourceCallback.java index 85ccc69c..e92daccf 100644 --- a/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQResourceCallback.java +++ b/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQResourceCallback.java @@ -80,6 +80,6 @@ public void notifyFailure(BError error) { // Service level `panic` is captured in this method. // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the application. // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 -// System.exit(1); + System.exit(1); } } diff --git a/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQTypeCheckCallback.java b/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQTypeCheckCallback.java deleted file mode 100644 index bfe7175e..00000000 --- a/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQTypeCheckCallback.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. 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 io.ballerina.stdlib.rabbitmq; - -import io.ballerina.runtime.api.values.BError; - -import java.util.concurrent.Semaphore; - -/** - * {@code RabbitMQTypeCheckCallback} provides ability to check whether a given type is a subtype of - * rabbitmq:AnydataMessage. - */ -public class RabbitMQTypeCheckCallback { - - private final Semaphore semaphore; - private Boolean isMessageType = false; - - RabbitMQTypeCheckCallback(Semaphore semaphore) { - this.semaphore = semaphore; - } - - public void notifySuccess(Object obj) { - isMessageType = (Boolean) obj; - semaphore.release(); - } - - public void notifyFailure(BError error) { - semaphore.release(); - // Service level `panic` is captured in this method. - // Since, `panic` is due to a critical application bug or resource exhaustion we need to exit the application. - // Please refer: https://github.com/ballerina-platform/ballerina-standard-library/issues/2714 -// System.exit(1); - error.printStackTrace(); - } - - public boolean getIsMessageType() { - return isMessageType; - } -}