diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index ee995f0d..97e9efe9 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 0f74d325..643b6ac5 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/central-publish.yml b/.github/workflows/central-publish.yml index 11922b55..ebe213e7 100644 --- a/.github/workflows/central-publish.yml +++ b/.github/workflows/central-publish.yml @@ -15,7 +15,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/process-load-test-result.yml b/.github/workflows/process-load-test-result.yml index 19ca1689..7fb10615 100644 --- a/.github/workflows/process-load-test-result.yml +++ b/.github/workflows/process-load-test-result.yml @@ -7,7 +7,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 43b27aa1..8ac69f78 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: websubhub diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 31e0976d..db98c8e1 100644 --- a/.github/workflows/pull-request.yml +++ b/.github/workflows/pull-request.yml @@ -10,5 +10,5 @@ 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 secrets: inherit diff --git a/.github/workflows/trigger-load-tests.yml b/.github/workflows/trigger-load-tests.yml index 247c2a78..6c74c2dd 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-ballerina-websubhub' runtime_artifacts_url: 'https://api.github.com/repos/ballerina-platform/module-ballerina-websubhub/actions/artifacts' diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index 458aab57..d91a5f37 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 a3f2fa32..2637122c 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ This repository only contains the source code for the package. ### Set up the prerequisites -1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations). +1. Download and install Java SE Development Kit (JDK) version 21 (from one of the following locations). * [Oracle](https://www.oracle.com/java/technologies/downloads/) * [OpenJDK](https://adoptium.net/) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 4ba44123..7ad624a8 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,19 +1,19 @@ [package] org = "ballerina" name = "websubhub" -version = "1.12.0" +version = "1.12.1" authors = ["Ballerina"] keywords = ["websub", "hub", "publisher", "service", "listener", "client"] repository = "https://github.com/ballerina-platform/module-ballerina-websubhub" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.9.0" +distribution = "2201.10.0-20241019-091600-89e54c08" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "websubhub-native" -version = "1.12.0" -path = "../native/build/libs/websubhub-native-1.12.0.jar" +version = "1.12.1" +path = "../native/build/libs/websubhub-native-1.12.1-SNAPSHOT.jar" diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index e8a00e39..4791a4b4 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "websubhub-compiler-plugin" class = "io.ballerina.stdlib.websubhub.WebSubHubCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/websubhub-compiler-plugin-1.12.0.jar" +path = "../compiler-plugin/build/libs/websubhub-compiler-plugin-1.12.1-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index 0bf584bc..4726c4ae 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.10.0-20241019-091600-89e54c08" [[package]] org = "ballerina" name = "auth" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, @@ -22,18 +22,17 @@ dependencies = [ [[package]] org = "ballerina" name = "cache" -version = "3.8.0" +version = "3.8.1" dependencies = [ {org = "ballerina", name = "constraint"}, {org = "ballerina", name = "jballerina.java"}, - {org = "ballerina", name = "task"}, - {org = "ballerina", name = "time"} + {org = "ballerina", name = "task"} ] [[package]] org = "ballerina" name = "constraint" -version = "1.5.0" +version = "1.5.1" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -41,7 +40,7 @@ dependencies = [ [[package]] org = "ballerina" name = "crypto" -version = "2.7.2" +version = "2.7.3" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "time"} @@ -53,7 +52,7 @@ modules = [ [[package]] org = "ballerina" name = "file" -version = "1.10.0" +version = "1.10.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -64,7 +63,7 @@ dependencies = [ [[package]] org = "ballerina" name = "http" -version = "2.12.0" +version = "2.13.0" dependencies = [ {org = "ballerina", name = "auth"}, {org = "ballerina", name = "cache"}, @@ -96,7 +95,7 @@ modules = [ [[package]] org = "ballerina" name = "io" -version = "1.6.1" +version = "1.6.2" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.value"} @@ -116,7 +115,7 @@ modules = [ [[package]] org = "ballerina" name = "jwt" -version = "2.13.0" +version = "2.13.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, @@ -124,8 +123,7 @@ dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "lang.int"}, {org = "ballerina", name = "lang.string"}, - {org = "ballerina", name = "log"}, - {org = "ballerina", name = "time"} + {org = "ballerina", name = "log"} ] modules = [ {org = "ballerina", packageName = "jwt", moduleName = "jwt"} @@ -223,7 +221,7 @@ dependencies = [ [[package]] org = "ballerina" name = "log" -version = "2.10.0" +version = "2.10.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -237,7 +235,7 @@ modules = [ [[package]] org = "ballerina" name = "mime" -version = "2.10.0" +version = "2.10.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, @@ -251,20 +249,19 @@ modules = [ [[package]] org = "ballerina" name = "oauth2" -version = "2.12.0" +version = "2.12.1" dependencies = [ {org = "ballerina", name = "cache"}, {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "log"}, - {org = "ballerina", name = "time"}, {org = "ballerina", name = "url"} ] [[package]] org = "ballerina" name = "observe" -version = "1.3.0" +version = "1.3.1" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -272,7 +269,7 @@ dependencies = [ [[package]] org = "ballerina" name = "os" -version = "1.8.0" +version = "1.8.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"} @@ -281,7 +278,7 @@ dependencies = [ [[package]] org = "ballerina" name = "task" -version = "2.5.0" +version = "2.5.1" dependencies = [ {org = "ballerina", name = "jballerina.java"}, {org = "ballerina", name = "time"} @@ -304,7 +301,7 @@ modules = [ [[package]] org = "ballerina" name = "time" -version = "2.4.0" +version = "2.5.1" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -312,7 +309,7 @@ dependencies = [ [[package]] org = "ballerina" name = "url" -version = "2.4.0" +version = "2.4.1" dependencies = [ {org = "ballerina", name = "jballerina.java"} ] @@ -323,7 +320,7 @@ modules = [ [[package]] org = "ballerina" name = "uuid" -version = "1.8.0" +version = "1.8.1" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "jballerina.java"}, @@ -337,7 +334,7 @@ modules = [ [[package]] org = "ballerina" name = "websubhub" -version = "1.12.0" +version = "1.12.1" dependencies = [ {org = "ballerina", name = "crypto"}, {org = "ballerina", name = "http"}, diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index 12c08494..a1a85401 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -7,12 +7,12 @@ keywords = ["websub", "hub", "publisher", "service", "listener", "client"] repository = "https://github.com/ballerina-platform/module-ballerina-websubhub" icon = "icon.png" license = ["Apache-2.0"] -distribution = "2201.9.0" +distribution = "2201.10.0-20241019-091600-89e54c08" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "websubhub-native" version = "@toml.version@" diff --git a/build.gradle b/build.gradle index 4f67c968..5f8d5caf 100644 --- a/build.gradle +++ b/build.gradle @@ -16,10 +16,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}" } ext.ballerinaLangVersion = project.ballerinaLangVersion diff --git a/compiler-plugin-tests/build.gradle b/compiler-plugin-tests/build.gradle index a011c759..8159ecd7 100644 --- a/compiler-plugin-tests/build.gradle +++ b/compiler-plugin-tests/build.gradle @@ -48,8 +48,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 adbe3f12..f5a671b0 100644 --- a/compiler-plugin/build.gradle +++ b/compiler-plugin/build.gradle @@ -40,8 +40,11 @@ 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/compiler-plugin/src/main/java/io/ballerina/stdlib/websubhub/task/validator/ServiceDeclarationValidator.java b/compiler-plugin/src/main/java/io/ballerina/stdlib/websubhub/task/validator/ServiceDeclarationValidator.java index 0b2e7efe..5d98533b 100644 --- a/compiler-plugin/src/main/java/io/ballerina/stdlib/websubhub/task/validator/ServiceDeclarationValidator.java +++ b/compiler-plugin/src/main/java/io/ballerina/stdlib/websubhub/task/validator/ServiceDeclarationValidator.java @@ -41,6 +41,10 @@ public class ServiceDeclarationValidator { private static final Map> allowedReturnTypes; private static final List methodsWithOptionalReturnTypes; + private ServiceDeclarationValidator() { + //private constructor + } + static { allowedMethods = List.of( Constants.ON_REGISTER_TOPIC, Constants.ON_DEREGISTER_TOPIC, Constants.ON_UPDATE_MESSAGE, diff --git a/gradle.properties b/gradle.properties index 6cd49363..a0665cb3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,41 +1,46 @@ org.gradle.caching=true group=io.ballerina.stdlib version=1.12.1-SNAPSHOT -ballerinaLangVersion=2201.10.0 +ballerinaLangVersion=2201.10.0-20241019-091600-89e54c08 puppycrawlCheckstyleVersion=10.12.0 testngVersion=7.6.1 ballerinaGradlePluginVersion=2.0.1 gsonVersion=2.8.8 +spotbugsPluginVersion=6.0.18 +shadowJarPluginVersion=8.1.1 +downloadPluginVersion=5.4.0 +releasePluginVersion=2.8.0 + # Direct Dependencies -stdlibIoVersion=1.6.1 -stdlibRandomVersion=1.5.0 -stdlibTimeVersion=2.4.0 -stdlibUrlVersion=2.4.0 -stdlibCryptoVersion=2.7.2 -stdlibLogVersion=2.10.0 -stdlibMimeVersion=2.10.0 -stdlibUuidVersion=1.8.0 -stdlibHttpVersion=2.12.0 +stdlibIoVersion=1.6.2-20240928-084100-656404f +stdlibRandomVersion=1.5.1-20240930-193000-e5c6c0e +stdlibTimeVersion=2.5.1-20240930-120200-e59222b +stdlibUrlVersion=2.4.1-20240930-120200-b7fb9e1 +stdlibCryptoVersion=2.7.3-20240930-132000-5ecc9ab +stdlibLogVersion=2.10.1-20240930-154200-5ab2aa4 +stdlibMimeVersion=2.10.1-20241009-141200-8b6c9f0 +stdlibUuidVersion=1.8.1-20241009-134600-a05012b +stdlibHttpVersion=2.13.0-20241022-163700-67b6515 # Transitive Dependencies # Level 01 -stdlibConstraintVersion=1.5.0 +stdlibConstraintVersion=1.5.1-20240930-123400-5ecd396 # Level 02 -stdlibOsVersion=1.8.0 -stdlibTaskVersion=2.5.0 +stdlibOsVersion=1.8.1-20241001-120600-dd1626e +stdlibTaskVersion=2.5.1-20241002-145700-5bdb843 # Level 03 -stdlibCacheVersion=3.8.0 -stdlibFileVersion=1.10.0 +stdlibCacheVersion=3.8.1-20241007-154900-63f4403 +stdlibFileVersion=1.10.1-20241007-160900-03f7b64 # Level 04 -stdlibAuthVersion=2.12.0 -stdlibJwtVersion=2.13.0 -stdlibOAuth2Version=2.12.0 +stdlibAuthVersion=2.12.1-20241010-130800-733dbef +stdlibJwtVersion=2.13.1-20241010-123600-5ea6a94 +stdlibOAuth2Version=2.12.1-20241010-123600-0e0cfcc # Ballerinax Observe -observeVersion=1.3.0 -observeInternalVersion=1.3.0 +observeVersion=1.3.1-20241007-161000-645452d +observeInternalVersion=1.3.1-20241015-172900-cdc3cb3 diff --git a/native/build.gradle b/native/build.gradle index 6f5eb8b6..caad4a16 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -42,8 +42,11 @@ 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/websubhub/HubCallback.java b/native/src/main/java/io/ballerina/stdlib/websubhub/HubCallback.java deleted file mode 100644 index 7debf2f7..00000000 --- a/native/src/main/java/io/ballerina/stdlib/websubhub/HubCallback.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2021, 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.websubhub; - -import io.ballerina.runtime.api.Future; -import io.ballerina.runtime.api.Module; -import io.ballerina.runtime.api.async.Callback; -import io.ballerina.runtime.api.types.Type; -import io.ballerina.runtime.api.values.BError; - -/** - * {@code HubCallback} used to handle the websubhub remote method invocation results. - */ -public class HubCallback implements Callback { - private final Future future; - private final Module module; - - public HubCallback(Future future, Module module) { - this.future = future; - this.module = module; - } - - @Override - public void notifySuccess(Object result) { - if (result instanceof BError) { - BError error = (BError) result; - if (!isModuleDefinedError(error)) { - error.printStackTrace(); - } - } - - future.complete(result); - } - - @Override - public void notifyFailure(BError bError) { - bError.printStackTrace(); - // 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); - } - - private boolean isModuleDefinedError(BError error) { - Type errorType = error.getType(); - Module packageDetails = errorType.getPackage(); - String orgName = packageDetails.getOrg(); - String packageName = packageDetails.getName(); - return Constants.PACKAGE_ORG.equals(orgName) && Constants.PACKAGE_NAME.equals(packageName); - } -} diff --git a/native/src/main/java/io/ballerina/stdlib/websubhub/ModuleUtils.java b/native/src/main/java/io/ballerina/stdlib/websubhub/ModuleUtils.java index 4e95f1ed..59c46e32 100644 --- a/native/src/main/java/io/ballerina/stdlib/websubhub/ModuleUtils.java +++ b/native/src/main/java/io/ballerina/stdlib/websubhub/ModuleUtils.java @@ -20,6 +20,11 @@ import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.Module; +import io.ballerina.runtime.api.creators.ErrorCreator; +import io.ballerina.runtime.api.types.Type; +import io.ballerina.runtime.api.values.BError; + +import java.util.concurrent.CompletableFuture; /** * {@code ModuleUtils} contains the utility methods for the module. @@ -37,4 +42,38 @@ public static void setModule(Environment environment) { public static Module getModule() { return module; } -} + + public static void notifySuccess(CompletableFuture future, Object result) { + if (result instanceof BError) { + BError error = (BError) result; + if (!isModuleDefinedError(error)) { + error.printStackTrace(); + } + } + future.complete(result); + } + + public static void notifyFailure(BError bError) { + bError.printStackTrace(); + // 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); + } + + private static boolean isModuleDefinedError(BError error) { + Type errorType = error.getType(); + Module packageDetails = errorType.getPackage(); + String orgName = packageDetails.getOrg(); + String packageName = packageDetails.getName(); + return Constants.PACKAGE_ORG.equals(orgName) && Constants.PACKAGE_NAME.equals(packageName); + } + + public static Object getResult(CompletableFuture balFuture) { + try { + return balFuture.get(); + } catch (Throwable throwable) { + throw ErrorCreator.createError(throwable); + } + } +} \ No newline at end of file diff --git a/native/src/main/java/io/ballerina/stdlib/websubhub/NativeHttpToWebsubhubAdaptor.java b/native/src/main/java/io/ballerina/stdlib/websubhub/NativeHttpToWebsubhubAdaptor.java index d61825ed..c14ded63 100644 --- a/native/src/main/java/io/ballerina/stdlib/websubhub/NativeHttpToWebsubhubAdaptor.java +++ b/native/src/main/java/io/ballerina/stdlib/websubhub/NativeHttpToWebsubhubAdaptor.java @@ -19,9 +19,7 @@ package io.ballerina.stdlib.websubhub; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.Module; -import io.ballerina.runtime.api.PredefinedTypes; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.async.StrandMetadata; import io.ballerina.runtime.api.creators.ValueCreator; @@ -33,12 +31,14 @@ import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.utils.TypeUtils; import io.ballerina.runtime.api.values.BArray; +import io.ballerina.runtime.api.values.BError; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BString; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.CompletableFuture; import static io.ballerina.stdlib.websubhub.Constants.ON_DEREGISTER_TOPIC; import static io.ballerina.stdlib.websubhub.Constants.ON_REGISTER_TOPIC; @@ -78,7 +78,7 @@ public static Object callRegisterMethod(Environment env, BObject adaptor, if (isReadOnly) { message.freezeDirect(); } - Object[] args = new Object[]{message, true, bHttpHeaders, true}; + Object[] args = new Object[]{message, bHttpHeaders}; return invokeRemoteFunction(env, bHubService, args, "callRegisterMethod", ON_REGISTER_TOPIC); } @@ -90,7 +90,7 @@ public static Object callDeregisterMethod(Environment env, BObject adaptor, if (isReadOnly) { message.freezeDirect(); } - Object[] args = new Object[]{message, true, bHttpHeaders, true}; + Object[] args = new Object[]{message, bHttpHeaders}; return invokeRemoteFunction(env, bHubService, args, "callDeregisterMethod", ON_DEREGISTER_TOPIC); } @@ -102,7 +102,7 @@ public static Object callOnUpdateMethod(Environment env, BObject adaptor, if (isReadOnly) { message.freezeDirect(); } - Object[] args = new Object[]{message, true, bHttpHeaders, true}; + Object[] args = new Object[]{message, bHttpHeaders}; return invokeRemoteFunction(env, bHubService, args, "callOnUpdateMethod", ON_UPDATE_MESSAGE); } @@ -114,7 +114,7 @@ public static Object callOnSubscriptionMethod(Environment env, BObject adaptor, if (isReadOnly) { message.freezeDirect(); } - Object[] args = new Object[]{message, true, bHttpHeaders, true}; + Object[] args = new Object[]{message, bHttpHeaders}; return invokeRemoteFunction(env, bHubService, args, "callOnSubscriptionMethod", ON_SUBSCRIPTION); } @@ -126,7 +126,7 @@ public static Object callOnSubscriptionValidationMethod(Environment env, BObject if (isReadOnly) { message.freezeDirect(); } - Object[] args = new Object[]{message, true, bHttpHeaders, true}; + Object[] args = new Object[]{message, bHttpHeaders}; return invokeRemoteFunction(env, bHubService, args, "callOnSubscriptionValidationMethod", ON_SUBSCRIPTION_VALIDATION); } @@ -138,7 +138,7 @@ public static Object callOnSubscriptionIntentVerifiedMethod(Environment env, BOb if (isReadOnly) { message.freezeDirect(); } - Object[] args = new Object[]{message, true, bHttpHeaders, true}; + Object[] args = new Object[]{message, bHttpHeaders}; return invokeRemoteFunction(env, bHubService, args, "callOnSubscriptionIntentVerifiedMethod", ON_SUBSCRIPTION_INTENT_VERIFIED); @@ -151,7 +151,7 @@ public static Object callOnUnsubscriptionMethod(Environment env, BObject adaptor if (isReadOnly) { message.freezeDirect(); } - Object[] args = new Object[]{message, true, bHttpHeaders, true}; + Object[] args = new Object[]{message, bHttpHeaders}; return invokeRemoteFunction(env, bHubService, args, "callOnUnsubscriptionMethod", ON_UNSUBSCRIPTION); } @@ -163,7 +163,7 @@ public static Object callOnUnsubscriptionValidationMethod(Environment env, BObje if (isReadOnly) { message.freezeDirect(); } - Object[] args = new Object[]{message, true, bHttpHeaders, true}; + Object[] args = new Object[]{message, bHttpHeaders}; return invokeRemoteFunction(env, bHubService, args, "callOnUnsubscriptionValidationMethod", ON_UNSUBSCRIPTION_VALIDATION); } @@ -175,7 +175,7 @@ public static Object callOnUnsubscriptionIntentVerifiedMethod(Environment env, B if (isReadOnly) { message.freezeDirect(); } - Object[] args = new Object[]{message, true, bHttpHeaders, true}; + Object[] args = new Object[]{message, bHttpHeaders}; return invokeRemoteFunction(env, bHubService, args, "callOnUnsubscriptionIntentVerifiedMethod", ON_UNSUBSCRIPTION_INTENT_VERIFIED); } @@ -200,20 +200,27 @@ private static boolean isReadOnlyParam(BObject serviceObj, String remoteMethod) private static Object invokeRemoteFunction(Environment env, BObject bHubService, Object[] args, String parentFunctionName, String remoteFunctionName) { - Future balFuture = env.markAsync(); - Module module = ModuleUtils.getModule(); - StrandMetadata metadata = new StrandMetadata(module.getOrg(), module.getName(), module.getVersion(), - parentFunctionName); - ObjectType serviceType = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(bHubService)); - if (serviceType.isIsolated() && serviceType.isIsolated(remoteFunctionName)) { - env.getRuntime().invokeMethodAsyncConcurrently( - bHubService, remoteFunctionName, null, metadata, - new HubCallback(balFuture, module), null, PredefinedTypes.TYPE_NULL, args); - } else { - env.getRuntime().invokeMethodAsyncSequentially( - bHubService, remoteFunctionName, null, metadata, - new HubCallback(balFuture, module), null, PredefinedTypes.TYPE_NULL, args);; - } - return null; + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + Module module = ModuleUtils.getModule(); + StrandMetadata metadata = new StrandMetadata(module.getOrg(), module.getName(), module.getVersion(), + parentFunctionName); + ObjectType serviceType = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(bHubService)); + Object result; + try { + if (serviceType.isIsolated() && serviceType.isIsolated(remoteFunctionName)) { + result = env.getRuntime().startIsolatedWorker(bHubService, remoteFunctionName, null, metadata, + null, args).get(); + } else { + result = env.getRuntime().startNonIsolatedWorker(bHubService, remoteFunctionName, null, + metadata, null, args).get(); + } + ModuleUtils.notifySuccess(balFuture, result); + return ModuleUtils.getResult(balFuture); + } catch (BError bError) { + ModuleUtils.notifyFailure(bError); + } + return null; + }); } }