Skip to content

Commit

Permalink
Support Kotlin suspend functions as scheduler methods
Browse files Browse the repository at this point in the history
  • Loading branch information
geoand committed Apr 7, 2022
1 parent 0dbfc80 commit 13213ec
Show file tree
Hide file tree
Showing 38 changed files with 516 additions and 73 deletions.
15 changes: 15 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,21 @@
<artifactId>quarkus-undertow-spi</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-scheduler-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-scheduler-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-scheduler-kotlin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-scheduler</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@
import io.quarkus.scheduler.SkippedExecution;
import io.quarkus.scheduler.SuccessfulExecution;
import io.quarkus.scheduler.Trigger;
import io.quarkus.scheduler.runtime.ScheduledInvoker;
import io.quarkus.scheduler.runtime.ScheduledMethodMetadata;
import io.quarkus.scheduler.runtime.SchedulerContext;
import io.quarkus.scheduler.common.runtime.ScheduledInvoker;
import io.quarkus.scheduler.common.runtime.ScheduledMethodMetadata;
import io.quarkus.scheduler.common.runtime.SchedulerContext;
import io.quarkus.scheduler.common.runtime.SkipConcurrentExecutionInvoker;
import io.quarkus.scheduler.common.runtime.SkipPredicateInvoker;
import io.quarkus.scheduler.common.runtime.StatusEmitterInvoker;
import io.quarkus.scheduler.common.runtime.util.SchedulerUtils;
import io.quarkus.scheduler.runtime.SchedulerRuntimeConfig;
import io.quarkus.scheduler.runtime.SkipConcurrentExecutionInvoker;
import io.quarkus.scheduler.runtime.SkipPredicateInvoker;
import io.quarkus.scheduler.runtime.StatusEmitterInvoker;
import io.quarkus.scheduler.runtime.util.SchedulerUtils;
import io.smallrye.common.vertx.VertxContext;
import io.vertx.core.Handler;
import io.vertx.core.Vertx;
Expand Down
25 changes: 25 additions & 0 deletions extensions/scheduler/api/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-scheduler-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-scheduler-api</artifactId>
<name>Quarkus - Scheduler - API</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx</artifactId>
</dependency>
</dependencies>
</project>
41 changes: 41 additions & 0 deletions extensions/scheduler/common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-scheduler-parent</artifactId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-scheduler-common</artifactId>
<name>Quarkus - Scheduler - Common</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-scheduler-api</artifactId>
</dependency>
<dependency>
<groupId>com.cronutils</groupId>
<artifactId>cron-utils</artifactId>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
<exclusion>
<groupId>org.glassfish</groupId>
<artifactId>javax.el</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- TEST dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.scheduler.runtime;
package io.quarkus.scheduler.common.runtime;

import java.util.concurrent.CompletionStage;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.scheduler.runtime;
package io.quarkus.scheduler.common.runtime;

abstract class DelegateInvoker implements ScheduledInvoker {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.scheduler.runtime;
package io.quarkus.scheduler.common.runtime;

import java.util.concurrent.CompletionStage;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.scheduler.runtime;
package io.quarkus.scheduler.common.runtime;

import java.util.List;

Expand Down Expand Up @@ -47,4 +47,4 @@ public void setSchedules(List<Scheduled> schedules) {
this.schedules = schedules;
}

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.scheduler.runtime;
package io.quarkus.scheduler.common.runtime;

import java.lang.reflect.InvocationTargetException;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.scheduler.runtime;
package io.quarkus.scheduler.common.runtime;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.scheduler.runtime;
package io.quarkus.scheduler.common.runtime;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.scheduler.runtime;
package io.quarkus.scheduler.common.runtime;

import java.util.concurrent.CompletionStage;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.scheduler.runtime.util;
package io.quarkus.scheduler.common.runtime.util;

import static io.smallrye.common.expression.Expression.Flag.LENIENT_SYNTAX;
import static io.smallrye.common.expression.Expression.Flag.NO_TRIM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import io.quarkus.scheduler.common.runtime.util.SchedulerUtils;

public class SchedulerUtilsTest {

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.quarkus.scheduler.deployment;

import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.Type;

final class KotlinUtil {

private static final Type VOID_CLASS = Type.create(SchedulerDotNames.VOID, Type.Kind.CLASS);

private KotlinUtil() {
}

static boolean isSuspendMethod(MethodInfo methodInfo) {
if (!methodInfo.parameters().isEmpty()) {
return methodInfo.parameters().get(methodInfo.parameters().size() - 1).name()
.equals(SchedulerDotNames.CONTINUATION);
}
return false;
}

static Type determineReturnTypeOfSuspendMethod(MethodInfo methodInfo) {
Type lastParamType = methodInfo.parameters().get(methodInfo.parameters().size() - 1);
if (lastParamType.kind() != Type.Kind.PARAMETERIZED_TYPE) {
throw new IllegalStateException("Something went wrong during parameter type resolution - expected "
+ lastParamType + " to be a Continuation with a generic type");
}
lastParamType = lastParamType.asParameterizedType().arguments().get(0);
if (lastParamType.kind() != Type.Kind.WILDCARD_TYPE) {
throw new IllegalStateException("Something went wrong during parameter type resolution - expected "
+ lastParamType + " to be a Continuation with a generic type");
}
lastParamType = lastParamType.asWildcardType().superBound();
if (lastParamType.name().equals(SchedulerDotNames.KOTLIN_UNIT)) {
return VOID_CLASS;
}
return lastParamType;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public ScheduledBusinessMethodItem(BeanInfo bean, MethodInfo method, List<Annota
this.method = method;
this.schedules = schedules;
this.nonBlocking = hasNonBlockingAnnotation || SchedulerDotNames.COMPLETION_STAGE.equals(method.returnType().name())
|| SchedulerDotNames.UNI.equals(method.returnType().name());
|| SchedulerDotNames.UNI.equals(method.returnType().name()) || KotlinUtil.isSuspendMethod(method);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ class SchedulerDotNames {
static final DotName COMPLETION_STAGE = DotName.createSimple(CompletionStage.class.getName());
static final DotName VOID = DotName.createSimple(Void.class.getName());

static final DotName CONTINUATION = DotName.createSimple("kotlin.coroutines.Continuation");
static final DotName KOTLIN_UNIT = DotName.createSimple("kotlin.Unit");
static final DotName ABSTRACT_COROUTINE_INVOKER = DotName
.createSimple("io.quarkus.scheduler.kotlin.runtime.AbstractCoroutineInvoker");

}
Loading

0 comments on commit 13213ec

Please sign in to comment.