Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to Java 21 #509

Merged
merged 12 commits into from
Nov 18, 2024
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ This repository only contains the source code for the package.
## Build from the source
### Set up the prerequisites

1. Download and install Java SE Development Kit (JDK) version 17 (from one of the following locations).
1. Download and install Java SE Development Kit (JDK) version 21 (from one of the following locations).
* [Oracle](https://www.oracle.com/java/technologies/downloads/)

* [OpenJDK](https://adoptium.net/)
Expand Down
6 changes: 3 additions & 3 deletions ballerina/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.8.0"

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

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

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/quartz-2.3.2.jar"
6 changes: 3 additions & 3 deletions build-config/resources/Ballerina.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ icon = "icon.png"
license = ["Apache-2.0"]
distribution = "2201.8.0"

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

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

[[platform.java17.dependency]]
[[platform.java21.dependency]]
path = "./lib/quartz-@quartz.version@.jar"
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ org.gradle.caching=true
group=io.ballerina.stdlib
version=2.5.1-SNAPSHOT

ballerinaLangVersion=2201.8.0
ballerinaLangVersion=2201.11.0-20241117-133400-a3054b77
axiomVersion=1.2.22
puppycrawlCheckstyleVersion=10.12.0
ballerinaGradlePluginVersion=2.0.1
githubSpotbugsVersion=5.0.14
githubSpotbugsVersion=6.0.18
githubJohnrengelmanShadowVersion=7.1.2
underCouchDownloadVersion=5.4.0
researchgateReleaseVersion=2.8.0

quartzVersion=2.3.2

#stdlib dependencies
stdlibTimeVersion=2.4.0
stdlibTimeVersion=2.6.0-20241113-073800-201b904
8 changes: 6 additions & 2 deletions native/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,12 @@ tasks.withType(Checkstyle) {
}

spotbugsMain {
effort "max"
reportLevel "low"
ignoreFailures = true
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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
package io.ballerina.stdlib.task.utils;

import io.ballerina.runtime.api.Runtime;
import io.ballerina.runtime.api.async.Callback;
import io.ballerina.runtime.api.concurrent.StrandMetadata;
import io.ballerina.runtime.api.creators.ErrorCreator;
import io.ballerina.runtime.api.types.ObjectType;
import io.ballerina.runtime.api.values.BError;
import io.ballerina.runtime.api.values.BObject;
import io.ballerina.stdlib.task.objects.TaskManager;
import org.quartz.Job;
Expand All @@ -37,9 +40,19 @@ public TaskJob() {
*/
@Override
public void execute(JobExecutionContext jobExecutionContext) {
Runtime runtime = TaskManager.getInstance().getRuntime();
BObject job = (BObject) jobExecutionContext.getMergedJobDataMap().get(TaskConstants.JOB);
Callback callback = new TaskCallBack(jobExecutionContext);
runtime.invokeMethodAsync(job, TaskConstants.EXECUTE, null, null, callback);
Thread.startVirtualThread(() -> {
Runtime runtime = TaskManager.getInstance().getRuntime();
BObject job = (BObject) jobExecutionContext.getMergedJobDataMap().get(TaskConstants.JOB);
try {
ObjectType objectType = (ObjectType) job.getOriginalType();
boolean isConcurrentSafe = objectType.isIsolated() && objectType.isIsolated(TaskConstants.EXECUTE);
StrandMetadata metadata = new StrandMetadata(isConcurrentSafe, null);
runtime.callMethod(job, TaskConstants.EXECUTE, metadata);
} catch (BError error) {
Utils.notifyFailure(jobExecutionContext, error);
} catch (Throwable t) {
Utils.notifyFailure(jobExecutionContext, ErrorCreator.createError(t));
}
});
}
}
33 changes: 32 additions & 1 deletion native/src/main/java/io/ballerina/stdlib/task/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,16 @@
*/
package io.ballerina.stdlib.task.utils;

import io.ballerina.runtime.api.TypeTags;
import io.ballerina.runtime.api.creators.ErrorCreator;
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.BError;
import io.ballerina.stdlib.task.exceptions.SchedulingException;
import org.quartz.JobBuilder;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SimpleScheduleBuilder;
Expand Down Expand Up @@ -58,6 +59,8 @@ private Utils() {}

private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS");

private static final PrintStream console = System.out;

public static BError createTaskError(String message) {
return ErrorCreator.createDistinctError(TaskConstants.ERROR, ModuleUtils.getModule(),
StringUtils.fromString(message));
Expand Down Expand Up @@ -164,4 +167,32 @@ public static void disableQuartzLogs() {
public static boolean isInt(Object time) {
return TypeUtils.getType(time).getTag() == TypeTags.INT_TAG;
}

public static void notifyFailure(JobExecutionContext jobExecutionContext, BError bError) {
Scheduler scheduler = jobExecutionContext.getScheduler();
String errorPolicy = (String) jobExecutionContext.getMergedJobDataMap().get(TaskConstants.ERROR_POLICY);
String jobId = (String) jobExecutionContext.getMergedJobDataMap().get(TaskConstants.JOB_ID);
if (isLogged(errorPolicy)) {
Utils.printMessage("Unable to execute the job[" + jobId + "]. " + bError.getMessage(), console);
}
if (isTerminated(errorPolicy)) {
try {
scheduler.unscheduleJob(jobExecutionContext.getTrigger().getKey());
} catch (SchedulerException e) {
if (errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_TERMINATE)) {
Utils.printMessage(e.toString(), console);
}
}
}
}

private static boolean isLogged(String errorPolicy) {
return errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_TERMINATE) ||
errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_CONTINUE);
}

private static boolean isTerminated(String errorPolicy) {
return errorPolicy.equalsIgnoreCase(TaskConstants.LOG_AND_TERMINATE) ||
errorPolicy.equalsIgnoreCase(TaskConstants.TERMINATE);
}
}
1 change: 1 addition & 0 deletions native/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
requires io.ballerina.runtime;
requires quartz;
requires java.logging;
requires io.ballerina.lang;
exports io.ballerina.stdlib.task.actions;
exports io.ballerina.stdlib.task.exceptions;
exports io.ballerina.stdlib.task.objects;
Expand Down
Loading