From 5476caf7b2d7e5157ede157eecabe6fc1e4d6298 Mon Sep 17 00:00:00 2001 From: ravinperera00 Date: Sun, 17 Nov 2024 00:28:15 +0530 Subject: [PATCH] Migrate to new Runtime APIs --- .../workflows/build-timestamped-master.yml | 2 +- .../workflows/build-with-bal-test-graalvm.yml | 2 +- .../workflows/build-with-ballerina-lang.yml | 8 +- .github/workflows/central-publish.yml | 2 +- .github/workflows/daily-build.yml | 4 +- .../workflows/process-load-test-result.yml | 2 +- .github/workflows/publish-release.yml | 2 +- .github/workflows/pull-request.yml | 2 +- .github/workflows/trigger-load-tests.yml | 2 +- .github/workflows/trivy-scan.yml | 2 +- README.md | 2 +- ballerina/Ballerina.toml | 20 ++-- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 49 +++++---- build-config/resources/Ballerina.toml | 10 +- build.gradle | 8 +- compiler-plugin-tests/build.gradle | 7 +- compiler-plugin/build.gradle | 7 +- gradle.properties | 48 +++++---- native/build.gradle | 7 +- .../stdlib/rabbitmq/MessageDispatcher.java | 102 +++++++++--------- .../rabbitmq/RabbitMQResourceCallback.java | 7 +- .../rabbitmq/RabbitMQTypeCheckCallback.java | 7 +- .../stdlib/rabbitmq/RabbitMQUtils.java | 8 +- .../stdlib/rabbitmq/util/ListenerUtils.java | 6 +- .../stdlib/rabbitmq/util/MessageUtils.java | 2 +- 26 files changed, 172 insertions(+), 148 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index ec5df0ff..f0cc8f7e 100644 --- a/.github/workflows/build-timestamped-master.yml +++ b/.github/workflows/build-timestamped-master.yml @@ -14,5 +14,5 @@ jobs: call_workflow: name: Run Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@java21 secrets: inherit diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index d8320dc1..503f7140 100644 --- a/.github/workflows/build-with-bal-test-graalvm.yml +++ b/.github/workflows/build-with-bal-test-graalvm.yml @@ -30,7 +30,7 @@ jobs: call_stdlib_workflow: name: Run StdLib Workflow if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} - uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@java21 with: lang_tag: ${{ inputs.lang_tag }} lang_version: ${{ inputs.lang_version }} diff --git a/.github/workflows/build-with-ballerina-lang.yml b/.github/workflows/build-with-ballerina-lang.yml index a2d18d67..eb020988 100644 --- a/.github/workflows/build-with-ballerina-lang.yml +++ b/.github/workflows/build-with-ballerina-lang.yml @@ -30,11 +30,11 @@ jobs: repository: 'ballerina-platform/ballerina-lang' ref: ${{ inputs.lang_tag || 'master' }} - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: 17.0.7 + java-version: 21.0.3 - name: Set Ballerina Lang version run: | @@ -77,11 +77,11 @@ jobs: repository: 'ballerina-platform/ballerina-lang' ref: ${{ inputs.lang_tag || 'master' }} - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: 17.0.7 + java-version: 21.0.3 - name: Set Ballerina Lang version run: | diff --git a/.github/workflows/central-publish.yml b/.github/workflows/central-publish.yml index 6bd74c44..0dcae97c 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -16,7 +16,7 @@ jobs: call_workflow: name: Run Central Publish Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@java21 secrets: inherit with: environment: ${{ github.event.inputs.environment }} diff --git a/.github/workflows/daily-build.yml b/.github/workflows/daily-build.yml index 264a639f..f4e024be 100644 --- a/.github/workflows/daily-build.yml +++ b/.github/workflows/daily-build.yml @@ -12,11 +12,11 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Set up JDK 17 + - name: Set up JDK 21 uses: actions/setup-java@v3 with: distribution: 'temurin' - java-version: 17.0.7 + java-version: 21.0.3 - name: Set environment variable if: github.event.action == 'check_connector_for_breaking_changes' diff --git a/.github/workflows/process-load-test-result.yml b/.github/workflows/process-load-test-result.yml index 97d84249..13514670 100644 --- a/.github/workflows/process-load-test-result.yml +++ b/.github/workflows/process-load-test-result.yml @@ -6,7 +6,7 @@ on: jobs: call_stdlib_process_load_test_results_workflow: name: Run StdLib Process Load Test Results Workflow - uses: ballerina-platform/ballerina-library/.github/workflows/process-load-test-results-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/process-load-test-results-template.yml@java21 with: results: ${{ toJson(github.event.client_payload.results) }} secrets: diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index 2c29d16f..2e7bb0aa 100644 --- a/.github/workflows/publish-release.yml +++ b/.github/workflows/publish-release.yml @@ -9,7 +9,7 @@ jobs: call_workflow: name: Run Release Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@java21 secrets: inherit with: package-name: rabbitmq diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index fdfe23fe..da5b6c88 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -6,7 +6,7 @@ jobs: call_workflow: name: Run PR Build Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@java21 with: additional-windows-test-flags: "-x test" secrets: inherit diff --git a/.github/workflows/trigger-load-tests.yml b/.github/workflows/trigger-load-tests.yml index 79c93971..c28ad2cc 100644 --- a/.github/workflows/trigger-load-tests.yml +++ b/.github/workflows/trigger-load-tests.yml @@ -22,7 +22,7 @@ jobs: call_stdlib_trigger_load_test_workflow: name: Run StdLib Load Test Workflow if: ${{ github.event_name != 'schedule' || (github.event_name == 'schedule' && github.repository_owner == 'ballerina-platform') }} - uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@java21 with: repo_name: 'module-ballerinax-rabbitmq' runtime_artifacts_url: 'https://api.github.com/repos/ballerina-platform/module-ballerinax-rabbitmq/actions/artifacts' diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 2f7999de..684db291 100644 --- a/.github/workflows/trivy-scan.yml +++ b/.github/workflows/trivy-scan.yml @@ -9,5 +9,5 @@ jobs: call_workflow: name: Run Trivy Scan Workflow if: ${{ github.repository_owner == 'ballerina-platform' }} - uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main + uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@java21 secrets: inherit diff --git a/README.md b/README.md index 09f4faca..83691e79 100644 --- a/README.md +++ b/README.md @@ -194,7 +194,7 @@ This repository only contains the source code for the library. ### Set up the prerequisites -* Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations). +* Download and install Java SE Development Kit (JDK) version 21 (from one of the following locations). * [Oracle](https://www.oracle.com/java/technologies/downloads/) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 9a70295a..7888b1c0 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,31 +1,31 @@ [package] org = "ballerinax" name = "rabbitmq" -version = "3.1.1" +version = "3.2.0" authors = ["Ballerina"] keywords = ["service", "client", "messaging", "network", "pubsub"] repository = "https://github.com/ballerina-platform/module-ballerinax-rabbitmq" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.10.0" +distribution = "2201.11.0-20241112-214900-6b80ab87" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] path = "./lib/amqp-client-5.18.0.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "rabbitmq-native" -version = "3.1.1" -path = "../native/build/libs/rabbitmq-native-3.1.1-SNAPSHOT.jar" +version = "3.2.0" +path = "../native/build/libs/rabbitmq-native-3.2.0-SNAPSHOT.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "constraint-native" -version = "1.5.0" -path = "./lib/constraint-native-1.5.0.jar" +version = "1.6.0" +path = "./lib/constraint-native-1.6.0-20241113-090900-d276ad5.jar" [build-options] observabilityIncluded=true diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index f058e27c..da6cb0b3 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "rabbitmq-compiler-plugin" class = "io.ballerina.stdlib.rabbitmq.plugin.RabbitmqCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/rabbitmq-compiler-plugin-3.1.1-SNAPSHOT.jar" +path = "../compiler-plugin/build/libs/rabbitmq-compiler-plugin-3.2.0-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 7f49c584..0a66d311 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,12 +5,12 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.10.0" +distribution-version = "2201.11.0-20241112-214900-6b80ab87" [[package]] org = "ballerina" name = "auth" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "crypto"}, @@ -23,7 +23,7 @@ dependencies = [ [[package]] org = "ballerina" name = "cache" -version = "3.8.0" +version = "3.8.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "constraint"}, @@ -35,7 +35,7 @@ dependencies = [ [[package]] org = "ballerina" name = "constraint" -version = "1.5.0" +version = "1.6.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} @@ -47,7 +47,7 @@ modules = [ [[package]] org = "ballerina" name = "crypto" -version = "2.7.2" +version = "2.7.3" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "time"} @@ -56,10 +56,20 @@ modules = [ {org = "ballerina", packageName = "crypto", moduleName = "crypto"} ] +[[package]] +org = "ballerina" +name = "data.jsondata" +version = "0.3.0" +scope = "testOnly" +dependencies = [ + {org = "ballerina", name = "jballerina.java"}, + {org = "ballerina", name = "lang.object"} +] + [[package]] org = "ballerina" name = "file" -version = "1.10.0" +version = "1.10.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "io"}, @@ -71,13 +81,14 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.13.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "crypto"}, + {org = "ballerina", name = "data.jsondata"}, {org = "ballerina", name = "file"}, {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -100,7 +111,7 @@ dependencies = [ [[package]] org = "ballerina" name = "io" -version = "1.6.1" +version = "1.6.2" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"}, @@ -118,7 +129,7 @@ modules = [ [[package]] org = "ballerina" name = "jwt" -version = "2.13.0" +version = "2.13.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "cache"}, @@ -241,7 +252,7 @@ modules = [ [[package]] org = "ballerina" name = "log" -version = "2.10.0" +version = "2.10.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "io"}, @@ -256,7 +267,7 @@ modules = [ [[package]] org = "ballerina" name = "mime" -version = "2.10.0" +version = "2.10.2" scope = "testOnly" dependencies = [ {org = "ballerina", name = "io"}, @@ -268,7 +279,7 @@ dependencies = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.12.0" +version = "2.12.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "cache"}, @@ -282,7 +293,7 @@ dependencies = [ [[package]] org = "ballerina" name = "observe" -version = "1.3.0" +version = "1.4.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -290,7 +301,7 @@ dependencies = [ [[package]] org = "ballerina" name = "os" -version = "1.8.0" +version = "1.8.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "io"}, @@ -300,7 +311,7 @@ dependencies = [ [[package]] org = "ballerina" name = "task" -version = "2.5.0" +version = "2.5.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"}, @@ -324,7 +335,7 @@ modules = [ [[package]] org = "ballerina" name = "time" -version = "2.4.0" +version = "2.6.0" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -332,7 +343,7 @@ dependencies = [ [[package]] org = "ballerina" name = "url" -version = "2.4.0" +version = "2.4.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} @@ -341,7 +352,7 @@ dependencies = [ [[package]] org = "ballerina" name = "uuid" -version = "1.8.0" +version = "1.8.1" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, @@ -389,7 +400,7 @@ modules = [ [[package]] org = "ballerinax" name = "rabbitmq" -version = "3.1.1" +version = "3.2.0" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "crypto"}, diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index 1685be1d..824feb06 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -7,21 +7,21 @@ keywords = ["service", "client", "messaging", "network", "pubsub"] repository = "https://github.com/ballerina-platform/module-ballerinax-rabbitmq" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.11.0" +distribution = "2201.11.0-20241112-214900-6b80ab87" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] path = "./lib/amqp-client-@amqp.client.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "rabbitmq-native" version = "@toml.version@" path = "../native/build/libs/rabbitmq-native-@project.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "constraint-native" version = "@constraint.version@" diff --git a/build.gradle b/build.gradle index 5938d983..1cc67cf4 100644 --- a/build.gradle +++ b/build.gradle @@ -17,10 +17,10 @@ */ plugins { - id "com.github.spotbugs" version "5.0.14" - id "com.github.johnrengelman.shadow" version "8.1.1" - id "de.undercouch.download" version "5.4.0" - id "net.researchgate.release" version "2.8.0" + id "com.github.spotbugs" version "${spotbugsPluginVersion}" + id "com.github.johnrengelman.shadow" version "${shadowJarPluginVersion}" + id "de.undercouch.download" version "${downloadPluginVersion}" + id "net.researchgate.release" version "${releasePluginVersion}" } allprojects { diff --git a/compiler-plugin-tests/build.gradle b/compiler-plugin-tests/build.gradle index baba99d2..48b1944c 100644 --- a/compiler-plugin-tests/build.gradle +++ b/compiler-plugin-tests/build.gradle @@ -49,8 +49,11 @@ checkstyle { checkstyleTest.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") spotbugsTest { - effort "max" - reportLevel "low" + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW reportsDir = file("$project.buildDir/reports/spotbugs") reports { html.enabled true diff --git a/compiler-plugin/build.gradle b/compiler-plugin/build.gradle index 09df0290..cee10ad6 100644 --- a/compiler-plugin/build.gradle +++ b/compiler-plugin/build.gradle @@ -45,8 +45,11 @@ tasks.withType(Checkstyle) { checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") spotbugsMain { - effort "max" - reportLevel "low" + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW reportsDir = file("$project.buildDir/reports/spotbugs") reports { html.enabled true diff --git a/gradle.properties b/gradle.properties index c2cbe8ea..a1923056 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,42 +1,46 @@ org.gradle.caching=true group=io.ballerina.stdlib version=3.2.0-SNAPSHOT -ballerinaLangVersion=2201.11.0-20241008-112400-81975006 +ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87 amqpClientVersion=5.18.0 puppycrawlCheckstyleVersion=10.12.1 testngVersion=7.6.1 slf4jVersion=1.7.30 ballerinaGradlePluginVersion=2.0.1 +spotbugsPluginVersion=6.0.18 +shadowJarPluginVersion=8.1.1 +downloadPluginVersion=5.4.0 +releasePluginVersion=2.8.0 gsonVersion=2.8.8 # stdlib dependencies -stdlibIoVersion=1.6.1 -stdlibTimeVersion=2.4.0 -stdlibUrlVersion=2.4.0 +stdlibIoVersion=1.6.2-20241112-233100-995cf5f +stdlibTimeVersion=2.6.0-20241113-073800-201b904 +stdlibUrlVersion=2.4.1-20241113-073900-335ff51 -stdlibConstraintVersion=1.5.0 -stdlibCryptoVersion=2.7.2 -stdlibLogVersion=2.10.0 -stdlibOsVersion=1.8.0 -stdlibRandomVersion=1.5.0 -stdlibTaskVersion=2.5.0 +stdlibConstraintVersion=1.6.0-20241113-090900-d276ad5 +stdlibCryptoVersion=2.7.3-20241113-081400-d015a39 +stdlibLogVersion=2.10.1-20241113-120000-4577868 +stdlibOsVersion=1.8.1-20241113-122000-cca973b +stdlibRandomVersion=1.5.1-20241113-122300-1bc770e +stdlibTaskVersion=2.5.1-20241113-123500-f905281 -stdlibCacheVersion=3.8.0 -stdlibFileVersion=1.10.0 -stdlibMimeVersion=2.10.0 -stdlibUuidVersion=1.8.0 +stdlibCacheVersion=3.8.1-20241113-125700-b75a1bf +stdlibFileVersion=1.10.1-20241113-151700-e1a2e38 +stdlibMimeVersion=2.10.2-20241113-154200-d953747 +stdlibUuidVersion=1.8.1-20241113-154400-443c67b -stdlibAuthVersion=2.12.0 -stdlibDataJsonDataVersion=0.3.0-20241105-101100-661d11f -stdlibJwtVersion=2.13.0 -stdlibOAuth2Version=2.12.0 +stdlibAuthVersion=2.12.1-20241113-162300-ded40eb +stdlibDataJsonDataVersion=0.3.0-20241114-143900-285d739 +stdlibJwtVersion=2.13.1-20241113-162400-b59ccfa +stdlibOAuth2Version=2.12.1-20241113-162400-4c6ddfe -stdlibHttpVersion=2.13.0-20241106-120000-d375c3b +stdlibHttpVersion=2.13.0-20241114-182900-7e9f66a -stdlibTransactionVersion=1.10.0 +stdlibTransactionVersion=1.10.1-20241116-112500-189a4e5 # Ballerinax Observer -observeVersion=1.3.0 -observeInternalVersion=1.3.0 +observeVersion=1.4.0-20241113-092000-b83ae74 +observeInternalVersion=1.3.1-20241113-101700-265054d diff --git a/native/build.gradle b/native/build.gradle index 6a1b977b..d068194e 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -49,8 +49,11 @@ tasks.withType(Checkstyle) { checkstyleMain.dependsOn(":checkstyle:downloadCheckstyleRuleFiles") spotbugsMain { - effort "max" - reportLevel "low" + def classLoader = plugins["com.github.spotbugs"].class.classLoader + def SpotBugsConfidence = classLoader.findLoadedClass("com.github.spotbugs.snom.Confidence") + def SpotBugsEffort = classLoader.findLoadedClass("com.github.spotbugs.snom.Effort") + effort = SpotBugsEffort.MAX + reportLevel = SpotBugsConfidence.LOW reportsDir = file("$project.buildDir/reports/spotbugs") reports { html.enabled true 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 98dfeffd..c453fa79 100644 --- a/native/src/main/java/io/ballerina/stdlib/rabbitmq/MessageDispatcher.java +++ b/native/src/main/java/io/ballerina/stdlib/rabbitmq/MessageDispatcher.java @@ -23,10 +23,8 @@ import com.rabbitmq.client.Channel; import com.rabbitmq.client.DefaultConsumer; import com.rabbitmq.client.Envelope; -import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.Runtime; -import io.ballerina.runtime.api.async.Callback; -import io.ballerina.runtime.api.async.StrandMetadata; +import io.ballerina.runtime.api.concurrent.StrandMetadata; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.types.MethodType; import io.ballerina.runtime.api.types.ObjectType; @@ -52,9 +50,9 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.Semaphore; -import static io.ballerina.runtime.api.TypeTags.INTERSECTION_TAG; -import static io.ballerina.runtime.api.TypeTags.OBJECT_TYPE_TAG; -import static io.ballerina.runtime.api.TypeTags.RECORD_TYPE_TAG; +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; @@ -109,7 +107,7 @@ private String getQueueNameFromConfig(BObject service) { .getAnnotation(StringUtils.fromString(ModuleUtils.getModule().getOrg() + ORG_NAME_SEPARATOR + ModuleUtils.getModule().getName() + VERSION_SEPARATOR - + ModuleUtils.getModule().getVersion() + ":" + + ModuleUtils.getModule().getMajorVersion() + ":" + RabbitMQConstants.SERVICE_CONFIG)); return serviceConfig.getStringValue(RabbitMQConstants.ALIAS_QUEUE_NAME).getValue(); } @@ -146,8 +144,8 @@ public void handleDelivery(String consumerTag, private void handleDispatch(byte[] message, Envelope envelope, AMQP.BasicProperties properties) { CountDownLatch countDownLatch = new CountDownLatch(1); - Callback callback = new RabbitMQResourceCallback(countDownLatch, channel, queueName, message.length, - properties.getReplyTo(), envelope.getExchange()); + RabbitMQResourceCallback callback = new RabbitMQResourceCallback(countDownLatch, channel, queueName, + message.length, properties.getReplyTo(), envelope.getExchange()); try { if (properties.getReplyTo() != null && getAttachedFunctionType(service, FUNC_ON_REQUEST) != null) { MethodType onRequestFunction = getAttachedFunctionType(service, FUNC_ON_REQUEST); @@ -181,7 +179,7 @@ private Object[] getResourceParameters(byte[] message, Envelope envelope, AMQP.B boolean messageExists = false; boolean payloadExists = false; boolean constraintValidation = (boolean) listenerObj.getNativeData(CONSTRAINT_VALIDATION); - Object[] arguments = new Object[parameters.length * 2]; + Object[] arguments = new Object[parameters.length]; int index = 0; for (Parameter parameter : parameters) { Type referredType = getReferredType(parameter.type); @@ -220,7 +218,6 @@ private Object[] getResourceParameters(byte[] message, Envelope envelope, AMQP.B arguments[index++] = value; break; } - arguments[index++] = true; } return arguments; } @@ -238,47 +235,41 @@ private BObject getCallerBObject(long deliveryTag) { return callerObj; } - private void executeResourceOnMessage(Callback callback, Type returnType, Object... args) { - StrandMetadata metadata = new StrandMetadata(ORG_NAME, RABBITMQ, - ModuleUtils.getModule().getVersion(), FUNC_ON_MESSAGE); - executeResource(RabbitMQConstants.FUNC_ON_MESSAGE, callback, metadata, returnType, args); + private void executeResourceOnMessage(RabbitMQResourceCallback callback, Type returnType, Object... args) { + executeResource(RabbitMQConstants.FUNC_ON_MESSAGE, callback, args); } - private void executeResourceOnRequest(Callback callback, Type returnType, Object... args) { - StrandMetadata metadata = new StrandMetadata(ORG_NAME, RABBITMQ, - ModuleUtils.getModule().getVersion(), FUNC_ON_REQUEST); - executeResource(FUNC_ON_REQUEST, callback, metadata, returnType, args); + private void executeResourceOnRequest(RabbitMQResourceCallback callback, Type returnType, Object... args) { + executeResource(FUNC_ON_REQUEST, callback, args); } private void executeOnError(MethodType onErrorMethod, byte[] message, Envelope envelope, AMQP.BasicProperties properties, BError bError) { - StrandMetadata metadata = new StrandMetadata(ORG_NAME, RABBITMQ, - ModuleUtils.getModule().getVersion(), FUNC_ON_ERROR); - executeResource(FUNC_ON_ERROR, null, metadata, onErrorMethod.getReturnType(), - createAndPopulateMessageRecord(message, envelope, properties, - getReferredType(onErrorMethod.getParameters()[0].type)), true, bError, true); + executeResource(FUNC_ON_ERROR, null, createAndPopulateMessageRecord(message, envelope, properties, + getReferredType(onErrorMethod.getParameters()[0].type)), bError); } - private void executeResource(String function, Callback callback, StrandMetadata metaData, Type returnType, - Object... args) { + private void executeResource(String function, RabbitMQResourceCallback callback, Object... args) { ObjectType serviceType = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(service)); - if (ObserveUtils.isTracingEnabled()) { - if (serviceType.isIsolated() && serviceType.isIsolated(function)) { - runtime.invokeMethodAsyncConcurrently(service, function, null, metaData, callback, - getNewObserverContextInProperties(), returnType, args); - } else { - runtime.invokeMethodAsyncSequentially(service, function, null, metaData, callback, - getNewObserverContextInProperties(), returnType, args); + Thread.startVirtualThread(() -> { + Map properties = getProperties(function); + if (ObserveUtils.isTracingEnabled()) { + properties = getNewObserverContextInProperties(); } - return; - } - if (serviceType.isIsolated() && serviceType.isIsolated(function)) { - runtime.invokeMethodAsyncConcurrently(service, function, null, metaData, callback, null, - returnType, args); - } else { - runtime.invokeMethodAsyncSequentially(service, function, null, metaData, callback, null, - returnType, args); - } + boolean isConcurrentSafe = serviceType.isIsolated() && serviceType.isIsolated(function); + StrandMetadata strandMetadata = new StrandMetadata(isConcurrentSafe, properties); + try { + Object result = runtime.callMethod(service, function, strandMetadata, args); + if (callback != null) { + callback.notifySuccess(result); + } + } catch (BError bError) { + if (callback != null) { + callback.notifyFailure(bError); + } + throw bError; + } + }); } private boolean isMessageType(Parameter parameter, BMap annotations) { @@ -296,15 +287,21 @@ 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 metadata = new StrandMetadata(ORG_NAME, RABBITMQ, - ModuleUtils.getModule().getVersion(), IS_ANYDATA_MESSAGE); - runtime.invokeMethodAsyncSequentially(client, IS_ANYDATA_MESSAGE, null, metadata, - messageTypeCheckCallback, null, PredefinedTypes.TYPE_BOOLEAN, - ValueCreator.createTypedescValue(paramType), true); + 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) { - returnErrorValue(e.getMessage()); + throw returnErrorValue(e.getMessage()); } return messageTypeCheckCallback.getIsMessageType(); } @@ -329,4 +326,13 @@ private static MethodType getAttachedFunctionType(BObject serviceObject, String } return function; } + + public static Map getProperties(String resourceName) { + Map properties = new HashMap<>(); + properties.put("moduleOrg", ORG_NAME); + properties.put("moduleName", RABBITMQ); + properties.put("moduleVersion", ModuleUtils.getModule().getMajorVersion()); + properties.put("parentFunctionName", resourceName); + return properties; + } } 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 7a48a6fc..85ccc69c 100644 --- a/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQResourceCallback.java +++ b/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQResourceCallback.java @@ -19,7 +19,6 @@ package io.ballerina.stdlib.rabbitmq; import com.rabbitmq.client.Channel; -import io.ballerina.runtime.api.async.Callback; import io.ballerina.runtime.api.values.BError; import io.ballerina.stdlib.rabbitmq.observability.RabbitMQMetricsUtil; import io.ballerina.stdlib.rabbitmq.observability.RabbitMQObservabilityConstants; @@ -33,7 +32,7 @@ * * @since 0.995.0 */ -public class RabbitMQResourceCallback implements Callback { +public class RabbitMQResourceCallback { private final CountDownLatch countDownLatch; private final Channel channel; private final String queueName; @@ -59,7 +58,6 @@ public class RabbitMQResourceCallback implements Callback { } - @Override public void notifySuccess(Object obj) { if (obj instanceof BError) { ((BError) obj).printStackTrace(); @@ -75,7 +73,6 @@ public void notifySuccess(Object obj) { countDownLatch.countDown(); } - @Override public void notifyFailure(BError error) { countDownLatch.countDown(); RabbitMQMetricsUtil.reportError(channel, RabbitMQObservabilityConstants.ERROR_TYPE_DISPATCH); @@ -83,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 index 16206a82..bfe7175e 100644 --- a/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQTypeCheckCallback.java +++ b/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQTypeCheckCallback.java @@ -18,7 +18,6 @@ package io.ballerina.stdlib.rabbitmq; -import io.ballerina.runtime.api.async.Callback; import io.ballerina.runtime.api.values.BError; import java.util.concurrent.Semaphore; @@ -27,7 +26,7 @@ * {@code RabbitMQTypeCheckCallback} provides ability to check whether a given type is a subtype of * rabbitmq:AnydataMessage. */ -public class RabbitMQTypeCheckCallback implements Callback { +public class RabbitMQTypeCheckCallback { private final Semaphore semaphore; private Boolean isMessageType = false; @@ -36,19 +35,17 @@ public class RabbitMQTypeCheckCallback implements Callback { this.semaphore = semaphore; } - @Override public void notifySuccess(Object obj) { isMessageType = (Boolean) obj; semaphore.release(); } - @Override 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); +// System.exit(1); error.printStackTrace(); } diff --git a/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQUtils.java b/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQUtils.java index 97c408b0..05a4ecb3 100644 --- a/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/rabbitmq/RabbitMQUtils.java @@ -20,13 +20,13 @@ import com.rabbitmq.client.AMQP; import com.rabbitmq.client.Envelope; -import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.creators.ErrorCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.types.ArrayType; import io.ballerina.runtime.api.types.IntersectionType; import io.ballerina.runtime.api.types.RecordType; import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.types.UnionType; import io.ballerina.runtime.api.utils.JsonUtils; import io.ballerina.runtime.api.utils.StringUtils; @@ -45,9 +45,9 @@ import java.util.ArrayList; import java.util.Map; -import static io.ballerina.runtime.api.TypeTags.INTERSECTION_TAG; -import static io.ballerina.runtime.api.TypeTags.STRING_TAG; -import static io.ballerina.runtime.api.TypeTags.UNION_TAG; +import static io.ballerina.runtime.api.types.TypeTags.INTERSECTION_TAG; +import static io.ballerina.runtime.api.types.TypeTags.STRING_TAG; +import static io.ballerina.runtime.api.types.TypeTags.UNION_TAG; import static io.ballerina.stdlib.rabbitmq.RabbitMQConstants.MESSAGE_CONTENT_FIELD; import static io.ballerina.stdlib.rabbitmq.RabbitMQConstants.MESSAGE_DELIVERY_TAG_FIELD; import static io.ballerina.stdlib.rabbitmq.RabbitMQConstants.MESSAGE_EXCHANGE_FIELD; diff --git a/native/src/main/java/io/ballerina/stdlib/rabbitmq/util/ListenerUtils.java b/native/src/main/java/io/ballerina/stdlib/rabbitmq/util/ListenerUtils.java index 66bb5b6d..ac78501f 100644 --- a/native/src/main/java/io/ballerina/stdlib/rabbitmq/util/ListenerUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/rabbitmq/util/ListenerUtils.java @@ -23,9 +23,9 @@ import com.rabbitmq.client.ShutdownSignalException; import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Runtime; -import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.types.AnnotatableType; import io.ballerina.runtime.api.types.ObjectType; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BMap; @@ -170,7 +170,7 @@ private static void declareQueueIfNotExists(BObject service, Channel channel) th BMap serviceConfig = (BMap) ((AnnotatableType) TypeUtils.getType(service)) .getAnnotation(StringUtils.fromString(ModuleUtils.getModule().getOrg() + ORG_NAME_SEPARATOR + ModuleUtils.getModule().getName() + VERSION_SEPARATOR - + ModuleUtils.getModule().getVersion() + ":" + + ModuleUtils.getModule().getMajorVersion() + ":" + RabbitMQConstants.SERVICE_CONFIG)); String queueName = ""; Map argumentsMap = new HashMap<>(); @@ -244,7 +244,7 @@ private static boolean getAckMode(BObject service) { BMap serviceConfig = (BMap) serviceType .getAnnotation(StringUtils.fromString(ModuleUtils.getModule().getOrg() + ORG_NAME_SEPARATOR + ModuleUtils.getModule().getName() + VERSION_SEPARATOR - + ModuleUtils.getModule().getVersion() + ":" + + ModuleUtils.getModule().getMajorVersion() + ":" + RabbitMQConstants.SERVICE_CONFIG)); boolean autoAck = true; if (serviceConfig != null && serviceConfig.containsKey(RabbitMQConstants.AUTO_ACK)) { diff --git a/native/src/main/java/io/ballerina/stdlib/rabbitmq/util/MessageUtils.java b/native/src/main/java/io/ballerina/stdlib/rabbitmq/util/MessageUtils.java index 09776852..f7b9752c 100644 --- a/native/src/main/java/io/ballerina/stdlib/rabbitmq/util/MessageUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/rabbitmq/util/MessageUtils.java @@ -21,7 +21,7 @@ import com.rabbitmq.client.AlreadyClosedException; import com.rabbitmq.client.Channel; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.TypeTags; +import io.ballerina.runtime.api.types.TypeTags; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BObject;