cayenne-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrus Adamchik <and...@objectstyle.org>
Subject Re: Cayenne under OSGi
Date Sun, 03 Mar 2013 09:23:11 GMT
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
View raw message