Skip to content

Commit

Permalink
Sync documentation of main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Oct 12, 2024
1 parent 73126e6 commit 0d460a5
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
15 changes: 15 additions & 0 deletions _versions/main/guides/cdi-integration.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,21 @@ if (foo.getHandle().getBean().isActive()) {
}
----

If you want to consume only active beans, you can inject an `InjectableInstance<>` and call `getActive()` to get the single instance or `listActive()` to get all instances:

[source,java]
----
import io.quarkus.arc.InjectableInstance;
@Inject
@Any
InjectableInstance<Foo> foos;
for (Foo foo : foos.listActive())
...
}
----

[[synthetic_observers]]
== Use Case - Synthetic Observers

Expand Down
69 changes: 69 additions & 0 deletions _versions/main/guides/websockets-next-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,40 @@ class MyBean {
There are also other convenient methods.
For example, `OpenConnections#findByEndpointId(String)` makes it easy to find connections for a specific endpoint.

==== User data

It is also possible to associate arbitrary user data with a specific connection.
The `io.quarkus.websockets.next.UserData` object obtained by the `WebSocketConnection#userData()` method represents mutable user data associated with a connection.

[source, java]
----
import io.quarkus.websockets.next.WebSocketConnection;
import io.quarkus.websockets.next.UserData.TypedKey;
@WebSocket(path = "/endpoint/{username}")
class MyEndpoint {
@Inject
CoolService service;
@OnOpen
void open(WebSocketConnection connection) {
connection.userData().put(TypedKey.forBoolean("isCool"), service.isCool(connection.pathParam("username"))); <1>
}
@OnTextMessage
String process(String message) {
if (connection.userData().get(TypedKey.forBoolean("isCool"))) { <2>
return "Cool message processed!";
} else {
return "Message processed!";
}
}
}
----
<1> `CoolService#isCool()` returns `Boolean` that is associated with the current connection.
<2> The `TypedKey.forBoolean("isCool")` is the key used to obtain the data stored when the connection was created.

[[server-cdi-events]]
==== CDI events

Expand Down Expand Up @@ -997,6 +1031,41 @@ class MyBean {
There are also other convenient methods.
For example, `OpenClientConnections#findByClientId(String)` makes it easy to find connections for a specific endpoint.

==== User data

It is also possible to associate arbitrary user data with a specific connection.
The `io.quarkus.websockets.next.UserData` object obtained by the `WebSocketClientConnection#userData()` method represents mutable user data associated with a connection.

[source, java]
----
import io.quarkus.websockets.next.WebSocketClientConnection;
import io.quarkus.websockets.next.UserData.TypedKey;
@WebSocketClient(path = "/endpoint/{username}")
class MyEndpoint {
@Inject
CoolService service;
@OnOpen
void open(WebSocketClientConnection connection) {
connection.userData().put(TypedKey.forBoolean("isCool"), service.isCool(connection.pathParam("username"))); <1>
}
@OnTextMessage
String process(String message) {
if (connection.userData().get(TypedKey.forBoolean("isCool"))) { <2>
return "Cool message processed!";
} else {
return "Message processed!";
}
}
}
----
<1> `CoolService#isCool()` returns `Boolean` that is associated with the current connection.
<2> The `TypedKey.forBoolean("isCool")` is the key used to obtain the data stored when the connection was created.


[[client-cdi-events]]
==== CDI events

Expand Down

0 comments on commit 0d460a5

Please sign in to comment.