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

Provide well-defined behavior / ordering / etc. in case where ServiceLoader finds >1 JobOperator impl. #193

Open
scottkurz opened this issue Jan 13, 2022 · 4 comments

Comments

@scottkurz
Copy link
Contributor

In the BatchRuntime.java implementation we now simply return the first JobOperator found (see here).

We could do something like failing fast if we find >1.

Other ideas?

@rmannibucau
Copy link

We could also add to JobOperator a default int priority() {return 1000;} and sort them. Implementations must use 1000 but users could wrap any operator and use something higher to force the selection. If multiple higher priority operators are there we fail else we pick it.

A side note is that if the job operator is in a CDI application, we must pick the CDI beans since we enable the operator to be decorated/intercepted so maybe we should also try CDI first - and in CDI a single bean can match so we would be good by design (= if it is ambiguous, user would already have done the job to pick the right one in CDI).

Just throwing ideas, not yet sure which one is good or not. Think I still think the fail fast is the best compromise.

@radcortez
Copy link

I believe it would be useful to have a way to control which implementation is selected. Priority seems the best way to do it (and already used in other places across the platform).

@rmannibucau
Copy link

rmannibucau commented Jan 14, 2022

(still thinking out loud) but actually all spec which can be selected - ie where it is not contextual as CDI EE, Servlet, JNDI or EJB can be - have a provider method in the lookup entrypoint so it means it is more about adding BatchRuntime.getJoboperator(String provider) than anything else probably (using as ref bval, cdi se, jsonb, jsonp, jpa but others have alternate mecanism like JAXRS, JSF, ...).

note that the standard lookup strategy is also to

  1. if explicit in parameters use it
  2. check a spec system property
  3. (optional) check a lib/<file>.properties
  4. use service discovery (loader these days)

@scottkurz
Copy link
Contributor Author

Just want to reiterate that this is NOT currently planned for 2.1. (See the 2.1 / EE 10 milestone: https://github.com/eclipse-ee4j/batch-api/milestone/1)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants