You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@felix.apache.org by "Pierre De Rop (JIRA)" <ji...@apache.org> on 2015/04/17 23:31:00 UTC

[jira] [Updated] (FELIX-4853) Create a new ServiceDependency that sets the TCCL to the incoming servicereference bundle's classloader before invoking callbaks

     [ https://issues.apache.org/jira/browse/FELIX-4853?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Pierre De Rop updated FELIX-4853:
---------------------------------
    Attachment: examples.tgz

Attached the bndtools examples.
With Eclipse Luna, install a JRE 1.8 (make it the default JRE);
then open bndtools perspective, and import the attached project.


> 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
>         Attachments: examples.tgz
>
>
> 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
(v6.3.4#6332)