Skip to content

Conversation

yrodiere
Copy link
Member

@yrodiere yrodiere commented Dec 20, 2017

@sebersole Here are the fixes I mentioned yesterday regarding the ManagedBeanRegistry. Mainly this is about making sure that, when shouldRegistryManageLifecycle is false, the registry really doesn't manage the CDI lifecycle at all and delegates to the CDI runtime.

All of the commits in this PR are follow-ups to already-fixed tickets:

WARNING: I had to use CDI 2.0 APIs, and those APIs are not available in WildFly 11. So I added a build step to patch the WildFly server.

@yrodiere yrodiere force-pushed the bean_registry_cdi_lifecycle_fixes branch from 1d4fb72 to f0f1c8f Compare December 20, 2017 17:11
@yrodiere yrodiere changed the title [PREVIEW] ManagedBeanRegistry CDI lifecycle fixes ManagedBeanRegistry CDI lifecycle fixes Dec 20, 2017
@yrodiere yrodiere requested a review from sebersole December 20, 2017 17:14
@yrodiere
Copy link
Member Author

@sebersole Following @Sanne's advice, I managed to avoid the switch to WildFly 12. This PR now targets WildFly 11, with only a patch file applied to the server to upgrade Weld to a version supporting CDI 2.0.

Copy link
Member

@sebersole sebersole left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall these seem like some very complicated changes. I'm going to have to sit down and look through them

* even if there is already an instance in the CDI context.
* This means singletons are not really singletons, but this seems to be the behavior required by
* the JPA 2.2 spec.
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But see, this is not true. For a given class we only ever generate one ManagedBean instance = they are singletons (unless of course they are used again in a non-JPA context). Notice the caching of them initially in a Map keyed by class...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unless of course they are used again in a non-JPA context

My point exactly. They are singleton in the JPA context only, not in the CDI context overall. I can rephrase the comment to clarify that if you like.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, even in the JPA context, such "not-actually-singleton" beans will be instantiated once per ServiceRegistry, which unless I'm mistaken means once per SessionFactory/persistence unit. So even from the JPA point of view, they cannot always be viewed as singletons.

@yrodiere yrodiere force-pushed the bean_registry_cdi_lifecycle_fixes branch 2 times, most recently from ede1255 to 65bc115 Compare January 5, 2018 16:21
@yrodiere
Copy link
Member Author

yrodiere commented Jan 5, 2018

Now working on tests as discussed; I couldn't finish today, but I'll probably be able to push something on Monday.

@yrodiere yrodiere force-pushed the bean_registry_cdi_lifecycle_fixes branch 2 times, most recently from cf51133 to 3b600f5 Compare January 8, 2018 14:03
@yrodiere
Copy link
Member Author

yrodiere commented Jan 8, 2018

Added non-regression tests as requested.

@yrodiere yrodiere force-pushed the bean_registry_cdi_lifecycle_fixes branch from 3b600f5 to a4dfcc8 Compare January 10, 2018 16:22
@sebersole sebersole self-assigned this Jan 12, 2018
@sebersole
Copy link
Member

@yrodiere Just because it is easier to ask than to see it in the PR.... you are using CDI 2.0's SE bootstrap now, right? Instead of using WildFly?

@yrodiere
Copy link
Member Author

@sebersole Yes. I did exactly what you did in your own tests.

@sebersole
Copy link
Member

sebersole commented Jan 12, 2018 via email

@yrodiere
Copy link
Member Author

Is that just for completeness?

It is. If anything relies on CDI in your WildFly ITs, without this patch the IT will probably fail.

If you don't think you'll ever use CDI in your WildFly ITs, then yes you can skip this commit. I can remove it if you want.

@sebersole
Copy link
Member

sebersole commented Jan 12, 2018 via email

This commit should not change the current behavior, it is only about
moving code to separate classes to make the following changes clearer.
…epending on the 'shouldRegistryManageLifecycle' parameter

The registry should not manage the bean lifecycle when
'shouldRegistryManageLifecycle' is false. The easiest way to do so is to
use BeanManager.createInstance to retrieve beans in the Standard CDI lifecycle
strategy: it correctly retrieves singletons from the CDI context instead
of instantiating them again.

Also, fix javax.enterprise.inject.spi.Bean-based instance destructions:
we used to only request destruction to the creational context, which is
wrong because it may skip the execution of @PostDestroy methods in
particular.
…n when possible

This should take care of @Alternative in particular.
@yrodiere yrodiere force-pushed the bean_registry_cdi_lifecycle_fixes branch from a4dfcc8 to 3f67a2d Compare January 12, 2018 14:46
@yrodiere
Copy link
Member Author

I can just remove that as I integrate your PR locally. Or you can if you
really want to :)

I rebased on master and removed the commit.

@sebersole
Copy link
Member

sebersole commented Jan 12, 2018 via email

@sebersole
Copy link
Member

@yrodiere I did some work on top of this as discussed and pushed upstream in prep for tomorrow's Beta1 release. It's just a Beta, so if you find anything we need to change its not a big deal - we'll get it into the next one

@sebersole sebersole closed this Jan 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants