Skip to content

Commit

Permalink
Merge pull request #244 from ravinperera00/java21
Browse files Browse the repository at this point in the history
Migrate to Java 21
  • Loading branch information
warunalakshitha authored Oct 17, 2024
2 parents 052bf67 + 39c9de4 commit b614c0a
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 161 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build-timestamped-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/build-with-bal-test-graalvm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/central-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
call_workflow:
name: Run Central Publish Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/central-publish-template.yml@java21
secrets: inherit
with:
environment: ${{ github.event.inputs.environment }}
2 changes: 1 addition & 1 deletion .github/workflows/process-load-test-result.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: mqtt
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
call_workflow:
name: Run PR Build Workflow
if: ${{ github.repository_owner == 'ballerina-platform' }}
uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@main
uses: ballerina-platform/ballerina-library/.github/workflows/pull-request-build-template.yml@java21
with:
additional-windows-test-flags: "-x test"
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/trigger-load-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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-mqtt'
runtime_artifacts_url: 'https://api.github.com/repos/ballerina-platform/module-ballerina-mqtt/actions/artifacts'
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trivy-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 6 additions & 6 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ version = "1.2.0"
authors = ["ballerina"]
keywords = ["mqtt", "client", "messaging", "network", "pubsub", "iot"]
repository = "https://github.com/ballerina-platform/module-ballerina-mqtt"
distribution = "2201.10.0"
distribution = "2201.10.0-20241007-143200-6b69ca80"

[platform.java17]
[platform.java21]
graalvmCompatible = true

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "mqtt-native"
version = "1.2.0"
path = "../native/build/libs/mqtt-native-1.2.0.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "org.eclipse.paho"
artifactId = "org.eclipse.paho.mqttv5.client"
version = "1.2.5"
path = "./lib/org.eclipse.paho.mqttv5.client-1.2.5.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "org.bouncycastle"
artifactId = "bcpkix-jdk18on"
version = "1.78"
path = "./lib/bcpkix-jdk18on-1.78.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "org.bouncycastle"
artifactId = "bcutil-jdk18on"
version = "1.78"
Expand Down
2 changes: 1 addition & 1 deletion ballerina/Dependencies.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

[ballerina]
dependencies-toml-version = "2"
distribution-version = "2201.10.0"
distribution-version = "2201.10.0-20241007-143200-6b69ca80"

[[package]]
org = "ballerina"
Expand Down
12 changes: 6 additions & 6 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,30 @@ version = "@toml.version@"
authors = ["ballerina"]
keywords = ["mqtt", "client", "messaging", "network", "pubsub", "iot"]
repository = "https://github.com/ballerina-platform/module-ballerina-mqtt"
distribution = "2201.10.0"
distribution = "2201.10.0-20241007-143200-6b69ca80"

[platform.java17]
[platform.java21]
graalvmCompatible = true

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "io.ballerina.stdlib"
artifactId = "mqtt-native"
version = "@toml.version@"
path = "../native/build/libs/[email protected]@.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "org.eclipse.paho"
artifactId = "org.eclipse.paho.mqttv5.client"
version = "@paho.mqtt.version@"
path = "./lib/[email protected]@.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "org.bouncycastle"
artifactId = "bcpkix-jdk18on"
version = "@bouncy.castle.version@"
path = "./lib/[email protected]@.jar"

[[platform.java17.dependency]]
[[platform.java21.dependency]]
groupId = "org.bouncycastle"
artifactId = "bcutil-jdk18on"
version = "@bouncy.castle.version@"
Expand Down
7 changes: 5 additions & 2 deletions compiler-plugin-tests/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,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
Expand Down
7 changes: 5 additions & 2 deletions compiler-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,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
Expand Down
20 changes: 10 additions & 10 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
org.gradle.caching=true
group=io.ballerina.stdlib
version=1.2.1-SNAPSHOT
ballerinaLangVersion=2201.10.0
ballerinaLangVersion=2201.10.0-20241011-152000-627c5bb0

checkstylePluginVersion=10.12.1
spotbugsPluginVersion=5.0.14
spotbugsPluginVersion=6.0.18
shadowJarPluginVersion=8.1.1
downloadPluginVersion=5.4.0
releasePluginVersion=2.8.0
Expand All @@ -20,16 +20,16 @@ pahoMqtt5Version=1.2.5
#stdlib dependencies

# Level 01
stdlibTimeVersion=2.4.0
stdlibIoVersion=1.6.0
stdlibTimeVersion=2.5.1-20240930-120200-e59222b
stdlibIoVersion=1.6.2-20240928-084100-656404f

# Level 02
stdlibLogVersion=2.10.0
stdlibCryptoVersion=2.7.2
stdlibRandomVersion=1.5.0
stdlibLogVersion=2.10.1-20240930-154200-5ab2aa4
stdlibCryptoVersion=2.7.3-20240930-132000-5ecc9ab
stdlibRandomVersion=1.5.1-20240930-193000-e5c6c0e

# Level 03
stdlibUuidVersion=1.8.0
stdlibUuidVersion=1.8.1-20241009-134600-a05012b

observeVersion=1.3.0
observeInternalVersion=1.3.0
observeVersion=1.3.1-20241007-161000-645452d
observeInternalVersion=1.3.1-20241007-182700-a5f77a1
7 changes: 5 additions & 2 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@
package io.ballerina.stdlib.mqtt.caller;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.Future;
import io.ballerina.runtime.api.values.BMap;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.stdlib.mqtt.utils.MqttConstants;
import io.ballerina.stdlib.mqtt.utils.MqttUtils;
import io.ballerina.stdlib.mqtt.utils.Util;
import org.eclipse.paho.mqttv5.client.MqttClient;
import org.eclipse.paho.mqttv5.common.MqttException;
import org.eclipse.paho.mqttv5.common.MqttMessage;

import java.util.Objects;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

Expand All @@ -47,16 +48,18 @@ public static Object complete(Environment env, BObject callerObject) {
MqttClient subscriber = (MqttClient) callerObject.getNativeData(MqttConstants.SUBSCRIBER);
int messageId = (int) callerObject.getNativeData(MqttConstants.MESSAGE_ID);
int qos = (int) callerObject.getNativeData(MqttConstants.QOS);
Future future = env.markAsync();
executorService.execute(() -> {
try {
subscriber.messageArrivedComplete(messageId, qos);
future.complete(null);
} catch (MqttException e) {
future.complete(MqttUtils.createMqttError(e));
}
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
executorService.execute(() -> {
try {
subscriber.messageArrivedComplete(messageId, qos);
future.complete(null);
} catch (MqttException e) {
future.complete(MqttUtils.createMqttError(e));
}
});
return Util.getResult(future);
});
return null;
}

public static Object respond(Environment env, BObject callerObject, BMap message) {
Expand All @@ -70,16 +73,17 @@ public static Object respond(Environment env, BObject callerObject, BMap message
if (Objects.nonNull(correlationData)) {
mqttMessage.getProperties().setCorrelationData(correlationData);
}
Future future = env.markAsync();
executorService.execute(() -> {
try {
subscriber.publish(responseTopic, mqttMessage);
future.complete(null);
} catch (MqttException e) {
future.complete(MqttUtils.createMqttError(e));
}
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
executorService.execute(() -> {
try {
subscriber.publish(responseTopic, mqttMessage);
future.complete(null);
} catch (MqttException e) {
future.complete(MqttUtils.createMqttError(e));
}
});
return Util.getResult(future);
});
return null;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package io.ballerina.stdlib.mqtt.client;

import io.ballerina.runtime.api.Environment;
import io.ballerina.runtime.api.Future;
import io.ballerina.runtime.api.creators.TypeCreator;
import io.ballerina.runtime.api.creators.ValueCreator;
import io.ballerina.runtime.api.types.StreamType;
Expand All @@ -32,6 +31,7 @@
import io.ballerina.runtime.api.values.BTypedesc;
import io.ballerina.stdlib.mqtt.utils.MqttConstants;
import io.ballerina.stdlib.mqtt.utils.MqttUtils;
import io.ballerina.stdlib.mqtt.utils.Util;
import org.eclipse.paho.mqttv5.client.MqttClient;
import org.eclipse.paho.mqttv5.client.MqttConnectionOptions;
import org.eclipse.paho.mqttv5.client.persist.MemoryPersistence;
Expand All @@ -41,6 +41,7 @@

import java.util.ArrayList;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
Expand Down Expand Up @@ -107,8 +108,9 @@ public static Object externSubscribe(BObject clientObject, BArray subscriptions)
public static Object externPublish(Environment env, BObject clientObject, BString topic, BMap message) {
MqttClient publisher = (MqttClient) clientObject.getNativeData(MqttConstants.MQTT_CLIENT);
MqttMessage mqttMessage = generateMqttMessage(message);
try {
Future future = env.markAsync();
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
try {
publisher.publish(topic.getValue(), mqttMessage);
LinkedBlockingQueue deliveryTokenQueue = (LinkedBlockingQueue) clientObject
.getNativeData(DELIVERY_TOKEN_QUEUE);
Expand All @@ -120,10 +122,11 @@ public static Object externPublish(Environment env, BObject clientObject, BStrin
future.complete(MqttUtils.createMqttError(e));
}
});
} catch (MqttException e) {
return MqttUtils.createMqttError(e);
}
return null;
} catch (MqttException e) {
return MqttUtils.createMqttError(e);
}
return Util.getResult(future);
});
}

public static Object externReceive(BObject clientObject, BTypedesc bTypedesc) {
Expand Down Expand Up @@ -180,17 +183,19 @@ public static Object externReconnect(BObject clientObject) {
public static Object nextResult(Environment env, BObject streamIterator) {
BlockingQueue<?> messageQueue = (BlockingQueue<?>) streamIterator.getNativeData(RESPONSE_QUEUE);
ExecutorService executor = (ExecutorService) streamIterator.getNativeData(RESPONSE_EXECUTOR_SERVICE);
Future future = env.markAsync();
executor.execute(() -> {
try {
BMap message = (BMap) messageQueue.take();
future.complete(message);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
future.complete(MqttUtils.createMqttError(e));
}
return env.yieldAndRun(() -> {
CompletableFuture<Object> future = new CompletableFuture<>();
executor.execute(() -> {
try {
BMap message = (BMap) messageQueue.take();
future.complete(message);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
future.complete(MqttUtils.createMqttError(e));
}
});
return Util.getResult(future);
});
return null;
}

public static void closeStream(BObject streamIterator) {
Expand Down
Loading

0 comments on commit b614c0a

Please sign in to comment.