-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
WebSockets Next: make it possible to store user data in a connection #43787
Conversation
mkouba
commented
Oct 9, 2024
- resolves websocket-next api - missing user properties map #43772
54d9914
to
6b36a91
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🙈 The PR is closed and the preview is expired. |
This comment has been minimized.
This comment has been minimized.
/** | ||
* @param <TYPE> The type this key is used for. | ||
*/ | ||
record TypedKey<TYPE>(String value) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You don't really need the string key. The object identity of the key is itself good enough.
This
static class Key<T> {
}
is all you need.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really. This way you would need to use the object reference as a key. Always. That's not what we want/need. A string-based key is IMO more practical.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, you're risking collisions, so the string keys will have to be namespaced... Not a fan. But your choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is for user data. I don't expect collisions there. Anyway, we risk collisions pretty much everywhere when it comes to MP Config and application properties 🤷.
*/ | ||
record TypedKey<TYPE>(String value) { | ||
|
||
public static TypedKey<Integer> forInt(String val) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't it be an int
here?
public static TypedKey<Integer> forInt(String val) { | |
public static TypedKey<Integer> forInt(int val) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and then return new TypedKey<>(String.valueOf(val));
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The value is actually the key
. I should rename the param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In other words, this factory method is used to create a typed key with the specified string value. I.e. you expect the value to be integer, but the key is still string-based.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we hide this implementation detail by providing extra put
/get
/remove
methods in the UserData
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's actually not an implementation detail. We want the users to use the typed key in order to use generics to verify the type of the value in put()
and to cast the value automatically when obtaining the value with get()
. We could add getString()
and putString()
etc. but I don't think it would make the API more clear or useful. Also we would have to keep the generic way so that it could be used for "custom" types, similar to https://github.com/quarkusio/quarkus/pull/43787/files#diff-a63047e6c7bf732258f9858dcb9cb5303fa5ebe9756eb27cc970a4130190bdc3R62.
Status for workflow
|
Status for workflow
|