Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jakartabatch-dev] Overview of Jakarta Batch 2.1 + CDI integration details

Hi Scott, some comments inline

Romain Manni-Bucau
@rmannibucau |  Blog | Old BlogGithub | LinkedIn | Book


Le jeu. 7 oct. 2021 à 15:55, Scott Kurz <skurz@xxxxxxxxxx> a écrit :

Since Batch + CDI integration overlaps a bunch of issues in our 2.1 milestone:  https://github.com/eclipse-ee4j/batch-api/milestone/1 ) let me level set with a thread here.

My take is that we specify a set of details like this:

1. Batch implementation required to perform CDI injection into batch artifacts  (https://github.com/eclipse-ee4j/batch-api/issues/46)

The Batch implementation MUST be able to load batch artifacts and inject CDI-managed beans (i.e. have the CDI engine inject them, however we'd state it), with or without the presence of BDA on the batch artifacts (i.e. without the batch artifacts needing to be themselves loaded as CDI managed beans), unless CDI is disabled altogether,  (e.g. bean discovery mode = none),

This loading with CDI bean injection MUST occur for any of the spec-mentioned artifact loading techniques (i.e. mapping from JSL @ref values):  a) CDI bean name(*)  b)   batch.xml entry  c) FQCN     (*) - IIRC, we would need to spec the bean name syntax

By default, with BDA=annotated, batch artifacts will not be managed as CDI beans.  


Not sure what you meant but annotated will still create cdi beans (as Bean<?>) so it will be compatible, bda=none will ignore the jar so think we should stick to "what is a cdi bean can be a batch component" which also includes producers btw, no?
 



This will be backed by a statement in the platform spec too (https://github.com/eclipse-ee4j/jakartaee-platform/issues/420),

2.  Instance scope for batch artifacts - CDI bean / non-bean

When a batch artifact is loaded but NOT as a CDI-managed bean, the batch implementation MUST ensure artifact instances are scoped to a single JSL reference.   This means, for one, that different methods within a given listener will use the same instance for a given step (e.g. StepListener beforeStep/afterStep).  

When a batch artifact is loaded as a CDI-managed bean there should be one instance request (TBD: figure out the correct wording) to the BeanManager for each JSL reference.    (This ensures again that using a bean with @Dependent-scoped, the default, doesn't result in different instances across e.g. beforeStep/afterStep).   However, since the BeanManager is control of instance scope it may not be one instance per JSL reference; e.g. using @ApplicationScoped for a batch artifact could result in one instance per application.


What about letting the user decide but encourage @Dependent? There are valid cases for @AppScoped (when reusing the same bean and storing the state elsewhere like a request scope bean or jobcontext.
 



3. Inject JobOperator - (straightforward:  https://github.com/eclipse-ee4j/batch-api/issues/17)

4. The Batch implementation MAY provide custom, proprietary techniques for disabling CDI

Strictly speaking there's probably no need to explicitly state this but it does provide continuity speaking to our legacy of trying to define a generic, non/pre-CDI specified behavior.  


A jakarta.batch.cdi.enabled=false can be neat in properties for portability.
 



5. (A miscellaneous  consequence worth mentioning) - Don't rely on field initializers  https://github.com/eclipse-ee4j/batch-api/issues/73   
Since the CDI engine may be in control of @BatchProperty injection, field initializers can not be relied upon to provide a default value in the absence of a corresponding JSL property, and so should be considered a non-best practice (since CDI is a better practice).

I think these artifacts already exist so it's too late to try to ban them.   But we should say something in the spec, since the question has come up.  Perhaps an implementation would want to issue a warning.

Think we can say that we register a generic batch property producer with dependent scope so any injection must comply with it. We can also  mention it is only valid during bean lookup (before it is used) and not after clarifying the behavior for normal scope proxies and expliciting the risk for not dependent beans.



6. Batch defined custom scope

Still on the table:  Job/Step-scoped ((https://github.com/eclipse-ee4j/batch-api/issues/79)    One issue to clarify is whether we should offer both the "thread local" behavior of JobContext/StepContext and non-thread-affinity scope variants, and what exactly to name them, etc.
(Not sure if we need to specify when standard CDI scope lifecycle event callbacks are made relative to parts of the batch lifecycle or not)

7. Injection of one Batch artifact into another  https://github.com/eclipse-ee4j/batch-api/issues/171

I think we've effectivley covered this now.  Item 2.,  above describes instance creation from the batch container artifact loading, and so at this point we can just say "normal CDI rules apply".  And of course item 6. elaborates on those rules.
---

I think that's it.   Did I miss anything?   Appreciate your comments/feedback.
------------------------------------------------------
Scott Kurz
WebSphere / Open Liberty Batch and Developer Experience
skurz@xxxxxxxxxx
--------------------------------------------------------


_______________________________________________
jakartabatch-dev mailing list
jakartabatch-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jakartabatch-dev

Back to the top