cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cristiano Ghersi <cristiano.ghe...@gmail.com>
Subject Re: Cayenne under OSGi
Date Mon, 04 Mar 2013 10:35:19 GMT
Hi Andrus
We need to be very careful in osgi environment in class loading issues.
Every bundle has its own classloader and this is why we need to register
the class loader explicitly from the bundle that effectively uses Cayenne.
Regarding the dependencies, it is far more manageable to use a separate
bundle for them, to collect the osgi-friendly version of them...
Let me know if you need further clarification
Thanks
Cghersi
Il giorno 03/mar/2013 10:23, "Andrus Adamchik" <andrus@objectstyle.org> ha
scritto:

> 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.
>
> Also something I haven't explored yet is this separate dependencies bundle.
>
> 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 <
> cristiano.ghersi@abodata.com> wrote:
>
> > Hi Andrus,
> >
> > 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:
> >
> > ServerRuntime myRuntime = new ServerRuntime("myDomain.xml");
> > ...
> > ClassRegistry.registerClass(MyPersistentClass1.class);
> > ClassRegistry.registerClass(MyPersistentClass2.class);
> > //call ClassRegistry.registerClass(Class) for each class created by
> > CayenneModeler
> >
> > 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
> >
> > Let me know if you need any further information!
> >
> > Thanks
> > Cristiano
> >
> > 2013/2/28 Andrus Adamchik <andrus@objectstyle.org>
> >
> >> Hi Cristiano,
> >>
> >> So I guess our goal is to tweak the Cayenne build process (and code if
> >> needed) so that it builds OSGI-compatible jars.
> >>
> >> Let's start with the codeā€¦ I created a diff to better demonstrate the
> >> change in DefaultAdhocObjectFactory between Cayenne and your code:
> >>
> >> +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<ClassLoader> registeredClassLoaders =
> >> ClassLoaderRegistry.registeredClassLoaders();
> >> +                       for (ClassLoader loader :
> registeredClassLoaders) {
> >> +                               try {
> >> +                                       return
> loader.loadClass(className);
> >> +                               }
> >> +                               catch (ClassNotFoundException cnfe) {
> >> +                               }
> >> +                       }
> >> +
> >>             if (!className.endsWith("[]")) {
> >>                 if ("byte".equals(className)) {
> >>                     return Byte.TYPE;
> >>
> >>
> >> 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?
> >>
> >> 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).
> >>
> >> Andrus
> >>
> >>
> >>
> >> On Feb 28, 2013, at 12:19 PM, Cristiano Ghersi <
> >> cristiano.ghersi@abodata.com> wrote:
> >>> Hi Andrus,
> >>>
> >>> I know you have been very busy with the new upcoming release of
> Cayenne.
> >>>
> >>> I'd like to know if and when we can resume the task of Cayenne
> >>> OSGi-fication.
> >>>
> >>> I'm at your disposal for every clarification.
> >>>
> >>> Thank you very much
> >>> Best
> >>> Cristiano
> >>
> >>
> >>
>
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message