-
Notifications
You must be signed in to change notification settings - Fork 43
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
Provide an API to ContainerProvider to allow ServiceLoader results to be filtered / prioritised / sorted #365
Comments
How would that be used? Also, last time I looked into it, |
with static getter/setter for I'm open to alternative solutions that allow the user to control which implementation is used when multiple implementations are available. |
+1 for priorities, -1 for using |
Wouldn't this be easier with a @jansupol The Jakarta EE 10 minimum JDK has been brought up a few times in the various mailing lists. I believe that those groups wanting to stick with JDK 8 will have to stay with older Jakarta EE revisions. |
For the record, I'm -1 for priorities in the websocket API itself, and would rather see that be something a user of the API implements on top of the API if they desire it. Alternative 2 - how about using a Predicate instead? Either as a ContainerProvider singleton behavior change for all users of void ContainerProvider.setImplementationPredicate(Predicate<Class<? extends WebSocketContainer>> predicate) Or as a per-call version (this could be baked into the spec provided ContainerProvider interface) ... WebSocketContainer ContainerProvider.getWebSocketContainer(Predicate<Class<? extends WebSocketContainer>> predicate) The per-call version could benefit from having a default predicate that just returns the first hit (like it currently does). |
I think it would be useful to get @rmannibucau 's view on this since the requirement originated with TomEE. |
I agree, more details would be useful to frame the discussion further. From the limited information so far, it seems that for WebSocket Client usage there are situations where there are multiple implementations present on the classloader. But that brings up other questions ...
|
Hi everyone, I think it is either @priority (if available) or useless (if you know which container you want you do new MyContainer(), no?).
This would make it close to all EE providers loading logic and not custom to a single spec. Side note: indeed spec impl can cache the provider to use per classloader for perf. |
The use of I should be able to do something like ... ServerContainer serverBasedClient = (ServerContainer) servletContext.getAttribute("jakarata.websocket.server.ServerContainer");
configure(serverBasedClient);
ContainerProvider.setImplementation(serverBasedClient); or FooWebSocketClient client = new FooWebSocketClient();
configure(client);
ContainerProvider.setImplementation(client); That way, I know that all users of the Where does the Also, where would the I have a different view of this requirement. The far more useful approach ...
Priority is not a factor in these use cases. |
@joakime you move the problem because as soon as you will expose
Indeed if you prefer to add Why is it important to make it in the spec? Because if you don't you basically should deprecate Why So to summarize: it is key to not delegate the selection responsability to the caller - or if decided, ContainerProvider#getWebSocketContainer must be deprecated but it has some real value and it should be kept IMHO. I'm not sure I see how your proposal helps since "specific implementation" is what ContainerProvider should resolve and caller code will just call So the issue is really the entry point is a static method (to embrace the standalone case) and it does not let "contributors" to do this selection logic in an encapsulated fashion - this is where priority notion helps a lot. The only solution todo is to wrapp all edit: @markt-asf staying on java 8 is fine since the new API can be replaced by multiple options (the simplest being to let them all be instantiated - obvious if using priority method option and no more the annotation option - or reimplement the read of these files as before java 6, not crazy is j8 is a big constraint - I can hear that. |
@rmannibucau this is great detail, thank you. Lots to noodle through here. I just am cautious about making the API even messier than it already is. Example: If I could start from scratch, there would be no streaming support (only partial messages), there would be no encoders or decoders, tracking all sessions would be dropped, there would be a simpler API than the Configurators as defined, client would be more configurable for common scenarios (SSL/TLS, proxy, auth, cookies, etc), CDI would have been involved from the get go to properly delineate the websocket scopes, customized server upgrades would be easier, and proper extension support (both custom extensions, configuring existing extensions, and ability to participate in extension resolution). But we have to work with what we have.
I'm a bit surprised by this statement, as we (Eclipse Jetty) haven't been able to run without the annotation jar if those annotations are present anywhere in any runtime accessible class (nod to JEP238) on the container or webapp classpaths (for Jetty 9.x). The JPMS layer introduced in Jetty 10 and Jetty 11 also makes this statement extra surprising as that layer pitches a fit if you attempt to load a class with annotations that are not declared in your module-info.java as |
@joakime requirement can be made optional (requires static) and java spec requires only available runtime annotations to be loaded in java.lang reflect. Give it a try in a small main:
|
I don't understand the concept of an annotated priority? Surely implementor
will just set it to Integer.MAX_VALUE to encourage usage of their
implementation!
…On Wed, 28 Apr 2021, 06:08 Romain Manni-Bucau, ***@***.***> wrote:
@joakime <https://github.com/joakime> requirement can be made optional
(requires static) and java spec requires only available runtime annotations
to be loaded in java.lang reflect. Give it a try in a small main:
@foo public class Bar {}
public class Main {
public static void main(String.... a) {
System.out.println(List.of(Bar.class.getAnnotations()));
}
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#365 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAARJLMQ2MJ2FDBNJL7FJ2TTK4KURANCNFSM43TNFBBA>
.
|
@gregw maybe end users but containers and libraries will not to enable users to override it, it is what happens in practise otherwise users report it as a bug. Now happy to get another working solution too but as of today only a sorting works and priority is the most trivial and common solution AFAIK. |
The I'll note that it should be possible to solve the TomEE use case simply by not including the Tomcat WebSocket implementation as it is packaged in a separate JAR for both the standard and embedded distributions. I wrote various iterations of my analysis of various scenarios but it comes down to containers/users need a way to control the result of My current thinking is that a new
|
This will require a minimum of Java 9. Then we can use
ServiceLoader.stream()
and filter / sort the results. I'm leaning towards sort rather than filter.The text was updated successfully, but these errors were encountered: