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

WIP: Initial POC for a new declarative WebSocket server API #38783

Closed
wants to merge 26 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
a06b1b6
Initial POC for a new declarative WebSocket server API
mkouba Feb 1, 2024
170b6e2
MessageCodec: rename canHandle() to supports()
mkouba Feb 15, 2024
2428094
WebSocketServerProcessor: add sample of a generated endpoint class
mkouba Feb 15, 2024
94ddbcc
Codecs: clarify javadoc, add test for TextMessage#outputCodec()
mkouba Feb 15, 2024
5b95142
Decode consumed Multi item in the bytecode
mkouba Feb 16, 2024
d3733a6
Rename Mutex to Bulkhead and try to implement strategy proposed by Franz
mkouba Feb 16, 2024
3056fe4
Add test for BlockingSender.sendTextAndAwait(String)
mkouba Feb 16, 2024
50c5cb0
Rename Bulkhead to ConcurrencyLimiter
mkouba Feb 16, 2024
5ff81ac
ConcurrencyLimiter - add asserts to verify the mechanism works correctly
mkouba Feb 16, 2024
d941c00
Introduce WebSocketServerException and default timeout for callbacks
mkouba Feb 21, 2024
4c07f7b
Verify web socket signatures, scopes, and endpoint annotation issues
cescoffier Feb 20, 2024
1846ea7
Add support for io.vertx.core.json.JsonArray
mkouba Feb 22, 2024
731b42c
Introduce WebSocket#executionMode()
mkouba Feb 27, 2024
b9ea633
Rename WebSocket.ExecutionMode.SIMULTANEOUS to CONCURRENT
mkouba Feb 27, 2024
e055614
Improve WebSocket javadoc
mkouba Feb 27, 2024
a241c14
CDI session context improvements
mkouba Feb 28, 2024
b9ef0af
Sort imports in WebSocketSessionContext
mkouba Feb 28, 2024
cf0ee83
Execution model refactoring
mkouba Feb 29, 2024
f85cce3
SignatureConsumingMultiTest: add asserts for CDI request context
mkouba Feb 29, 2024
da5d101
Improve the RequestContextTest
mkouba Mar 1, 2024
d3f2ecd
Annotate API with io.smallrye.common.annotation.Experimental
mkouba Mar 1, 2024
400f7e8
Set experimental status in the descriptor
mkouba Mar 1, 2024
46b9376
Add WebSocketServerConnection#closeAndAwait() and ConnectionCloseTest
mkouba Mar 1, 2024
284847c
ContextSupport - log server connection info
mkouba Mar 1, 2024
2dad087
Introduce HandshakeRequest accessible from the connection
mkouba Mar 2, 2024
e8fd866
Rename WebSocketServerConnection#handshake() to handshakeRequest()
mkouba Mar 4, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2066,6 +2066,16 @@
<artifactId>quarkus-websockets-client-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-websockets-next</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-websockets-next-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-undertow-spi</artifactId>
Expand Down
20 changes: 20 additions & 0 deletions extensions/websockets-next/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?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>
<artifactId>quarkus-extensions-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-websockets-next-aggregator</artifactId>
<name>Quarkus - WebSockets Next Aggregator</name>
<packaging>pom</packaging>
<modules>
<module>server</module>
</modules>

</project>
72 changes: 72 additions & 0 deletions extensions/websockets-next/server/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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>
<artifactId>quarkus-websockets-next-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-websockets-next-deployment</artifactId>
<name>Quarkus - WebSockets Next - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-http-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jackson-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-websockets-next</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5-internal</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<systemPropertyVariables>
<java.util.logging.manager>
org.jboss.logmanager.LogManager</java.util.logging.manager>
<quarkus.log.level>INFO</quarkus.log.level>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package io.quarkus.websockets.next.deployment;

import io.quarkus.builder.item.MultiBuildItem;

/**
* A generated {@link io.quarkus.websockets.next.runtime.WebSocketEndpoint}.
*/
final class GeneratedEndpointBuildItem extends MultiBuildItem {

final String className;
final String path;

GeneratedEndpointBuildItem(String className, String path) {
this.className = className;
this.path = path;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.quarkus.websockets.next.deployment;

import org.jboss.jandex.DotName;

import io.quarkus.websockets.next.BinaryMessage;
import io.quarkus.websockets.next.OnClose;
import io.quarkus.websockets.next.OnMessage;
import io.quarkus.websockets.next.OnOpen;
import io.quarkus.websockets.next.TextMessage;
import io.quarkus.websockets.next.WebSocket;
import io.quarkus.websockets.next.WebSocketServerConnection;
import io.smallrye.common.annotation.Blocking;
import io.smallrye.common.annotation.RunOnVirtualThread;
import io.smallrye.mutiny.Multi;
import io.smallrye.mutiny.Uni;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;

final class WebSocketDotNames {

static final DotName WEB_SOCKET = DotName.createSimple(WebSocket.class);
static final DotName WEB_SOCKET_CONNECTION = DotName.createSimple(WebSocketServerConnection.class);
static final DotName ON_OPEN = DotName.createSimple(OnOpen.class);
static final DotName ON_MESSAGE = DotName.createSimple(OnMessage.class);
static final DotName ON_CLOSE = DotName.createSimple(OnClose.class);
static final DotName UNI = DotName.createSimple(Uni.class);
static final DotName MULTI = DotName.createSimple(Multi.class);
static final DotName RUN_ON_VIRTUAL_THREAD = DotName.createSimple(RunOnVirtualThread.class);
static final DotName BLOCKING = DotName.createSimple(Blocking.class);
static final DotName STRING = DotName.createSimple(String.class);
static final DotName BUFFER = DotName.createSimple(Buffer.class);
static final DotName JSON_OBJECT = DotName.createSimple(JsonObject.class);
static final DotName JSON_ARRAY = DotName.createSimple(JsonArray.class);
static final DotName VOID = DotName.createSimple(Void.class);
static final DotName BINARY_MESSAGE = DotName.createSimple(BinaryMessage.class);
static final DotName TEXT_MESSAGE = DotName.createSimple(TextMessage.class);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
package io.quarkus.websockets.next.deployment;

import org.jboss.jandex.AnnotationInstance;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.DotName;
import org.jboss.jandex.MethodInfo;
import org.jboss.jandex.PrimitiveType;
import org.jboss.jandex.Type;
import org.jboss.jandex.Type.Kind;

import io.quarkus.arc.processor.BeanInfo;
import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.websockets.next.WebSocket;
import io.quarkus.websockets.next.runtime.WebSocketEndpoint;
import io.quarkus.websockets.next.runtime.WebSocketEndpoint.ExecutionModel;
import io.quarkus.websockets.next.runtime.WebSocketEndpoint.MessageType;

/**
* This build item represents a WebSocket endpoint class.
*/
public final class WebSocketEndpointBuildItem extends MultiBuildItem {

public final BeanInfo bean;
public final String path;
public final WebSocket.ExecutionMode executionMode;
public final Callback onOpen;
public final Callback onMessage;
public final Callback onClose;

public WebSocketEndpointBuildItem(BeanInfo bean, String path, WebSocket.ExecutionMode executionMode, Callback onOpen,
Callback onMessage, Callback onClose) {
this.bean = bean;
this.path = path;
this.executionMode = executionMode;
this.onOpen = onOpen;
this.onMessage = onMessage;
this.onClose = onClose;
}

public static class Callback {

public final AnnotationInstance annotation;
public final MethodInfo method;
public final ExecutionModel executionModel;
public final MessageType consumedMessageType;
public final MessageType producedMessageType;

public Callback(AnnotationInstance annotation, MethodInfo method, ExecutionModel executionModel) {
this.method = method;
this.annotation = annotation;
this.executionModel = executionModel;
this.consumedMessageType = initMessageType(method.parameters().isEmpty() ? null : method.parameterType(0));
this.producedMessageType = initMessageType(method.returnType());
}

public Type returnType() {
return method.returnType();
}

public Type messageParamType() {
return acceptsMessage() ? method.parameterType(0) : null;
}

public boolean isReturnTypeVoid() {
return returnType().kind() == Kind.VOID;
}

public boolean isReturnTypeUni() {
return WebSocketDotNames.UNI.equals(returnType().name());
}

public boolean isReturnTypeMulti() {
return WebSocketDotNames.MULTI.equals(returnType().name());
}

public boolean acceptsMessage() {
return consumedMessageType != MessageType.NONE;
}

public boolean acceptsBinaryMessage() {
return consumedMessageType == MessageType.BINARY;
}

public boolean acceptsMulti() {
return acceptsMessage() && method.parameterType(0).name().equals(WebSocketDotNames.MULTI);
}

public WebSocketEndpoint.MessageType consumedMessageType() {
return consumedMessageType;
}

public WebSocketEndpoint.MessageType producedMessageType() {
return producedMessageType;
}

public boolean broadcast() {
AnnotationValue broadcastValue = annotation.value("broadcast");
return broadcastValue != null && broadcastValue.asBoolean();
}

public DotName getInputCodec() {
return getCodec("inputCodec");
}

public DotName getOutpuCodec() {
DotName output = getCodec("outputCodec");
return output != null ? output : getInputCodec();
}

private DotName getCodec(String valueName) {
AnnotationInstance messageAnnotation = method.declaredAnnotation(WebSocketDotNames.BINARY_MESSAGE);
if (messageAnnotation == null) {
messageAnnotation = method.declaredAnnotation(WebSocketDotNames.TEXT_MESSAGE);
}
if (messageAnnotation != null) {
AnnotationValue codecValue = messageAnnotation.value(valueName);
if (codecValue != null) {
return codecValue.asClass().name();
}
}
return null;
}

MessageType initMessageType(Type messageType) {
MessageType ret = MessageType.NONE;
if (messageType != null && !messageType.name().equals(WebSocketDotNames.VOID)) {
if (method.hasDeclaredAnnotation(WebSocketDotNames.BINARY_MESSAGE)) {
ret = MessageType.BINARY;
} else if (method.hasDeclaredAnnotation(WebSocketDotNames.TEXT_MESSAGE)) {
ret = MessageType.TEXT;
} else {
if (isByteArray(messageType) || WebSocketDotNames.BUFFER.equals(messageType.name())) {
ret = MessageType.BINARY;
} else {
ret = MessageType.TEXT;
}
}
}
return ret;
}

static boolean isByteArray(Type type) {
return type.kind() == Kind.ARRAY && PrimitiveType.BYTE.equals(type.asArrayType().constituent());
}

static boolean isUniVoid(Type type) {
return WebSocketDotNames.UNI.equals(type.name())
&& type.asParameterizedType().arguments().get(0).name().equals(WebSocketDotNames.VOID);
}

}

}
Loading
Loading