Return-Path: X-Original-To: apmail-felix-dev-archive@www.apache.org Delivered-To: apmail-felix-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 0FF4317D2C for ; Mon, 20 Apr 2015 08:16:04 +0000 (UTC) Received: (qmail 80797 invoked by uid 500); 20 Apr 2015 08:15:58 -0000 Delivered-To: apmail-felix-dev-archive@felix.apache.org Received: (qmail 80721 invoked by uid 500); 20 Apr 2015 08:15:58 -0000 Mailing-List: contact dev-help@felix.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@felix.apache.org Delivered-To: mailing list dev@felix.apache.org Received: (qmail 80709 invoked by uid 99); 20 Apr 2015 08:15:58 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 20 Apr 2015 08:15:58 +0000 Date: Mon, 20 Apr 2015 08:15:58 +0000 (UTC) From: "Carlos Sierra (JIRA)" To: dev@felix.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Commented] (FELIX-4853) Create a new ServiceDependency that sets the TCCL to the incoming servicereference bundle's classloader before invoking callbaks MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/FELIX-4853?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14502494#comment-14502494 ] Carlos Sierra commented on FELIX-4853: -------------------------------------- Hey Pierre, first of all thanks again for your great explanations and help. I had already explored what you proposed above, and the main problem I found was that I needed to "tie" the bind implementation of the Activator (in your example) to the final one in the "real" callback POJO. So in the event that I need to have N callback methods in my component instance I need to create N callback wrappers or, otherwise, recreate the reflection logic to call the appropriate method in the final addressee of the callback. I found it much simpler just to extend ServiceDependencyImpl to wrap the callback invocation with the incoming service's classloader. Actually my use case is already covered thanks to the flexibility of Dependency Manager just creating a new Dependency type derived from the current ServiceDependencyImpl. My main concern here was that the OSGi bundle does not export the ServiceDependencyImpl package. I simply thought that this might have been something useful for more people and might have been interesting to be included with DM, but as you say, it might be very specific and very easy to solve by other means. Again, thanks for all your help. Carlos. > 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, examples2.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)