Skip to content

Commit 0d460a5

Browse files
committed
Sync documentation of main branch
1 parent 73126e6 commit 0d460a5

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-0
lines changed

_versions/main/guides/cdi-integration.adoc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,21 @@ if (foo.getHandle().getBean().isActive()) {
486486
}
487487
----
488488

489+
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:
490+
491+
[source,java]
492+
----
493+
import io.quarkus.arc.InjectableInstance;
494+
495+
@Inject
496+
@Any
497+
InjectableInstance<Foo> foos;
498+
499+
for (Foo foo : foos.listActive())
500+
...
501+
}
502+
----
503+
489504
[[synthetic_observers]]
490505
== Use Case - Synthetic Observers
491506

_versions/main/guides/websockets-next-reference.adoc

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,40 @@ class MyBean {
640640
There are also other convenient methods.
641641
For example, `OpenConnections#findByEndpointId(String)` makes it easy to find connections for a specific endpoint.
642642

643+
==== User data
644+
645+
It is also possible to associate arbitrary user data with a specific connection.
646+
The `io.quarkus.websockets.next.UserData` object obtained by the `WebSocketConnection#userData()` method represents mutable user data associated with a connection.
647+
648+
[source, java]
649+
----
650+
import io.quarkus.websockets.next.WebSocketConnection;
651+
import io.quarkus.websockets.next.UserData.TypedKey;
652+
653+
@WebSocket(path = "/endpoint/{username}")
654+
class MyEndpoint {
655+
656+
@Inject
657+
CoolService service;
658+
659+
@OnOpen
660+
void open(WebSocketConnection connection) {
661+
connection.userData().put(TypedKey.forBoolean("isCool"), service.isCool(connection.pathParam("username"))); <1>
662+
}
663+
664+
@OnTextMessage
665+
String process(String message) {
666+
if (connection.userData().get(TypedKey.forBoolean("isCool"))) { <2>
667+
return "Cool message processed!";
668+
} else {
669+
return "Message processed!";
670+
}
671+
}
672+
}
673+
----
674+
<1> `CoolService#isCool()` returns `Boolean` that is associated with the current connection.
675+
<2> The `TypedKey.forBoolean("isCool")` is the key used to obtain the data stored when the connection was created.
676+
643677
[[server-cdi-events]]
644678
==== CDI events
645679

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

1034+
==== User data
1035+
1036+
It is also possible to associate arbitrary user data with a specific connection.
1037+
The `io.quarkus.websockets.next.UserData` object obtained by the `WebSocketClientConnection#userData()` method represents mutable user data associated with a connection.
1038+
1039+
[source, java]
1040+
----
1041+
import io.quarkus.websockets.next.WebSocketClientConnection;
1042+
import io.quarkus.websockets.next.UserData.TypedKey;
1043+
1044+
@WebSocketClient(path = "/endpoint/{username}")
1045+
class MyEndpoint {
1046+
1047+
@Inject
1048+
CoolService service;
1049+
1050+
@OnOpen
1051+
void open(WebSocketClientConnection connection) {
1052+
connection.userData().put(TypedKey.forBoolean("isCool"), service.isCool(connection.pathParam("username"))); <1>
1053+
}
1054+
1055+
@OnTextMessage
1056+
String process(String message) {
1057+
if (connection.userData().get(TypedKey.forBoolean("isCool"))) { <2>
1058+
return "Cool message processed!";
1059+
} else {
1060+
return "Message processed!";
1061+
}
1062+
}
1063+
}
1064+
----
1065+
<1> `CoolService#isCool()` returns `Boolean` that is associated with the current connection.
1066+
<2> The `TypedKey.forBoolean("isCool")` is the key used to obtain the data stored when the connection was created.
1067+
1068+
10001069
[[client-cdi-events]]
10011070
==== CDI events
10021071

0 commit comments

Comments
 (0)