Return-Path: X-Original-To: apmail-cayenne-dev-archive@www.apache.org Delivered-To: apmail-cayenne-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 980ACE06C for ; Sun, 3 Mar 2013 09:23:40 +0000 (UTC) Received: (qmail 27250 invoked by uid 500); 3 Mar 2013 09:23:40 -0000 Delivered-To: apmail-cayenne-dev-archive@cayenne.apache.org Received: (qmail 27052 invoked by uid 500); 3 Mar 2013 09:23:37 -0000 Mailing-List: contact dev-help@cayenne.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cayenne.apache.org Delivered-To: mailing list dev@cayenne.apache.org Received: (qmail 27037 invoked by uid 99); 3 Mar 2013 09:23:37 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 03 Mar 2013 09:23:37 +0000 X-ASF-Spam-Status: No, hits=-0.0 required=5.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [208.78.103.231] (HELO vorsha.objectstyle.org) (208.78.103.231) by apache.org (qpsmtpd/0.29) with SMTP; Sun, 03 Mar 2013 09:23:32 +0000 Received: (qmail 8551 invoked from network); 3 Mar 2013 09:23:23 -0000 Received: from unknown (HELO ?127.0.0.1?) (127.0.0.1) by localhost with SMTP; 3 Mar 2013 09:23:23 -0000 Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Mac OS X Mail 6.2 \(1499\)) Subject: Re: Cayenne under OSGi From: Andrus Adamchik In-Reply-To: Date: Sun, 3 Mar 2013 12:23:11 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <2BDC562B-6FD6-419B-9B3E-97DACAF2913D@objectstyle.org> References: <0A0BB47A-A807-457C-AEFA-728921233080@objectstyle.org> <9ADF74BE-C219-4664-87E3-7BC7C73C2AB8@objectstyle.org> To: dev@cayenne.apache.org X-Mailer: Apple Mail (2.1499) X-Virus-Checked: Checked by ClamAV on apache.org Ok, I think understand the task in general, but some details still do = not fully connect in my head. I guess I need to dive into OSGi and to = tie all the loose ends in Cayenne class loading. E.g. it would be nice = to avoid registering each class manually, and just pass the right = ClassLoader somehow, preferably via DI instead of a static method. Your = code and this discussion certainly make it much easier.=20 Also something I haven't explored yet is this separate dependencies = bundle.=20 As usual, the toughest part is finding time to do this work. And I'll be = certainly happy if someone with OSGi experience takes it over. Will be = happy to apply the patches :) But otherwise, I'll put it in my Cayenne = queue. Thanks, Andrus On Mar 1, 2013, at 11:53 AM, Cristiano Ghersi = wrote: > Hi Andrus, >=20 > you perfectly caught the point: the difference is in the class = loading. > The class loaders are populated from the application that uses = Cayenne, > with the following example snippet: >=20 > ServerRuntime myRuntime =3D new ServerRuntime("myDomain.xml"); > ... > ClassRegistry.registerClass(MyPersistentClass1.class); > ClassRegistry.registerClass(MyPersistentClass2.class); > //call ClassRegistry.registerClass(Class) for each class created by > CayenneModeler >=20 > you can find ClassRegistry class in org.apache.cayenne.di.spi package; = it > is the other brick added by ourselves in order to correctly run under = OSGi >=20 > Let me know if you need any further information! >=20 > Thanks > Cristiano >=20 > 2013/2/28 Andrus Adamchik >=20 >> Hi Cristiano, >>=20 >> So I guess our goal is to tweak the Cayenne build process (and code = if >> needed) so that it builds OSGI-compatible jars. >>=20 >> Let's start with the code=85 I created a diff to better demonstrate = the >> change in DefaultAdhocObjectFactory between Cayenne and your code: >>=20 >> +import java.util.List; >> + >> import org.apache.cayenne.CayenneRuntimeException; >> import org.apache.cayenne.di.AdhocObjectFactory; >> import org.apache.cayenne.di.Inject; >> @@ -102,6 +104,16 @@ >> return Class.forName(className, true, classLoader); >> } >> catch (ClassNotFoundException e) { >> + //try with the class loader registry >> + List registeredClassLoaders =3D >> ClassLoaderRegistry.registeredClassLoaders(); >> + for (ClassLoader loader : = registeredClassLoaders) { >> + try { >> + return = loader.loadClass(className); >> + } >> + catch (ClassNotFoundException cnfe) { >> + } >> + } >> + >> if (!className.endsWith("[]")) { >> if ("byte".equals(className)) { >> return Byte.TYPE; >>=20 >>=20 >> I guess this is what you described in the previous message (only = slightly >> different naming - ClassLoaderRegistry). I couldn't find who actually >> populates those extra class loaders inside ClassLoaderRegistry? Could = you >> comment on this please? >>=20 >> So other than that, I guess all we need is changing cayenne-server >> packaging from "jar" to "bundle" (and configuring the bundle plugin = in the >> pom). >>=20 >> Andrus >>=20 >>=20 >>=20 >> On Feb 28, 2013, at 12:19 PM, Cristiano Ghersi < >> cristiano.ghersi@abodata.com> wrote: >>> Hi Andrus, >>>=20 >>> I know you have been very busy with the new upcoming release of = Cayenne. >>>=20 >>> I'd like to know if and when we can resume the task of Cayenne >>> OSGi-fication. >>>=20 >>> I'm at your disposal for every clarification. >>>=20 >>> Thank you very much >>> Best >>> Cristiano >>=20 >>=20 >>=20