From a7c88d5b8dff29c70f2ae9922d16af4255d3c5ad Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Mon, 7 Oct 2024 18:30:24 +0530 Subject: [PATCH 01/10] Migrate to Java 21 --- .../workflows/build-timestamped-master.yml | 2 +- .../workflows/build-with-bal-test-graalvm.yml | 2 +- .github/workflows/central-publish.yml | 2 +- .../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 | 16 +-- build-config/resources/Ballerina.toml | 16 +-- build-config/spotbugs-exclude.xml | 9 +- compiler-plugin-tests/build.gradle | 7 +- compiler-plugin/build.gradle | 7 +- gradle.properties | 12 +-- native/build.gradle | 7 +- .../io/ballerina/stdlib/udp/Dispatcher.java | 100 +++++++++++++----- .../io/ballerina/stdlib/udp/UdpCallback.java | 85 --------------- .../io/ballerina/stdlib/udp/UdpClient.java | 39 +++---- .../stdlib/udp/UdpClientHandler.java | 21 ++-- .../stdlib/udp/UdpConnectClientHandler.java | 4 +- .../io/ballerina/stdlib/udp/UdpFactory.java | 20 ++-- .../io/ballerina/stdlib/udp/UdpListener.java | 32 +++--- .../java/io/ballerina/stdlib/udp/Utils.java | 9 ++ .../stdlib/udp/nativeclient/Client.java | 90 ++++++++-------- .../udp/nativeclient/ConnectClient.java | 92 ++++++++-------- .../stdlib/udp/nativelistener/Caller.java | 50 +++++---- .../stdlib/udp/nativelistener/Listener.java | 91 ++++++++-------- .../stdlib/udp/testutils/MockServerUtils.java | 6 +- 29 files changed, 350 insertions(+), 381 deletions(-) delete mode 100644 native/src/main/java/io/ballerina/stdlib/udp/UdpCallback.java diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index 503d403e..e6d67f1c 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 184140b1..3bf96bb6 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 0cd0b0f0..fb245715 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 f719f09b..c7fff35f 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: udp diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index ecfa72ce..660df057 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 4393faf1..5c56a78c 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-udp' runtime_artifacts_url: 'https://api.github.com/repos/ballerina-platform/module-ballerina-udp/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 24d5ec04..63e1fd10 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ This repository only contains the source code for the package. ### Setting 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/) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index e3426a9c..81df49ef 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -9,44 +9,44 @@ icon = "icon.png" license = ["Apache-2.0"] distribution = "2201.10.0" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "udp-native" version = "1.11.0" path = "../native/build/libs/udp-native-1.11.0.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] path = "../test-utils/build/libs/udp-test-utils-1.11.0.jar" scope = "testOnly" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.netty" artifactId = "netty-handler" version = "4.1.108.Final" path = "./lib/netty-handler-4.1.108.Final.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.netty" artifactId = "netty-buffer" version = "4.1.108.Final" path = "./lib/netty-buffer-4.1.108.Final.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.netty" artifactId = "netty-transport" version = "4.1.108.Final" path = "./lib/netty-transport-4.1.108.Final.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.netty" artifactId = "netty-common" version = "4.1.108.Final" path = "./lib/netty-common-4.1.108.Final.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.netty" artifactId = "netty-resolver" version = "4.1.108.Final" diff --git a/build-config/resources/Ballerina.toml b/build-config/resources/Ballerina.toml index b2bcadcb..13e7bb98 100644 --- a/build-config/resources/Ballerina.toml +++ b/build-config/resources/Ballerina.toml @@ -9,44 +9,44 @@ icon = "icon.png" license = ["Apache-2.0"] distribution = "2201.10.0" -[platform.java17] +[platform.java21] graalvmCompatible = true -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "udp-native" version = "@toml.version@" path = "../native/build/libs/udp-native-@project.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] path = "../test-utils/build/libs/udp-test-utils-@project.version@.jar" scope = "testOnly" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.netty" artifactId = "netty-handler" version = "@netty.version@" path = "./lib/netty-handler-@netty.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.netty" artifactId = "netty-buffer" version = "@netty.version@" path = "./lib/netty-buffer-@netty.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.netty" artifactId = "netty-transport" version = "@netty.version@" path = "./lib/netty-transport-@netty.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.netty" artifactId = "netty-common" version = "@netty.version@" path = "./lib/netty-common-@netty.version@.jar" -[[platform.java17.dependency]] +[[platform.java21.dependency]] groupId = "io.netty" artifactId = "netty-resolver" version = "@netty.version@" diff --git a/build-config/spotbugs-exclude.xml b/build-config/spotbugs-exclude.xml index 1603f89a..06f8da75 100644 --- a/build-config/spotbugs-exclude.xml +++ b/build-config/spotbugs-exclude.xml @@ -24,13 +24,12 @@ - - - - - + + + + diff --git a/compiler-plugin-tests/build.gradle b/compiler-plugin-tests/build.gradle index 4c687424..e52c92a1 100644 --- a/compiler-plugin-tests/build.gradle +++ b/compiler-plugin-tests/build.gradle @@ -52,8 +52,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 d85207b5..bcd2a22d 100644 --- a/compiler-plugin/build.gradle +++ b/compiler-plugin/build.gradle @@ -48,8 +48,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/gradle.properties b/gradle.properties index 000c1164..8f2e72a8 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,12 +1,12 @@ org.gradle.caching=true group=io.ballerina.stdlib version=1.11.1-SNAPSHOT -ballerinaLangVersion=2201.10.0 +ballerinaLangVersion=2201.10.0-20241011-161100-51978649 puppycrawlCheckstyleVersion=10.12.0 githubJohnrengelmanShadowVersion=8.1.1 checkstyleToolVersion=7.8.2 -githubSpotbugsVersion=5.0.14 +githubSpotbugsVersion=6.0.18 testngVersion=7.6.1 nettyVersion=4.1.108.Final underCouchDownloadVersion=5.4.0 @@ -16,7 +16,7 @@ ballerinaGradlePluginVersion=2.0.1 gsonVersion=2.8.8 # Dependencies -stdlibIoVersion=1.6.0 -stdlibLogVersion=2.10.0 -observeVersion=1.3.0 -observeInternalVersion=1.3.0 +stdlibIoVersion=1.6.2-20240928-084100-656404f +stdlibLogVersion=2.10.1-20240930-154200-5ab2aa4 +observeVersion=1.3.1-20241007-161000-645452d +observeInternalVersion=1.3.1-20241007-182700-a5f77a1 diff --git a/native/build.gradle b/native/build.gradle index c2235fee..c7cb303e 100644 --- a/native/build.gradle +++ b/native/build.gradle @@ -61,8 +61,11 @@ compileJava { } 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/udp/Dispatcher.java b/native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java index d1efe5ae..efc77576 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java @@ -21,19 +21,26 @@ import io.ballerina.runtime.api.Runtime; import io.ballerina.runtime.api.TypeTags; import io.ballerina.runtime.api.async.StrandMetadata; +import io.ballerina.runtime.api.creators.ErrorCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.types.MethodType; import io.ballerina.runtime.api.types.ObjectType; +import io.ballerina.runtime.api.types.Parameter; import io.ballerina.runtime.api.types.Type; 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 io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.socket.DatagramPacket; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.net.InetSocketAddress; import java.util.Arrays; /** @@ -49,8 +56,7 @@ private static void invokeOnBytes(UdpService udpService, DatagramPacket datagram Type[] parameterTypes) { try { Object[] params = getOnBytesSignature(datagramPacket, channel, parameterTypes); - invokeAsyncCall(udpService.getService(), Constants.ON_BYTES, udpService.getRuntime(), - new UdpCallback(udpService, channel, datagramPacket), params); + invokeAsyncCall(udpService, datagramPacket, channel, Constants.ON_BYTES, params); } catch (BError e) { Dispatcher.invokeOnError(udpService, e.getMessage()); } @@ -60,8 +66,7 @@ private static void invokeOnDatagram(UdpService udpService, DatagramPacket datag Type[] parameterTypes) { try { Object[] params = getOnDatagramSignature(datagramPacket, channel, parameterTypes); - invokeAsyncCall(udpService.getService(), Constants.ON_DATAGRAM, udpService.getRuntime(), - new UdpCallback(udpService, channel, datagramPacket), params); + invokeAsyncCall(udpService, datagramPacket, channel, Constants.ON_DATAGRAM, params); } catch (BError e) { Dispatcher.invokeOnError(udpService, e.getMessage()); } @@ -75,44 +80,51 @@ public static void invokeOnError(UdpService udpService, String message) { filter(m -> m.getName().equals(Constants.ON_ERROR)).findFirst().orElse(null); if (methodType != null) { Object[] params = getOnErrorSignature(message); - invokeAsyncCall(udpService.getService(), Constants.ON_ERROR, udpService.getRuntime(), - new UdpCallback(udpService), params); + invokeAsyncCall(udpService, null, null, Constants.ON_ERROR, params); } } catch (Throwable t) { log.error("Error while executing onError function", t); } } - private static void invokeAsyncCall(BObject service, String methodName, Runtime runtime, UdpCallback callback, - Object[] params) { - StrandMetadata metadata = new StrandMetadata(Utils.getModule().getOrg(), Utils.getModule().getName(), - Utils.getModule().getVersion(), methodName); - ObjectType objectType = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(service)); - if (objectType.isIsolated() && objectType.isIsolated(methodName)) { - runtime.invokeMethodAsyncConcurrently(service, methodName, - null, metadata, callback, null, null, params); - } else { - runtime.invokeMethodAsyncSequentially(service, methodName, - null, metadata, callback, null, null, params); - } + private static void invokeAsyncCall(UdpService udpService, DatagramPacket datagramPacket, Channel channel, + String methodName, Object[] params) { + Thread.startVirtualThread(() -> { + BObject service = udpService.getService(); + Runtime runtime = udpService.getRuntime(); + StrandMetadata metadata = new StrandMetadata(Utils.getModule().getOrg(), Utils.getModule().getName(), + Utils.getModule().getVersion(), methodName); + ObjectType objectType = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(service)); + Object result; + try { + if (objectType.isIsolated() && objectType.isIsolated(methodName)) { + result = runtime.startIsolatedWorker(service, methodName, null, metadata, null, params).get(); + } else { + result = runtime.startNonIsolatedWorker(service, methodName, null, metadata, null, params).get(); + } + handleResult(udpService, datagramPacket, channel, result); + } catch (BError error) { + handleError(error); + } catch (Throwable throwable) { + handleError(ErrorCreator.createError(throwable)); + } + }); } private static Object[] getOnBytesSignature(DatagramPacket datagramPacket, Channel channel, Type[] parameterTypes) { byte[] byteContent = new byte[datagramPacket.content().readableBytes()]; datagramPacket.content().readBytes(byteContent); - Object[] bValues = new Object[parameterTypes.length * 2]; + Object[] bValues = new Object[parameterTypes.length]; int index = 0; for (Type param : parameterTypes) { int paramTag = param.getTag(); switch (paramTag) { case TypeTags.INTERSECTION_TAG: bValues[index++] = ValueCreator.createReadonlyArrayValue(byteContent); - bValues[index++] = true; break; case TypeTags.OBJECT_TYPE_TAG: bValues[index++] = createClient(datagramPacket, channel); - bValues[index++] = true; break; default: break; @@ -123,18 +135,16 @@ private static Object[] getOnBytesSignature(DatagramPacket datagramPacket, Chann private static Object[] getOnDatagramSignature(DatagramPacket datagramPacket, Channel channel, Type[] parameterTypes) { - Object[] bValues = new Object[parameterTypes.length * 2]; + Object[] bValues = new Object[parameterTypes.length]; int index = 0; for (Type param : parameterTypes) { int paramTag = param.getTag(); switch (paramTag) { case TypeTags.INTERSECTION_TAG: bValues[index++] = Utils.createReadOnlyDatagramWithSenderAddress(datagramPacket); - bValues[index++] = true; break; case TypeTags.OBJECT_TYPE_TAG: bValues[index++] = createClient(datagramPacket, channel); - bValues[index++] = true; break; default: break; @@ -144,7 +154,7 @@ private static Object[] getOnDatagramSignature(DatagramPacket datagramPacket, Ch } private static Object[] getOnErrorSignature(String message) { - return new Object[]{Utils.createUdpError(message), true}; + return new Object[]{Utils.createUdpError(message)}; } private static BObject createClient(DatagramPacket datagramPacket, Channel channel) { @@ -159,19 +169,55 @@ private static BObject createClient(DatagramPacket datagramPacket, Channel chann public static void invokeRead(UdpService udpService, DatagramPacket datagramPacket, Channel channel) { ObjectType objectType = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(udpService.getService())); + for (MethodType method : objectType.getMethods()) { switch (method.getName()) { case Constants.ON_BYTES: Dispatcher.invokeOnBytes(udpService, datagramPacket, channel, - method.getType().getParameterTypes()); + getParameterTypes(method.getType().getParameters())); break; case Constants.ON_DATAGRAM: Dispatcher.invokeOnDatagram(udpService, datagramPacket, channel, - method.getType().getParameterTypes()); + getParameterTypes(method.getType().getParameters())); break; default: break; } } } + + private static Type[] getParameterTypes(Parameter[] parameters) { + Type[] parameterTypes = new Type[parameters.length]; + for (int i = 0; i < parameters.length; i++) { + parameterTypes[i] = parameters[i].type; + } + return parameterTypes; + } + + private static void handleResult(UdpService udpService, DatagramPacket datagramP, Channel channel, Object object) { + if (object instanceof BArray) { + // call writeBytes if the service returns byte[] + byte[] byteContent = ((BArray) object).getBytes(); + UdpListener.send(udpService, new DatagramPacket(Unpooled.wrappedBuffer(byteContent), + datagramP.sender()), channel); + } else if (object instanceof BMap) { + // call sendDatagram if the service returns Datagram + BMap datagram = (BMap) object; + String host = datagram.getStringValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_HOST)).getValue(); + int port = datagram.getIntValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_PORT)).intValue(); + BArray data = datagram.getArrayValue(StringUtils.fromString(Constants.DATAGRAM_DATA)); + byte[] byteContent = data.getBytes(); + DatagramPacket datagramPacket = new DatagramPacket(Unpooled.wrappedBuffer(byteContent), + new InetSocketAddress(host, port)); + UdpListener.send(udpService, datagramPacket, channel); + } else if (object instanceof BError) { + ((BError) object).printStackTrace(); + } + log.debug("Method successfully dispatched."); + } + + + public static void handleError(BError bError) { + bError.printStackTrace(); + } } diff --git a/native/src/main/java/io/ballerina/stdlib/udp/UdpCallback.java b/native/src/main/java/io/ballerina/stdlib/udp/UdpCallback.java deleted file mode 100644 index dc4c0601..00000000 --- a/native/src/main/java/io/ballerina/stdlib/udp/UdpCallback.java +++ /dev/null @@ -1,85 +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.udp; - -import io.ballerina.runtime.api.async.Callback; -import io.ballerina.runtime.api.utils.StringUtils; -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.BString; -import io.netty.buffer.Unpooled; -import io.netty.channel.Channel; -import io.netty.channel.socket.DatagramPacket; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.net.InetSocketAddress; - -/** - * callback implementation. - */ -public class UdpCallback implements Callback { - - private static final Logger log = LoggerFactory.getLogger(UdpCallback.class); - - private UdpService udpService; - private Channel channel; - private DatagramPacket datagram; - - public UdpCallback(UdpService udpService, Channel channel, DatagramPacket datagram) { - this.udpService = udpService; - this.channel = channel; - this.datagram = datagram; - } - - public UdpCallback(UdpService udpService) { - this.udpService = udpService; - } - - public UdpCallback() {} - - @Override - public void notifySuccess(Object object) { - if (object instanceof BArray) { - // call writeBytes if the service returns byte[] - byte[] byteContent = ((BArray) object).getBytes(); - UdpListener.send(udpService, new DatagramPacket(Unpooled.wrappedBuffer(byteContent), - datagram.sender()), channel); - } else if (object instanceof BMap) { - // call sendDatagram if the service returns Datagram - BMap datagram = (BMap) object; - String host = datagram.getStringValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_HOST)).getValue(); - int port = datagram.getIntValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_PORT)).intValue(); - BArray data = datagram.getArrayValue(StringUtils.fromString(Constants.DATAGRAM_DATA)); - byte[] byteContent = data.getBytes(); - DatagramPacket datagramPacket = new DatagramPacket(Unpooled.wrappedBuffer(byteContent), - new InetSocketAddress(host, port)); - UdpListener.send(udpService, datagramPacket, channel); - } else if (object instanceof BError) { - ((BError) object).printStackTrace(); - } - log.debug("Method successfully dispatched."); - } - - @Override - public void notifyFailure(BError bError) { - bError.printStackTrace(); - } -} diff --git a/native/src/main/java/io/ballerina/stdlib/udp/UdpClient.java b/native/src/main/java/io/ballerina/stdlib/udp/UdpClient.java index fff47def..774039cd 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/UdpClient.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/UdpClient.java @@ -18,7 +18,6 @@ package io.ballerina.stdlib.udp; -import io.ballerina.runtime.api.Future; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; @@ -33,6 +32,7 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.LinkedList; +import java.util.concurrent.CompletableFuture; import java.util.concurrent.TimeUnit; /** @@ -45,7 +45,7 @@ public class UdpClient { // create connection oriented client public UdpClient(InetSocketAddress localAddress, InetSocketAddress remoteAddress, - EventLoopGroup group, Future callback) { + EventLoopGroup group, CompletableFuture balFuture) { clientBootstrap = new Bootstrap(); clientBootstrap.group(group) .channel(NioDatagramChannel.class) @@ -56,13 +56,13 @@ protected void initChannel(Channel ch) throws Exception { } }); if (remoteAddress != null) { - this.connect(remoteAddress, localAddress, callback); + this.connect(remoteAddress, localAddress, balFuture); } } // create connection less client public UdpClient(InetSocketAddress localAddress, EventLoopGroup group, - Future callback) { + CompletableFuture balFuture) { clientBootstrap = new Bootstrap(); clientBootstrap.group(group) .channel(NioDatagramChannel.class) @@ -75,16 +75,16 @@ protected void initChannel(Channel ch) throws Exception { if (future.isSuccess()) { channel = future.channel(); channel.config().setAutoRead(false); - callback.complete(null); + balFuture.complete(null); } else { - callback.complete(Utils.createUdpError("Error initializing UDP Client")); + balFuture.complete(Utils.createUdpError("Error initializing UDP Client")); } }); } // needed for connection oriented client private void connect(SocketAddress remoteAddress, SocketAddress localAddress, - Future callback) { + CompletableFuture balFuture) { clientBootstrap.connect(remoteAddress, localAddress) .addListener((ChannelFutureListener) future -> { if (future.isSuccess()) { @@ -92,23 +92,23 @@ private void connect(SocketAddress remoteAddress, SocketAddress localAddress, channel.pipeline().replace(Constants.CONNECTIONLESS_CLIENT_HANDLER, Constants.CONNECT_CLIENT_HANDLER, new UdpConnectClientHandler()); channel.config().setAutoRead(false); - callback.complete(null); + balFuture.complete(null); } else { - callback.complete(Utils.createUdpError("Can't connect to remote host: " + balFuture.complete(Utils.createUdpError("Can't connect to remote host: " + future.cause().getMessage())); } }); } - public void sendData(DatagramPacket datagram, Future callback) { + public void sendData(DatagramPacket datagram, CompletableFuture balFuture) { LinkedList fragments = Utils.fragmentDatagram(datagram); PromiseCombiner promiseCombiner = getPromiseCombiner(fragments); promiseCombiner.finish(channel.newPromise().addListener((ChannelFutureListener) future -> { if (future.isSuccess()) { - callback.complete(null); + balFuture.complete(null); } else { - callback.complete(Utils + balFuture.complete(Utils .createUdpError("Failed to send data: " + future.cause().getMessage())); } })); @@ -116,7 +116,7 @@ public void sendData(DatagramPacket datagram, Future callback) { private PromiseCombiner getPromiseCombiner(LinkedList fragments) { PromiseCombiner promiseCombiner = new PromiseCombiner(ImmediateEventExecutor.INSTANCE); - while (fragments.size() > 0) { + while (!fragments.isEmpty()) { if (channel.isWritable()) { promiseCombiner.add(channel.writeAndFlush(fragments.poll())); } @@ -124,7 +124,8 @@ private PromiseCombiner getPromiseCombiner(LinkedList fragments) return promiseCombiner; } - public void receiveData(double readTimeoutInSec, Future callback) { + public void receiveData(double readTimeoutInSec, CompletableFuture balFuture) { + long readTimeoutInNano = (long) (readTimeoutInSec * 1_000_000_000); channel.pipeline().addFirst(Constants.READ_TIMEOUT_HANDLER, new IdleStateHandler(readTimeoutInNano, 0, 0, TimeUnit.NANOSECONDS)); @@ -132,22 +133,22 @@ public void receiveData(double readTimeoutInSec, Future callback) { if (channel.pipeline().get(Constants.CONNECTIONLESS_CLIENT_HANDLER) != null) { UdpClientHandler handler = (UdpClientHandler) channel.pipeline(). get(Constants.CONNECTIONLESS_CLIENT_HANDLER); - handler.setCallback(callback); + handler.setBalFuture(balFuture); } else { UdpConnectClientHandler handler = (UdpConnectClientHandler) channel.pipeline(). get(Constants.CONNECT_CLIENT_HANDLER); - handler.setCallback(callback); + handler.setBalFuture(balFuture); } channel.read(); } - public void close(Future callback) { + public void close(CompletableFuture balFuture) { channel.close().addListener((ChannelFutureListener) future -> { if (future.isSuccess()) { - callback.complete(null); + balFuture.complete(null); } else { - callback.complete(Utils.createUdpError("Unable to close the UDP client. " + balFuture.complete(Utils.createUdpError("Unable to close the UDP client. " + future.cause().getMessage())); } }); diff --git a/native/src/main/java/io/ballerina/stdlib/udp/UdpClientHandler.java b/native/src/main/java/io/ballerina/stdlib/udp/UdpClientHandler.java index 9730539a..7b5d4589 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/UdpClientHandler.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/UdpClientHandler.java @@ -18,55 +18,48 @@ package io.ballerina.stdlib.udp; -import io.ballerina.runtime.api.Future; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; import io.netty.channel.socket.DatagramPacket; import io.netty.handler.timeout.IdleStateEvent; import java.net.PortUnreachableException; +import java.util.concurrent.CompletableFuture; /** * {@link UdpClientHandler} ia a ChannelInboundHandler implementation for udp client. */ public class UdpClientHandler extends SimpleChannelInboundHandler { - protected Future callback; + protected CompletableFuture balFuture; @Override protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket datagramPacket) throws Exception { ctx.channel().pipeline().remove(Constants.READ_TIMEOUT_HANDLER); - if (callback != null) { - callback.complete(Utils.createReadonlyDatagramWithRecipientAddress(datagramPacket)); - } + balFuture.complete(Utils.createReadonlyDatagramWithRecipientAddress(datagramPacket)); } @Override public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception { if (evt instanceof IdleStateEvent) { ctx.channel().pipeline().remove(Constants.READ_TIMEOUT_HANDLER); - // return timeout error - if (callback != null) { - callback.complete(Utils.createUdpError("Read timed out")); - } + balFuture.complete(Utils.createUdpError("Read timed out")); } } @Override public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { ctx.channel().pipeline().remove(Constants.READ_TIMEOUT_HANDLER); - if (callback != null) { String errorMsg = cause.getMessage(); if (cause instanceof PortUnreachableException) { errorMsg = "Port unreachable (" + ctx.channel().remoteAddress() + ")"; } - callback.complete(Utils.createUdpError(errorMsg)); - } + balFuture.complete(Utils.createUdpError(errorMsg)); } - public void setCallback(Future callback) { - this.callback = callback; + public void setBalFuture(CompletableFuture balFuture) { + this.balFuture = balFuture; } } diff --git a/native/src/main/java/io/ballerina/stdlib/udp/UdpConnectClientHandler.java b/native/src/main/java/io/ballerina/stdlib/udp/UdpConnectClientHandler.java index 131960c0..fe759637 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/UdpConnectClientHandler.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/UdpConnectClientHandler.java @@ -29,9 +29,7 @@ public class UdpConnectClientHandler extends UdpClientHandler { @Override protected void channelRead0(ChannelHandlerContext ctx, DatagramPacket datagramPacket) throws Exception { - if (callback != null) { - callback.complete(Utils.getReadonlyBytesFromDatagram(datagramPacket)); - } + balFuture.complete(Utils.getReadonlyBytesFromDatagram(datagramPacket)); ctx.channel().pipeline().remove(Constants.READ_TIMEOUT_HANDLER); } } diff --git a/native/src/main/java/io/ballerina/stdlib/udp/UdpFactory.java b/native/src/main/java/io/ballerina/stdlib/udp/UdpFactory.java index e093bcfa..46493c87 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/UdpFactory.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/UdpFactory.java @@ -18,18 +18,18 @@ package io.ballerina.stdlib.udp; -import io.ballerina.runtime.api.Future; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import java.net.InetSocketAddress; +import java.util.concurrent.CompletableFuture; /** * {@link UdpFactory} creates {@link UdpClient} and UdpListener. */ public class UdpFactory { - private static volatile UdpFactory udpFactory; + private static volatile UdpFactory udpFactory = new UdpFactory();; private EventLoopGroup group; private UdpFactory() { @@ -37,22 +37,20 @@ private UdpFactory() { } public static UdpFactory getInstance() { - if (udpFactory == null) { - udpFactory = new UdpFactory(); - } return udpFactory; } - public UdpClient createUdpClient(InetSocketAddress localAddress, InetSocketAddress remoteAddress, Future callback) { - return new UdpClient(localAddress, remoteAddress, getInstance().group, callback); + public UdpClient createUdpClient(InetSocketAddress localAddress, InetSocketAddress remoteAddress, + CompletableFuture balFuture) { + return new UdpClient(localAddress, remoteAddress, getInstance().group, balFuture); } - public UdpClient createUdpClient(InetSocketAddress localAddress, Future callback) { - return new UdpClient(localAddress, getInstance().group, callback); + public UdpClient createUdpClient(InetSocketAddress localAddress, CompletableFuture balFuture) { + return new UdpClient(localAddress, getInstance().group, balFuture); } public UdpListener createUdpListener(InetSocketAddress localAddress, InetSocketAddress remoteAddress, - Future callback, UdpService udpService) { - return new UdpListener(localAddress, remoteAddress, getInstance().group, callback, udpService); + CompletableFuture balFuture, UdpService udpService) { + return new UdpListener(localAddress, remoteAddress, getInstance().group, balFuture, udpService); } } diff --git a/native/src/main/java/io/ballerina/stdlib/udp/UdpListener.java b/native/src/main/java/io/ballerina/stdlib/udp/UdpListener.java index 14cb054e..96a27207 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/UdpListener.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/UdpListener.java @@ -18,7 +18,6 @@ package io.ballerina.stdlib.udp; -import io.ballerina.runtime.api.Future; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelFutureListener; @@ -32,6 +31,7 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.LinkedList; +import java.util.concurrent.CompletableFuture; /** * {@link UdpListener} creates the udp client and handles all the network operations. @@ -42,25 +42,25 @@ public class UdpListener { private final Bootstrap listenerBootstrap; public UdpListener(InetSocketAddress localAddress, InetSocketAddress remoteAddress, - EventLoopGroup group, Future callback, UdpService udpService) { + EventLoopGroup group, CompletableFuture balFuture, UdpService udpService) { listenerBootstrap = new Bootstrap(); listenerBootstrap.group(group) .channel(NioDatagramChannel.class) .handler(new ChannelInitializer<>() { @Override - protected void initChannel(Channel ch) throws Exception { + protected void initChannel(Channel ch) { ch.pipeline().addLast(Constants.LISTENER_HANDLER, new UdpListenerHandler(udpService)); } }); if (remoteAddress != null) { - connect(remoteAddress, localAddress, callback); + connect(remoteAddress, localAddress, balFuture); } else { listenerBootstrap.bind(localAddress).addListener((ChannelFutureListener) future -> { if (future.isSuccess()) { channel = future.channel(); - callback.complete(null); + balFuture.complete(null); } else { - callback.complete(Utils.createUdpError("Unable to initialize UDP Listener: " + + balFuture.complete(Utils.createUdpError("Unable to initialize UDP Listener: " + future.cause().getMessage())); } }); @@ -68,15 +68,15 @@ protected void initChannel(Channel ch) throws Exception { } // invoke when caller call writeBytes() or sendDatagram() - public static void send(DatagramPacket datagram, Channel channel, Future callback) { + public static void send(DatagramPacket datagram, Channel channel, CompletableFuture balFuture) { LinkedList fragments = Utils.fragmentDatagram(datagram); PromiseCombiner promiseCombiner = getPromiseCombiner(fragments, channel); promiseCombiner.finish(channel.newPromise().addListener((ChannelFutureListener) future -> { if (future.isSuccess()) { - callback.complete(null); + balFuture.complete(null); } else { - callback.complete(Utils + balFuture.complete(Utils .createUdpError("Failed to send data: " + future.cause().getMessage())); } })); @@ -96,7 +96,7 @@ public static void send(UdpService udpService, DatagramPacket datagram, Channel private static PromiseCombiner getPromiseCombiner(LinkedList fragments, Channel channel) { PromiseCombiner promiseCombiner = new PromiseCombiner(ImmediateEventExecutor.INSTANCE); - while (fragments.size() > 0) { + while (!fragments.isEmpty()) { if (channel.isWritable()) { promiseCombiner.add(channel.writeAndFlush(fragments.poll())); } @@ -105,24 +105,24 @@ private static PromiseCombiner getPromiseCombiner(LinkedList fra } // only invoke if the listener is a connected listener - private void connect(SocketAddress remoteAddress, SocketAddress localAddress, Future callback) { + private void connect(SocketAddress remoteAddress, SocketAddress localAddress, CompletableFuture balFuture) { listenerBootstrap.connect(remoteAddress, localAddress).addListener((ChannelFutureListener) future -> { channel = future.channel(); if (future.isSuccess()) { - callback.complete(null); + balFuture.complete(null); } else { - callback.complete(Utils.createUdpError("Can't connect to remote host.")); + balFuture.complete(Utils.createUdpError("Can't connect to remote host.")); } }); } - public void close(Future callback) throws InterruptedException { + public void close(CompletableFuture balFuture) throws InterruptedException { if (channel != null) { channel.close().sync().addListener((ChannelFutureListener) future -> { if (future.isSuccess()) { - callback.complete(null); + balFuture.complete(null); } else { - callback.complete(Utils.createUdpError("Failed to gracefully shutdown the Listener.")); + balFuture.complete(Utils.createUdpError("Failed to gracefully shutdown the Listener.")); } }); } diff --git a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java index f82d04ec..d48cb6ab 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java @@ -33,6 +33,7 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.Map; +import java.util.concurrent.CompletableFuture; /** * Represents the util functions of Socket operations. @@ -118,4 +119,12 @@ public static void setModule(Environment env) { public static Module getModule() { return udpModule; } + + public static Object getResult(CompletableFuture balFuture) { + try { + return balFuture.get(); + } catch (Throwable throwable) { + throw ErrorCreator.createError(throwable); + } + } } diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java index 495ad41a..a21082c9 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java @@ -19,7 +19,6 @@ package io.ballerina.stdlib.udp.nativeclient; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BDecimal; @@ -33,6 +32,9 @@ import io.netty.channel.socket.DatagramPacket; import java.net.InetSocketAddress; +import java.util.concurrent.CompletableFuture; + +import static io.ballerina.stdlib.udp.Utils.getResult; /** * Native function implementations of the UDP ConnectionlessClient. @@ -44,57 +46,57 @@ public final class Client { private Client() {} public static Object init(Environment env, BObject client, BMap config) { - final Future balFuture = env.markAsync(); - - BString host = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); - InetSocketAddress localAddress; - if (host == null) { - // A port number of zero will let the system pick up an ephemeral port in a bind operation. - localAddress = new InetSocketAddress(0); - } else { - localAddress = new InetSocketAddress(host.getValue(), 0); - } - - double timeout = ((BDecimal) config.get(StringUtils.fromString(Constants.CONFIG_READ_TIMEOUT))).floatValue(); - client.addNativeData(Constants.CONFIG_READ_TIMEOUT, timeout); - - UdpClient udpClient = UdpFactory.getInstance().createUdpClient(localAddress, balFuture); - client.addNativeData(Constants.CONNECTIONLESS_CLIENT, udpClient); - - return null; + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + BString host = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); + InetSocketAddress localAddress; + if (host == null) { + // A port number of zero will let the system pick up an ephemeral port in a bind operation. + localAddress = new InetSocketAddress(0); + } else { + localAddress = new InetSocketAddress(host.getValue(), 0); + } + double timeout = + ((BDecimal) config.get(StringUtils.fromString(Constants.CONFIG_READ_TIMEOUT))).floatValue(); + client.addNativeData(Constants.CONFIG_READ_TIMEOUT, timeout); + + UdpClient udpClient = UdpFactory.getInstance().createUdpClient(localAddress, balFuture); + client.addNativeData(Constants.CONNECTIONLESS_CLIENT, udpClient); + return getResult(balFuture); + }); } public static Object receive(Environment env, BObject client) { - final Future callback = env.markAsync(); - - double readTimeOut = (double) client.getNativeData(Constants.CONFIG_READ_TIMEOUT); - UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECTIONLESS_CLIENT); - udpClient.receiveData(readTimeOut, callback); - - return null; + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + double readTimeOut = (double) client.getNativeData(Constants.CONFIG_READ_TIMEOUT); + UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECTIONLESS_CLIENT); + udpClient.receiveData(readTimeOut, balFuture); + return getResult(balFuture); + }); } public static Object send(Environment env, BObject client, BMap datagram) { - final Future callback = env.markAsync(); - - String host = datagram.getStringValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_HOST)).getValue(); - int port = datagram.getIntValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_PORT)).intValue(); - BArray data = datagram.getArrayValue(StringUtils.fromString(Constants.DATAGRAM_DATA)); - byte[] byteContent = data.getBytes(); - DatagramPacket datagramPacket = new DatagramPacket(Unpooled.wrappedBuffer(byteContent), - new InetSocketAddress(host, port)); - UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECTIONLESS_CLIENT); - udpClient.sendData(datagramPacket, callback); - - return null; + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + String host = datagram.getStringValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_HOST)).getValue(); + int port = datagram.getIntValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_PORT)).intValue(); + BArray data = datagram.getArrayValue(StringUtils.fromString(Constants.DATAGRAM_DATA)); + byte[] byteContent = data.getBytes(); + DatagramPacket datagramPacket = new DatagramPacket(Unpooled.wrappedBuffer(byteContent), + new InetSocketAddress(host, port)); + UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECTIONLESS_CLIENT); + udpClient.sendData(datagramPacket, balFuture); + return getResult(balFuture); + }); } public static Object close(Environment env, BObject client) { - final Future callback = env.markAsync(); - - UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECTIONLESS_CLIENT); - udpClient.close(callback); - - return null; + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECTIONLESS_CLIENT); + udpClient.close(balFuture); + return getResult(balFuture); + }); } } diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java index db69d392..269c4517 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java @@ -19,7 +19,6 @@ package io.ballerina.stdlib.udp.nativeclient; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BDecimal; @@ -33,6 +32,9 @@ import io.netty.channel.socket.DatagramPacket; import java.net.InetSocketAddress; +import java.util.concurrent.CompletableFuture; + +import static io.ballerina.stdlib.udp.Utils.getResult; /** * Native function implementations of the UDP ConnectionlessClient. @@ -45,58 +47,58 @@ private ConnectClient() {} public static Object init(Environment env, BObject client, BString remoteHost, int remotePort, BMap config) { - final Future balFuture = env.markAsync(); - - BString host = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); - InetSocketAddress localAddress; - if (host == null) { - // A port number of zero will let the system pick up an ephemeral port in a bind operation. - localAddress = new InetSocketAddress(0); - } else { - localAddress = new InetSocketAddress(host.getValue(), 0); - } - - double timeout = ((BDecimal) config.get(StringUtils.fromString(Constants.CONFIG_READ_TIMEOUT))).floatValue(); - client.addNativeData(Constants.CONFIG_READ_TIMEOUT, timeout); - - InetSocketAddress remoteAddress = new InetSocketAddress(remoteHost.getValue(), remotePort); - client.addNativeData(Constants.REMOTE_ADDRESS, remoteAddress); - - UdpClient udpClient = UdpFactory.getInstance().createUdpClient(localAddress, remoteAddress, balFuture); - client.addNativeData(Constants.CONNECT_CLIENT, udpClient); - - return null; + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + BString host = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); + InetSocketAddress localAddress; + if (host == null) { + // A port number of zero will let the system pick up an ephemeral port in a bind operation. + localAddress = new InetSocketAddress(0); + } else { + localAddress = new InetSocketAddress(host.getValue(), 0); + } + + double timeout = + ((BDecimal) config.get(StringUtils.fromString(Constants.CONFIG_READ_TIMEOUT))).floatValue(); + client.addNativeData(Constants.CONFIG_READ_TIMEOUT, timeout); + + InetSocketAddress remoteAddress = new InetSocketAddress(remoteHost.getValue(), remotePort); + client.addNativeData(Constants.REMOTE_ADDRESS, remoteAddress); + + UdpClient udpClient = UdpFactory.getInstance().createUdpClient(localAddress, remoteAddress, balFuture); + client.addNativeData(Constants.CONNECT_CLIENT, udpClient); + return getResult(balFuture); + }); } public static Object read(Environment env, BObject client) { - final Future balFuture = env.markAsync(); - - double readTimeOut = (double) client.getNativeData(Constants.CONFIG_READ_TIMEOUT); - UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECT_CLIENT); - udpClient.receiveData(readTimeOut, balFuture); - - return null; + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + double readTimeOut = (double) client.getNativeData(Constants.CONFIG_READ_TIMEOUT); + UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECT_CLIENT); + udpClient.receiveData(readTimeOut, balFuture); + return getResult(balFuture); + }); } public static Object write(Environment env, BObject client, BArray data) { - final Future balFuture = env.markAsync(); - - byte[] byteContent = data.getBytes(); - InetSocketAddress remoteAddress = (InetSocketAddress) client.getNativeData(Constants.REMOTE_ADDRESS); - DatagramPacket datagramPacket = new DatagramPacket(Unpooled.wrappedBuffer(byteContent), remoteAddress); - - UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECT_CLIENT); - udpClient.sendData(datagramPacket, balFuture); - - return null; + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + byte[] byteContent = data.getBytes(); + InetSocketAddress remoteAddress = (InetSocketAddress) client.getNativeData(Constants.REMOTE_ADDRESS); + DatagramPacket datagramPacket = new DatagramPacket(Unpooled.wrappedBuffer(byteContent), remoteAddress); + UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECT_CLIENT); + udpClient.sendData(datagramPacket, balFuture); + return null; + }); } public static Object close(Environment env, BObject client) { - final Future callback = env.markAsync(); - - UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECT_CLIENT); - udpClient.close(callback); - - return null; + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + UdpClient udpClient = (UdpClient) client.getNativeData(Constants.CONNECT_CLIENT); + udpClient.close(balFuture); + return getResult(balFuture); + }); } } diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Caller.java b/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Caller.java index 83f475de..60195041 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Caller.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Caller.java @@ -19,7 +19,6 @@ package io.ballerina.stdlib.udp.nativelistener; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BArray; import io.ballerina.runtime.api.values.BMap; @@ -32,6 +31,9 @@ import io.netty.channel.socket.DatagramPacket; import java.net.InetSocketAddress; +import java.util.concurrent.CompletableFuture; + +import static io.ballerina.stdlib.udp.Utils.getResult; /** * Native function implementations of the UDP Caller. @@ -41,32 +43,34 @@ public final class Caller { private Caller() {} public static Object sendBytes(Environment env, BObject caller, BArray data) { - final Future callback = env.markAsync(); - - byte[] byteContent = data.getBytes(); - String remoteHost = ((BString) caller.getStringValue(StringUtils.fromString(Constants.CALLER_REMOTE_HOST))) - .getValue(); - int remotePort = ((Integer) caller.get(StringUtils.fromString(Constants.CALLER_REMOTE_PORT))); - InetSocketAddress remoteAddress = new InetSocketAddress(remoteHost, remotePort); - DatagramPacket datagram = new DatagramPacket(Unpooled.wrappedBuffer(byteContent), remoteAddress); - Channel channel = (Channel) caller.getNativeData(Constants.CHANNEL); + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + byte[] byteContent = data.getBytes(); + String remoteHost = caller.getStringValue(StringUtils.fromString(Constants.CALLER_REMOTE_HOST)) + .getValue(); + int remotePort = ((Integer) caller.get(StringUtils.fromString(Constants.CALLER_REMOTE_PORT))); + InetSocketAddress remoteAddress = new InetSocketAddress(remoteHost, remotePort); + DatagramPacket datagram = new DatagramPacket(Unpooled.wrappedBuffer(byteContent), remoteAddress); + Channel channel = (Channel) caller.getNativeData(Constants.CHANNEL); - UdpListener.send(datagram, channel, callback); - return null; + UdpListener.send(datagram, channel, balFuture); + return getResult(balFuture); + }); } public static Object sendDatagram(Environment env, BObject caller, BMap datagram) { - final Future callback = env.markAsync(); - - String host = datagram.getStringValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_HOST)).getValue(); - int port = datagram.getIntValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_PORT)).intValue(); - BArray data = datagram.getArrayValue(StringUtils.fromString(Constants.DATAGRAM_DATA)); - byte[] byteContent = data.getBytes(); - DatagramPacket datagramPacket = new DatagramPacket(Unpooled.wrappedBuffer(byteContent), - new InetSocketAddress(host, port)); + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + String host = datagram.getStringValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_HOST)).getValue(); + int port = datagram.getIntValue(StringUtils.fromString(Constants.DATAGRAM_REMOTE_PORT)).intValue(); + BArray data = datagram.getArrayValue(StringUtils.fromString(Constants.DATAGRAM_DATA)); + byte[] byteContent = data.getBytes(); + DatagramPacket datagramPacket = new DatagramPacket(Unpooled.wrappedBuffer(byteContent), + new InetSocketAddress(host, port)); - Channel channel = (Channel) caller.getNativeData(Constants.CHANNEL); - UdpListener.send(datagramPacket, channel, callback); - return null; + Channel channel = (Channel) caller.getNativeData(Constants.CHANNEL); + UdpListener.send(datagramPacket, channel, balFuture); + return getResult(balFuture); + }); } } diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Listener.java b/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Listener.java index 2fa0dcbe..d51ed9d8 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Listener.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativelistener/Listener.java @@ -18,7 +18,6 @@ package io.ballerina.stdlib.udp.nativelistener; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.Future; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; @@ -28,12 +27,12 @@ import io.ballerina.stdlib.udp.UdpListener; import io.ballerina.stdlib.udp.UdpService; import io.ballerina.stdlib.udp.Utils; -import io.ballerina.stdlib.udp.nativeclient.Client; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import java.net.InetAddress; import java.net.InetSocketAddress; +import java.util.concurrent.CompletableFuture; + +import static io.ballerina.stdlib.udp.Utils.getResult; /** * Native function implementations of the UDP Listener. @@ -42,8 +41,6 @@ public final class Listener { private Listener() {} - private static final Logger log = LoggerFactory.getLogger(Client.class); - public static Object init(BObject listener, int localPort, BMap config) { listener.addNativeData(Constants.LISTENER_CONFIG, config); listener.addNativeData(Constants.LOCAL_PORT, localPort); @@ -56,35 +53,33 @@ public static Object register(Environment env, BObject listener, BObject service } public static Object start(Environment env, BObject listener) { - Future balFuture = env.markAsync(); - - BMap config = (BMap) listener.getNativeData(Constants.LISTENER_CONFIG); - - BString localHost = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); - int localPort = (int) listener.getNativeData(Constants.LOCAL_PORT); - InetSocketAddress localAddress; - if (localHost == null) { - localAddress = new InetSocketAddress(localPort); - } else { - String hostname = localHost.getValue(); - localAddress = new InetSocketAddress(hostname, localPort); - } - - InetSocketAddress remoteAddress; - BString remoteHost = config.getStringValue(StringUtils.fromString(Constants.CONFIG_REMOTE_HOST)); - Long remotePort = config.getIntValue(StringUtils.fromString(Constants.CONFIG_REMOTE_PORT)); - - try { - UdpService udpService = (UdpService) listener.getNativeData(Constants.SERVICE); - remoteAddress = getRemoteAddress(remoteHost, remotePort); - UdpListener udpListener = UdpFactory.getInstance() - .createUdpListener(localAddress, remoteAddress, balFuture, udpService); - listener.addNativeData(Constants.LISTENER, udpListener); - } catch (Exception e) { - balFuture.complete(Utils.createUdpError(e.getMessage())); - } - - return null; + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + BMap config = (BMap) listener.getNativeData(Constants.LISTENER_CONFIG); + + BString localHost = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); + int localPort = (int) listener.getNativeData(Constants.LOCAL_PORT); + InetSocketAddress localAddress; + if (localHost == null) { + localAddress = new InetSocketAddress(localPort); + } else { + String hostname = localHost.getValue(); + localAddress = new InetSocketAddress(hostname, localPort); + } + InetSocketAddress remoteAddress; + BString remoteHost = config.getStringValue(StringUtils.fromString(Constants.CONFIG_REMOTE_HOST)); + Long remotePort = config.getIntValue(StringUtils.fromString(Constants.CONFIG_REMOTE_PORT)); + try { + UdpService udpService = (UdpService) listener.getNativeData(Constants.SERVICE); + remoteAddress = getRemoteAddress(remoteHost, remotePort); + UdpListener udpListener = UdpFactory.getInstance() + .createUdpListener(localAddress, remoteAddress, balFuture, udpService); + listener.addNativeData(Constants.LISTENER, udpListener); + } catch (Exception e) { + balFuture.complete(Utils.createUdpError(e.getMessage())); + } + return getResult(balFuture); + }); } public static Object detach(BObject listener) { @@ -97,19 +92,20 @@ public static Object detach(BObject listener) { } public static Object gracefulStop(Environment env, BObject listener) { - Future balFuture = env.markAsync(); - try { - UdpListener udpListener = (UdpListener) listener.getNativeData(Constants.LISTENER); - if (udpListener != null) { - udpListener.close(balFuture); - } else { - balFuture.complete(Utils.createUdpError("Unable to initialize the udp listener.")); + return env.yieldAndRun(() -> { + CompletableFuture balFuture = new CompletableFuture<>(); + try { + UdpListener udpListener = (UdpListener) listener.getNativeData(Constants.LISTENER); + if (udpListener != null) { + udpListener.close(balFuture); + } else { + balFuture.complete(Utils.createUdpError("Unable to initialize the udp listener.")); + } + } catch (InterruptedException e) { + balFuture.complete(Utils.createUdpError("Failed to gracefully shutdown the Listener.")); } - } catch (InterruptedException e) { - balFuture.complete(Utils.createUdpError("Failed to gracefully shutdown the Listener.")); - } - - return null; + return getResult(balFuture); + }); } private static InetSocketAddress getRemoteAddress(BString remoteHost, Long remotePort) throws Exception { @@ -119,7 +115,6 @@ private static InetSocketAddress getRemoteAddress(BString remoteHost, Long remot return new InetSocketAddress(InetAddress.getByName(remoteHost.getValue()).getHostAddress(), (int) remotePort.longValue()); } - return null; } } diff --git a/test-utils/src/main/java/io/ballerina/stdlib/udp/testutils/MockServerUtils.java b/test-utils/src/main/java/io/ballerina/stdlib/udp/testutils/MockServerUtils.java index f1877649..f5d8eed1 100644 --- a/test-utils/src/main/java/io/ballerina/stdlib/udp/testutils/MockServerUtils.java +++ b/test-utils/src/main/java/io/ballerina/stdlib/udp/testutils/MockServerUtils.java @@ -39,9 +39,8 @@ private MockServerUtils() {} private static MockUdpServer mockUdpServer; public static Object startUdpServer() throws InterruptedException { - ExecutorService executor = Executors.newSingleThreadExecutor(); mockUdpServer = new MockUdpServer(); - executor.execute(mockUdpServer); + Thread.startVirtualThread(mockUdpServer); // Give some time to start the UDP server before starting the tests. Thread.sleep(3000); return null; @@ -53,8 +52,7 @@ public static Object stopUdpServer() { } public static Object passUdpContent(BString serverContent, int port) { - ExecutorService client = Executors.newSingleThreadExecutor(); - client.execute(() -> sendUdpContent(serverContent.getValue(), port)); + Thread.startVirtualThread(() -> sendUdpContent(serverContent.getValue(), port)); return null; } From c7876f148385d08a1ba84c0dd7992682b0e41fba Mon Sep 17 00:00:00 2001 From: hindujaB Date: Wed, 13 Nov 2024 15:01:42 +0530 Subject: [PATCH 02/10] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 8 ++++---- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 81df49ef..5446656a 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "udp" -version = "1.11.0" +version = "1.11.1" authors = ["Ballerina"] keywords = ["UDP", "datagram", "transport"] repository = "https://github.com/ballerina-platform/module-ballerina-udp" @@ -15,11 +15,11 @@ graalvmCompatible = true [[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "udp-native" -version = "1.11.0" -path = "../native/build/libs/udp-native-1.11.0.jar" +version = "1.11.1" +path = "../native/build/libs/udp-native-1.11.1-SNAPSHOT.jar" [[platform.java21.dependency]] -path = "../test-utils/build/libs/udp-test-utils-1.11.0.jar" +path = "../test-utils/build/libs/udp-test-utils-1.11.1-SNAPSHOT.jar" scope = "testOnly" [[platform.java21.dependency]] diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 973b9503..f82777bc 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "udp-plugin" class = "io.ballerina.stdlib.udp.compiler.UdpCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/udp-compiler-plugin-1.11.0.jar" +path = "../compiler-plugin/build/libs/udp-compiler-plugin-1.11.1-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ba2379ec..de7bf99a 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 = "io" -version = "1.6.0" +version = "1.6.2" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"}, @@ -75,7 +75,7 @@ dependencies = [ [[package]] org = "ballerina" name = "log" -version = "2.10.0" +version = "2.10.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "io"}, @@ -90,7 +90,7 @@ modules = [ [[package]] org = "ballerina" name = "observe" -version = "1.3.0" +version = "1.4.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} @@ -113,7 +113,7 @@ modules = [ [[package]] org = "ballerina" name = "udp" -version = "1.11.0" +version = "1.11.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, From 01a0ac0a2f498e36c4c8bb7dbe30d0b11134b406 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Wed, 13 Nov 2024 15:03:01 +0530 Subject: [PATCH 03/10] Migrate runtime APIs --- gradle.properties | 10 +++++----- .../java/io/ballerina/stdlib/udp/Dispatcher.java | 14 +++++--------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/gradle.properties b/gradle.properties index 8f2e72a8..7e3fe3d5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,7 +1,7 @@ org.gradle.caching=true group=io.ballerina.stdlib version=1.11.1-SNAPSHOT -ballerinaLangVersion=2201.10.0-20241011-161100-51978649 +ballerinaLangVersion=2201.11.0-20241112-214900-6b80ab87 puppycrawlCheckstyleVersion=10.12.0 githubJohnrengelmanShadowVersion=8.1.1 @@ -16,7 +16,7 @@ ballerinaGradlePluginVersion=2.0.1 gsonVersion=2.8.8 # Dependencies -stdlibIoVersion=1.6.2-20240928-084100-656404f -stdlibLogVersion=2.10.1-20240930-154200-5ab2aa4 -observeVersion=1.3.1-20241007-161000-645452d -observeInternalVersion=1.3.1-20241007-182700-a5f77a1 +stdlibIoVersion=1.6.2-20241112-233100-995cf5f +stdlibLogVersion=2.10.1-20241113-120000-4577868 +observeVersion=1.4.0-20241113-092000-b83ae74 +observeInternalVersion=1.3.1-20241113-101700-265054d diff --git a/native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java b/native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java index efc77576..6a96dab2 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/Dispatcher.java @@ -19,14 +19,14 @@ package io.ballerina.stdlib.udp; import io.ballerina.runtime.api.Runtime; -import io.ballerina.runtime.api.TypeTags; -import io.ballerina.runtime.api.async.StrandMetadata; +import io.ballerina.runtime.api.concurrent.StrandMetadata; import io.ballerina.runtime.api.creators.ErrorCreator; import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.types.MethodType; import io.ballerina.runtime.api.types.ObjectType; import io.ballerina.runtime.api.types.Parameter; import io.ballerina.runtime.api.types.Type; +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.BArray; @@ -92,16 +92,12 @@ private static void invokeAsyncCall(UdpService udpService, DatagramPacket datagr Thread.startVirtualThread(() -> { BObject service = udpService.getService(); Runtime runtime = udpService.getRuntime(); - StrandMetadata metadata = new StrandMetadata(Utils.getModule().getOrg(), Utils.getModule().getName(), - Utils.getModule().getVersion(), methodName); ObjectType objectType = (ObjectType) TypeUtils.getReferredType(TypeUtils.getType(service)); + StrandMetadata metadata = new StrandMetadata( + objectType.isIsolated() && objectType.isIsolated(methodName), null); Object result; try { - if (objectType.isIsolated() && objectType.isIsolated(methodName)) { - result = runtime.startIsolatedWorker(service, methodName, null, metadata, null, params).get(); - } else { - result = runtime.startNonIsolatedWorker(service, methodName, null, metadata, null, params).get(); - } + result = runtime.callMethod(service, methodName, metadata, params); handleResult(udpService, datagramPacket, channel, result); } catch (BError error) { handleError(error); From cba3864956779f0001cdc836879217f3eb1b9ff0 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Wed, 13 Nov 2024 15:03:16 +0530 Subject: [PATCH 04/10] Revert "[Automated] Update the native jar versions" This reverts commit c7876f148385d08a1ba84c0dd7992682b0e41fba. --- ballerina/Ballerina.toml | 8 ++++---- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 5446656a..81df49ef 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "udp" -version = "1.11.1" +version = "1.11.0" authors = ["Ballerina"] keywords = ["UDP", "datagram", "transport"] repository = "https://github.com/ballerina-platform/module-ballerina-udp" @@ -15,11 +15,11 @@ graalvmCompatible = true [[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "udp-native" -version = "1.11.1" -path = "../native/build/libs/udp-native-1.11.1-SNAPSHOT.jar" +version = "1.11.0" +path = "../native/build/libs/udp-native-1.11.0.jar" [[platform.java21.dependency]] -path = "../test-utils/build/libs/udp-test-utils-1.11.1-SNAPSHOT.jar" +path = "../test-utils/build/libs/udp-test-utils-1.11.0.jar" scope = "testOnly" [[platform.java21.dependency]] diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index f82777bc..973b9503 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "udp-plugin" class = "io.ballerina.stdlib.udp.compiler.UdpCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/udp-compiler-plugin-1.11.1-SNAPSHOT.jar" +path = "../compiler-plugin/build/libs/udp-compiler-plugin-1.11.0.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index de7bf99a..ba2379ec 100644 --- a/ballerina/Dependencies.toml +++ b/ballerina/Dependencies.toml @@ -5,12 +5,12 @@ [ballerina] dependencies-toml-version = "2" -distribution-version = "2201.11.0-20241112-214900-6b80ab87" +distribution-version = "2201.10.0" [[package]] org = "ballerina" name = "io" -version = "1.6.2" +version = "1.6.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"}, @@ -75,7 +75,7 @@ dependencies = [ [[package]] org = "ballerina" name = "log" -version = "2.10.1" +version = "2.10.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "io"}, @@ -90,7 +90,7 @@ modules = [ [[package]] org = "ballerina" name = "observe" -version = "1.4.0" +version = "1.3.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} @@ -113,7 +113,7 @@ modules = [ [[package]] org = "ballerina" name = "udp" -version = "1.11.1" +version = "1.11.0" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, From 749e77519d22175b3a17ca1a1769d2cab81dfc65 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Mon, 18 Nov 2024 10:49:11 +0530 Subject: [PATCH 05/10] Revert workflow branches --- .github/workflows/build-timestamped-master.yml | 2 +- .github/workflows/build-with-bal-test-graalvm.yml | 2 +- .github/workflows/central-publish.yml | 2 +- .github/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 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build-timestamped-master.yml b/.github/workflows/build-timestamped-master.yml index e6d67f1c..503d403e 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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/build-timestamp-master-template.yml@main secrets: inherit diff --git a/.github/workflows/build-with-bal-test-graalvm.yml b/.github/workflows/build-with-bal-test-graalvm.yml index 3bf96bb6..184140b1 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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/build-with-bal-test-graalvm-template.yml@main 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 ebe213e7..11922b55 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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main 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 fb245715..0cd0b0f0 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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/process-load-test-results-template.yml@main with: results: ${{ toJson(github.event.client_payload.results) }} secrets: diff --git a/.github/workflows/publish-release.yml b/.github/workflows/publish-release.yml index c7fff35f..f719f09b 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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/release-package-template.yml@main secrets: inherit with: package-name: udp diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml index 660df057..ecfa72ce 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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main secrets: inherit diff --git a/.github/workflows/trigger-load-tests.yml b/.github/workflows/trigger-load-tests.yml index 5c56a78c..4393faf1 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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/trigger-load-tests-template.yml@main with: repo_name: 'module-ballerina-udp' runtime_artifacts_url: 'https://api.github.com/repos/ballerina-platform/module-ballerina-udp/actions/artifacts' diff --git a/.github/workflows/trivy-scan.yml b/.github/workflows/trivy-scan.yml index d91a5f37..458aab57 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@java21 + uses: ballerina-platform/ballerina-library/.github/workflows/trivy-scan-template.yml@main secrets: inherit From 15d91e445112ba8648e14bbe8634e76821f602ec Mon Sep 17 00:00:00 2001 From: hindujaB Date: Mon, 18 Nov 2024 12:24:41 +0530 Subject: [PATCH 06/10] Fix code quality errors --- .../java/io/ballerina/stdlib/udp/Utils.java | 22 +++++++++++++++++++ .../stdlib/udp/nativeclient/Client.java | 13 ++--------- .../udp/nativeclient/ConnectClient.java | 16 ++------------ 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java index d48cb6ab..65cb8b3c 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java @@ -24,12 +24,15 @@ import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BArray; +import io.ballerina.runtime.api.values.BDecimal; 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 io.netty.buffer.ByteBuf; import io.netty.channel.socket.DatagramPacket; +import java.net.InetSocketAddress; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; @@ -123,8 +126,27 @@ public static Module getModule() { public static Object getResult(CompletableFuture balFuture) { try { return balFuture.get(); + } catch (InterruptedException e) { + throw ErrorCreator.createError(e); } catch (Throwable throwable) { throw ErrorCreator.createError(throwable); } } + + public static InetSocketAddress getLocalInetSocketAddress(BObject client, BMap config) { + BString host = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); + InetSocketAddress localAddress; + if (host == null) { + // A port number of zero will let the system pick up an ephemeral port in a bind operation. + localAddress = new InetSocketAddress(0); + } else { + localAddress = new InetSocketAddress(host.getValue(), 0); + } + + double timeout = + ((BDecimal) config.get(StringUtils.fromString(Constants.CONFIG_READ_TIMEOUT))).floatValue(); + client.addNativeData(Constants.CONFIG_READ_TIMEOUT, timeout); + return localAddress; + } + } diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java index a21082c9..c40eb038 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java @@ -34,6 +34,7 @@ import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; +import static io.ballerina.stdlib.udp.Utils.getLocalInetSocketAddress; import static io.ballerina.stdlib.udp.Utils.getResult; /** @@ -49,17 +50,7 @@ public static Object init(Environment env, BObject client, BMap return env.yieldAndRun(() -> { CompletableFuture balFuture = new CompletableFuture<>(); BString host = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); - InetSocketAddress localAddress; - if (host == null) { - // A port number of zero will let the system pick up an ephemeral port in a bind operation. - localAddress = new InetSocketAddress(0); - } else { - localAddress = new InetSocketAddress(host.getValue(), 0); - } - double timeout = - ((BDecimal) config.get(StringUtils.fromString(Constants.CONFIG_READ_TIMEOUT))).floatValue(); - client.addNativeData(Constants.CONFIG_READ_TIMEOUT, timeout); - + InetSocketAddress localAddress = getLocalInetSocketAddress(client, config); UdpClient udpClient = UdpFactory.getInstance().createUdpClient(localAddress, balFuture); client.addNativeData(Constants.CONNECTIONLESS_CLIENT, udpClient); return getResult(balFuture); diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java index 269c4517..9b99e1b9 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java @@ -34,6 +34,7 @@ import java.net.InetSocketAddress; import java.util.concurrent.CompletableFuture; +import static io.ballerina.stdlib.udp.Utils.getLocalInetSocketAddress; import static io.ballerina.stdlib.udp.Utils.getResult; /** @@ -49,22 +50,9 @@ public static Object init(Environment env, BObject client, BString remoteHost, int remotePort, BMap config) { return env.yieldAndRun(() -> { CompletableFuture balFuture = new CompletableFuture<>(); - BString host = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); - InetSocketAddress localAddress; - if (host == null) { - // A port number of zero will let the system pick up an ephemeral port in a bind operation. - localAddress = new InetSocketAddress(0); - } else { - localAddress = new InetSocketAddress(host.getValue(), 0); - } - - double timeout = - ((BDecimal) config.get(StringUtils.fromString(Constants.CONFIG_READ_TIMEOUT))).floatValue(); - client.addNativeData(Constants.CONFIG_READ_TIMEOUT, timeout); - + InetSocketAddress localAddress = getLocalInetSocketAddress(client, config); InetSocketAddress remoteAddress = new InetSocketAddress(remoteHost.getValue(), remotePort); client.addNativeData(Constants.REMOTE_ADDRESS, remoteAddress); - UdpClient udpClient = UdpFactory.getInstance().createUdpClient(localAddress, remoteAddress, balFuture); client.addNativeData(Constants.CONNECT_CLIENT, udpClient); return getResult(balFuture); From 9d5dcf2db46f305055f14bed29859898a2ccdf24 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Mon, 18 Nov 2024 13:27:03 +0530 Subject: [PATCH 07/10] Fix code quality errors --- .../java/io/ballerina/stdlib/udp/Utils.java | 22 ------------------- .../stdlib/udp/nativeclient/Client.java | 1 - .../udp/nativeclient/ConnectClient.java | 2 -- 3 files changed, 25 deletions(-) diff --git a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java index 65cb8b3c..d48cb6ab 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java @@ -24,15 +24,12 @@ import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BArray; -import io.ballerina.runtime.api.values.BDecimal; 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 io.netty.buffer.ByteBuf; import io.netty.channel.socket.DatagramPacket; -import java.net.InetSocketAddress; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; @@ -126,27 +123,8 @@ public static Module getModule() { public static Object getResult(CompletableFuture balFuture) { try { return balFuture.get(); - } catch (InterruptedException e) { - throw ErrorCreator.createError(e); } catch (Throwable throwable) { throw ErrorCreator.createError(throwable); } } - - public static InetSocketAddress getLocalInetSocketAddress(BObject client, BMap config) { - BString host = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); - InetSocketAddress localAddress; - if (host == null) { - // A port number of zero will let the system pick up an ephemeral port in a bind operation. - localAddress = new InetSocketAddress(0); - } else { - localAddress = new InetSocketAddress(host.getValue(), 0); - } - - double timeout = - ((BDecimal) config.get(StringUtils.fromString(Constants.CONFIG_READ_TIMEOUT))).floatValue(); - client.addNativeData(Constants.CONFIG_READ_TIMEOUT, timeout); - return localAddress; - } - } diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java index c40eb038..2b682a25 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/Client.java @@ -21,7 +21,6 @@ import io.ballerina.runtime.api.Environment; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BArray; -import io.ballerina.runtime.api.values.BDecimal; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BString; diff --git a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java index 9b99e1b9..dc939a0c 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/nativeclient/ConnectClient.java @@ -19,9 +19,7 @@ package io.ballerina.stdlib.udp.nativeclient; import io.ballerina.runtime.api.Environment; -import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BArray; -import io.ballerina.runtime.api.values.BDecimal; import io.ballerina.runtime.api.values.BMap; import io.ballerina.runtime.api.values.BObject; import io.ballerina.runtime.api.values.BString; From 9683cb6d4a8c21f9184b1342ebcd0b8af8161125 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Mon, 18 Nov 2024 13:31:27 +0530 Subject: [PATCH 08/10] Add util method --- .../java/io/ballerina/stdlib/udp/Utils.java | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java index d48cb6ab..d9834d43 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java @@ -24,12 +24,15 @@ import io.ballerina.runtime.api.creators.ValueCreator; import io.ballerina.runtime.api.utils.StringUtils; import io.ballerina.runtime.api.values.BArray; +import io.ballerina.runtime.api.values.BDecimal; 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 io.netty.buffer.ByteBuf; import io.netty.channel.socket.DatagramPacket; +import java.net.InetSocketAddress; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; @@ -123,8 +126,26 @@ public static Module getModule() { public static Object getResult(CompletableFuture balFuture) { try { return balFuture.get(); + } catch (InterruptedException e) { + throw ErrorCreator.createError(e); } catch (Throwable throwable) { throw ErrorCreator.createError(throwable); } } + private static InetSocketAddress getLocalInetSocketAddress(BObject client, BMap config) { + BString host = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); + InetSocketAddress localAddress; + if (host == null) { + // A port number of zero will let the system pick up an ephemeral port in a bind operation. + localAddress = new InetSocketAddress(0); + } else { + localAddress = new InetSocketAddress(host.getValue(), 0); + } + + double timeout = + ((BDecimal) config.get(StringUtils.fromString(Constants.CONFIG_READ_TIMEOUT))).floatValue(); + client.addNativeData(Constants.CONFIG_READ_TIMEOUT, timeout); + return localAddress; + } + } From 86022969115725eaa21e3c924c1b8c85b89a54b9 Mon Sep 17 00:00:00 2001 From: hindujaB Date: Mon, 18 Nov 2024 13:51:01 +0530 Subject: [PATCH 09/10] [Automated] Update the native jar versions --- ballerina/Ballerina.toml | 8 ++++---- ballerina/CompilerPlugin.toml | 2 +- ballerina/Dependencies.toml | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ballerina/Ballerina.toml b/ballerina/Ballerina.toml index 81df49ef..5446656a 100644 --- a/ballerina/Ballerina.toml +++ b/ballerina/Ballerina.toml @@ -1,7 +1,7 @@ [package] org = "ballerina" name = "udp" -version = "1.11.0" +version = "1.11.1" authors = ["Ballerina"] keywords = ["UDP", "datagram", "transport"] repository = "https://github.com/ballerina-platform/module-ballerina-udp" @@ -15,11 +15,11 @@ graalvmCompatible = true [[platform.java21.dependency]] groupId = "io.ballerina.stdlib" artifactId = "udp-native" -version = "1.11.0" -path = "../native/build/libs/udp-native-1.11.0.jar" +version = "1.11.1" +path = "../native/build/libs/udp-native-1.11.1-SNAPSHOT.jar" [[platform.java21.dependency]] -path = "../test-utils/build/libs/udp-test-utils-1.11.0.jar" +path = "../test-utils/build/libs/udp-test-utils-1.11.1-SNAPSHOT.jar" scope = "testOnly" [[platform.java21.dependency]] diff --git a/ballerina/CompilerPlugin.toml b/ballerina/CompilerPlugin.toml index 973b9503..f82777bc 100644 --- a/ballerina/CompilerPlugin.toml +++ b/ballerina/CompilerPlugin.toml @@ -3,4 +3,4 @@ id = "udp-plugin" class = "io.ballerina.stdlib.udp.compiler.UdpCompilerPlugin" [[dependency]] -path = "../compiler-plugin/build/libs/udp-compiler-plugin-1.11.0.jar" +path = "../compiler-plugin/build/libs/udp-compiler-plugin-1.11.1-SNAPSHOT.jar" diff --git a/ballerina/Dependencies.toml b/ballerina/Dependencies.toml index ba2379ec..de7bf99a 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 = "io" -version = "1.6.0" +version = "1.6.2" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"}, @@ -75,7 +75,7 @@ dependencies = [ [[package]] org = "ballerina" name = "log" -version = "2.10.0" +version = "2.10.1" scope = "testOnly" dependencies = [ {org = "ballerina", name = "io"}, @@ -90,7 +90,7 @@ modules = [ [[package]] org = "ballerina" name = "observe" -version = "1.3.0" +version = "1.4.0" scope = "testOnly" dependencies = [ {org = "ballerina", name = "jballerina.java"} @@ -113,7 +113,7 @@ modules = [ [[package]] org = "ballerina" name = "udp" -version = "1.11.0" +version = "1.11.1" dependencies = [ {org = "ballerina", name = "io"}, {org = "ballerina", name = "jballerina.java"}, From 9173baa5f5752c3f2a456e93c804da99c5e34a3e Mon Sep 17 00:00:00 2001 From: hindujaB Date: Mon, 18 Nov 2024 13:51:34 +0530 Subject: [PATCH 10/10] Fix code quality --- native/src/main/java/io/ballerina/stdlib/udp/Utils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java index d9834d43..5d0329c9 100644 --- a/native/src/main/java/io/ballerina/stdlib/udp/Utils.java +++ b/native/src/main/java/io/ballerina/stdlib/udp/Utils.java @@ -127,12 +127,14 @@ public static Object getResult(CompletableFuture balFuture) { try { return balFuture.get(); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); throw ErrorCreator.createError(e); } catch (Throwable throwable) { throw ErrorCreator.createError(throwable); } } - private static InetSocketAddress getLocalInetSocketAddress(BObject client, BMap config) { + + public static InetSocketAddress getLocalInetSocketAddress(BObject client, BMap config) { BString host = config.getStringValue(StringUtils.fromString(Constants.CONFIG_LOCALHOST)); InetSocketAddress localAddress; if (host == null) {