[
https://issues.apache.org/jira/browse/OWB-931?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13895511#comment-13895511
]
Moritz Bechler commented on OWB-931:
------------------------------------
Mark: This is not about loading the proxy class, the proxy class should never
be loaded anywhere except by the proxy factory right after defining it. One
part is about where to define this class as defined classes can never be
unloaded until the defining classloader is gargabe collected.
I totally agree that the default behaviour must be to define in the bean class
classloader as otherwise this will break package protected access.
Let me explain a bit further about the environment I have here:
* a WAB context bootstrapped in OSGI
* in this context a CDI context is bootstrapped on start, shutdown when the
webapp is unloaded
* A MetaDataScanner which allows me to import bean classes from other bundles
(this is the tricky, nonstandard part)
So for the first problem let us drop the TCCL for a second, my brain was too
much in WAB mode. In more abstract terms, to prevent leaks, the proxies must be
defined in a classloader which eventually will be gargabe collected after the
CDI context has been shutdown. In normal scenarios this isn't a issue as the
bean classes will be loaded by some classloader which is child of some
application classloader which is bound to this lifecycle. In the WAB scenario
this is the webapp classloader which should be the TCCL. With enterprise
application bundles (If I understand correctly a CDI context is started for
each bundle) this should be the bundle classloader. In custom scenarios we
simply don't know.
So, maybe, we can just make the classloader selection customizable?
Regarding the scope provider: You mention the bean class - the proxy factory
does not load the bean class. Having a bundle containing random bean classes
import OWB implementation specifics looks very wrong to me. Let's again drop
the TCCL and call it "some classloader which sees OWB extensions". This is a
very common problem in OSGI and imho there is no perfect solution for it. One
way to do it is to make the extensions fragment of the core implementation and
use the core classloader. Again, I already would be very happy if there was a
way to override this.
regards
Moritz
> NormalScopeProxyFactory classloader usage
> -----------------------------------------
>
> Key: OWB-931
> URL: https://issues.apache.org/jira/browse/OWB-931
> Project: OpenWebBeans
> Issue Type: Brainstorming
> Components: Core
> Affects Versions: 1.2.0
> Reporter: Moritz Bechler
> Labels: ClassLoader, OSGI
>
> createNormalScopeProxy currently uses the bean class ClassLoader for two
> purposes:
> 1. defining the proxy class
> 2. instantiation of the instance provider.
> In our OSGI/WAB environment this usage does not make much sense:
> 1. the proxy class should be defined in the classloader which most closely
> reflects the CDI context lifecycle, which is the web context TCCL.
> 2. causes trouble with scope providers (e.g OWB's own
> RequestScopedBeanInterceptorHandler) when they are defined in another bundle.
> I don't think there is a proper compatible solution to this (except maybe
> making extensions fragments) but also trying the TCCL makes this much more
> painless to use.
> Is there any explanation for this particular choice of classloaders? Are
> there any reasons not to try TCCL first?
--
This message was sent by Atlassian JIRA
(v6.1.5#6160)