felix-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Carlos Sierra (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (FELIX-4853) Create a new ServiceDependency that sets the TCCL to the incoming servicereference bundle's classloader before invoking callbaks
Date Fri, 17 Apr 2015 10:24:58 GMT

    [ https://issues.apache.org/jira/browse/FELIX-4853?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14499590#comment-14499590

Carlos Sierra commented on FELIX-4853:

Hi again Pierre, 

I think I understand what you explained before but I believe my use case is different. I will
try to explain the differences I see.

I don't need the invocations to the service to be wrapped by the TCCL in this case, which
would be solved with the solution you proposed, what I really need is the callback instance
invocation to be wrapped by the TCCL. In my case I am registering the service in the callback
instance in CXF. CXF does a lot of introspection on the incoming service, and tries to load
resources from the TCCL. But it is not the service invoking CXF, it is the POJO I use as callback
instance. So at this point the options I saw was:

· Use ServiceReference<T> in several of my POJO's callback method parameters, which
binds my POJO to OSGi, thus losing one of the benefits of using DM
· Extend ServiceDependencyImpl and create a new dependency that does this for every callback
invocation so I don't need to "taint" my POJO's methods

Maybe I am doing something fundamentally wrong. What are your thoughts?

Thanks again in advance!

> Create a new ServiceDependency that sets the TCCL to the incoming servicereference bundle's
classloader before invoking callbaks
> --------------------------------------------------------------------------------------------------------------------------------
>                 Key: FELIX-4853
>                 URL: https://issues.apache.org/jira/browse/FELIX-4853
>             Project: Felix
>          Issue Type: New Feature
>          Components: Dependency Manager
>    Affects Versions: dependencymanager-3.2.0
>            Reporter: Carlos Sierra
> The invoke method would go like this:
> {code:title=TCCLServiceDependencyImpl.java|borderStyle=solid}
>         @Override
> 	@SuppressWarnings("rawtypes")
> 	public void invoke(
> 		Object[] callbackInstances, DependencyService dependencyService,
>                 ServiceReference reference, Object service, String name) {
> 		Bundle bundle = reference.getBundle();
> 		BundleWiring bundleWiring = bundle.adapt(BundleWiring.class);
> 		ClassLoader bundleClassLoader = bundleWiring.getClassLoader();
> 		Thread currentThread = Thread.currentThread();
> 		ClassLoader contextClassLoader = currentThread.getContextClassLoader();
> 		currentThread.setContextClassLoader(bundleClassLoader);
> 		try {
> 			super.invoke(
> 				callbackInstances, dependencyService, reference, service, name);
> 		}
> 		finally {
> 			currentThread.setContextClassLoader(contextClassLoader);
> 		}
> 	}
> {code}
> If you think this is useful I can provide a patch. Which version and which repo should
I use for it?

This message was sent by Atlassian JIRA

View raw message