FAQ
So thanks to Cristiano pinging me offline, I spent some time on reviewing this again. I think we need to take the following steps to integrate Abodata’s OSGi code (or follow it as a pattern when we write ours) :

1. Reorg Cayenne Maven structure, making cayenne-server and cayenne-client real Maven modules instead of aggregates. We’ve discussed this a few times, and IIRC I was the only one who opposed it :) I no longer do. We can use <optional> and “provided” dependencies to exclude the extras like JGroups and keep it clean.

2. We need to add OSGi metadata to cayenne-server (and other Cayenne jars in the chain… likely just cayenne-di).

3. We need to create OsgiServerModule with an overridden AdhocObjectFactory. This will implement refactored ClassRegistry and will load all model classes per this example: http://www.snip2code.com/Snippet/12313/Apache-Cayenne--correctly-load-classes-u

4. We may (or may not?) put those few OSGi classes in a separate cayenne-server-osgi module (to avoid dependency on OSGi framework in the base cayenne-server).

I placed #1 in my work stack (and really hope something else doesn’t pop up that pushes it down :-/ ) I don’t think Cristiano can create sensible patches against trunk without it. After this is done, we can discuss whether me or Cristiano can do 2..4.

Andrus
On Jan 31, 2013, at 3:42 PM, Cristiano Ghersi wrote:
Good morning,

My company (Abodata, www.abodata.com) has ported Cayenne into OSGi
environment, and we would like to contribute to Cayenne project with this
enhancement as I posted under user mailing list on October 2012.

Following your instructions, we have uploaded the full content under the
github repo:
https://github.com/cristianoghersi/CayenneOSGi

Basically, we have packaged the source code of 3.1 version into an OSGi
bundle called cayenne-osgi, adding some stuff to manage the particular
classloading features of OSGi.
Then we added also another bundle, called Cayenne-3.1-Dependencies, that
packages all the required dependencies.

I'm at complete disposal for every clarification you need.

I'll wait for your feedback.

Best
cghersi

Search Discussions

  • Andrus Adamchik at Nov 14, 2013 at 3:23 pm

    On Nov 14, 2013, at 5:56 PM, Andrus Adamchik wrote:

    1. Reorg Cayenne Maven structure, making cayenne-server and cayenne-client real Maven modules instead of aggregates. We’ve discussed this a few times, and IIRC I was the only one who opposed it :) I no longer do. We can use <optional> and “provided” dependencies to exclude the extras like JGroups and keep it clean.
    Oh and if anyone thinks this is controversial for any reason, please comment.

    A.
  • Andrus Adamchik at Nov 18, 2013 at 7:34 pm

    So I finally started on the actual OSGi task. Here is what we have:

    1. Reorg Cayenne Maven structure, making cayenne-server and cayenne-client real Maven modules instead of aggregates. We’ve discussed this a few times, and IIRC I was the only one who opposed it :) I no longer do. We can use <optional> and “provided” dependencies to exclude the extras like JGroups and keep it clean.
    This was done on Sunday.
    2. We need to add OSGi metadata to cayenne-server (and other Cayenne jars in the chain… likely just cayenne-di).
    Just committed configs needed to turn cayenne-di.jar and cayenne-server.jar into proper OSGi bundles. I used the default configuration of maven-bundle-plugin, so every single Cayenne package is exported in the bundle. In the future we may be more specific. cayenne-di.jar has no dependencies. cayenne-server.jar has a bunch of optional dependencies, and 4 required ones:

    cayenne-di
    commons-collections
    commons-logging
    velocity

    Also to generate a proper OSGi version (3.2.0.M2-SNAPSHOT) I had to add a dot to our Maven versioning scheme, so the trunk is now called 3.2.M2-SNAPSHOT. Which was probably the right thing to do anyways.
    3. We need to create OsgiServerModule with an overridden AdhocObjectFactory. This will implement refactored ClassRegistry and will load all model classes per this example: http://www.snip2code.com/Snippet/12313/Apache-Cayenne--correctly-load-classes-u
    4. We may (or may not?) put those few OSGi classes in a separate cayenne-server-osgi module (to avoid dependency on OSGi framework in the base cayenne-server).
    Still TODO.

    Andrus


    On Nov 14, 2013, at 5:56 PM, Andrus Adamchik wrote:

    So thanks to Cristiano pinging me offline, I spent some time on reviewing this again. I think we need to take the following steps to integrate Abodata’s OSGi code (or follow it as a pattern when we write ours) :

    1. Reorg Cayenne Maven structure, making cayenne-server and cayenne-client real Maven modules instead of aggregates. We’ve discussed this a few times, and IIRC I was the only one who opposed it :) I no longer do. We can use <optional> and “provided” dependencies to exclude the extras like JGroups and keep it clean.

    2. We need to add OSGi metadata to cayenne-server (and other Cayenne jars in the chain… likely just cayenne-di).

    3. We need to create OsgiServerModule with an overridden AdhocObjectFactory. This will implement refactored ClassRegistry and will load all model classes per this example: http://www.snip2code.com/Snippet/12313/Apache-Cayenne--correctly-load-classes-u

    4. We may (or may not?) put those few OSGi classes in a separate cayenne-server-osgi module (to avoid dependency on OSGi framework in the base cayenne-server).

    I placed #1 in my work stack (and really hope something else doesn’t pop up that pushes it down :-/ ) I don’t think Cristiano can create sensible patches against trunk without it. After this is done, we can discuss whether me or Cristiano can do 2..4.

    Andrus
    On Jan 31, 2013, at 3:42 PM, Cristiano Ghersi wrote:
    Good morning,

    My company (Abodata, www.abodata.com) has ported Cayenne into OSGi
    environment, and we would like to contribute to Cayenne project with this
    enhancement as I posted under user mailing list on October 2012.

    Following your instructions, we have uploaded the full content under the
    github repo:
    https://github.com/cristianoghersi/CayenneOSGi

    Basically, we have packaged the source code of 3.1 version into an OSGi
    bundle called cayenne-osgi, adding some stuff to manage the particular
    classloading features of OSGi.
    Then we added also another bundle, called Cayenne-3.1-Dependencies, that
    packages all the required dependencies.

    I'm at complete disposal for every clarification you need.

    I'll wait for your feedback.

    Best
    cghersi
  • Andrus Adamchik at Nov 20, 2013 at 6:57 pm
    After today’s round of changes (CAY-1886), I am able to start Cayenne bundles in an OSGi container (Felix). Here are the prerequisites (shown as “install” commands inside the Felix container). As you see we can’t use some of the direct dependencies of Cayenne, specifically commons-logging and velocity, in an OSGi container. However there are suitable replacements out there:

    install file:/Users/cayenne/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
    install file:/Users/cayenne/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.5/jcl-over-slf4j-1.7.5.jar
    install file:/Users/cayenne/.m2/repository/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar
    install file:/Users/cayenne/.m2/repository/org/slf4j/slf4j-simple/1.7.5/slf4j-simple-1.7.5.jar
    install file:/Users/cayenne/.m2/repository//org/apache/servicemix/bundles/org.apache.servicemix.bundles.velocity/1.7_6/org.apache.servicemix.bundles.velocity-1.7_6.jar
    install file:/Users/cayenne/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar

    ... now finally install 2 Cayenne bundles ...

    install file:/Users/cayenne/work/cayenne/cayenne-di/target/cayenne-di-3.2.M2-SNAPSHOT.jar
    install file:/Users/cayenne/work/cayenne/cayenne-server/target/cayenne-server-3.2.M2-SNAPSHOT.jar

    after that cayenne-server can be started, and I end up with the following container state:

    g! lb
    START LEVEL 1
        ID|State |Level|Name
         0|Active | 0|System Bundle (4.2.1)
         1|Active | 1|Apache Felix Bundle Repository (1.6.6)
         2|Active | 1|Apache Felix Gogo Command (0.12.0)
         3|Active | 1|Apache Felix Gogo Runtime (0.10.0)
         4|Active | 1|Apache Felix Gogo Shell (0.10.0)
        16|Resolved | 1|Commons Collections (3.2.1)
        23|Resolved | 1|jcl-over-slf4j (1.7.5)
        24|Resolved | 1|slf4j-api (1.7.5)
        25|Resolved | 1|slf4j-simple (1.7.5)
        27|Resolved | 1|Cayenne Dependency Injection Container (3.2.0.M2-SNAPSHOT)
        31|Resolved | 1|Apache ServiceMix :: Bundles :: velocity (1.7.0.6)
        32|Active | 1|Cayenne Server (3.2.0.M2-SNAPSHOT)
        35|Resolved | 1|Commons Lang (2.4.0)

    Next step is to write a bundle that uses Cayenne and see what we need to do with the ClassLoader.

    A.
  • Cristiano Ghersi at Nov 21, 2013 at 9:07 am
    Hi All,

    Great job Andrus!!

    For the next step you were talking about, I think we can use this example:
    http://www.snip2code.com/Snippet/12372/Use-Apache-Cayenne-under-OSGi-environmen
    where you can see an example of a bundle activator.

    Hope this can help in the following steps...

    Bye
    cghersi


    2013/11/20 Andrus Adamchik <andrus@objectstyle.org>
    After today’s round of changes (CAY-1886), I am able to start Cayenne
    bundles in an OSGi container (Felix). Here are the prerequisites (shown as
    “install” commands inside the Felix container). As you see we can’t use
    some of the direct dependencies of Cayenne, specifically commons-logging
    and velocity, in an OSGi container. However there are suitable replacements
    out there:

    install
    file:/Users/cayenne/.m2/repository/commons-collections/commons-collections/3.2.1/commons-collections-3.2.1.jar
    install
    file:/Users/cayenne/.m2/repository/org/slf4j/jcl-over-slf4j/1.7.5/jcl-over-slf4j-1.7.5.jar
    install
    file:/Users/cayenne/.m2/repository/org/slf4j/slf4j-api/1.7.5/slf4j-api-1.7.5.jar
    install
    file:/Users/cayenne/.m2/repository/org/slf4j/slf4j-simple/1.7.5/slf4j-simple-1.7.5.jar
    install
    file:/Users/cayenne/.m2/repository//org/apache/servicemix/bundles/org.apache.servicemix.bundles.velocity/1.7_6/org.apache.servicemix.bundles.velocity-1.7_6.jar
    install
    file:/Users/cayenne/.m2/repository/commons-lang/commons-lang/2.4/commons-lang-2.4.jar

    ... now finally install 2 Cayenne bundles ...

    install
    file:/Users/cayenne/work/cayenne/cayenne-di/target/cayenne-di-3.2.M2-SNAPSHOT.jar
    install
    file:/Users/cayenne/work/cayenne/cayenne-server/target/cayenne-server-3.2.M2-SNAPSHOT.jar

    after that cayenne-server can be started, and I end up with the following
    container state:

    g! lb
    START LEVEL 1
    ID|State |Level|Name
    0|Active | 0|System Bundle (4.2.1)
    1|Active | 1|Apache Felix Bundle Repository (1.6.6)
    2|Active | 1|Apache Felix Gogo Command (0.12.0)
    3|Active | 1|Apache Felix Gogo Runtime (0.10.0)
    4|Active | 1|Apache Felix Gogo Shell (0.10.0)
    16|Resolved | 1|Commons Collections (3.2.1)
    23|Resolved | 1|jcl-over-slf4j (1.7.5)
    24|Resolved | 1|slf4j-api (1.7.5)
    25|Resolved | 1|slf4j-simple (1.7.5)
    27|Resolved | 1|Cayenne Dependency Injection Container
    (3.2.0.M2-SNAPSHOT)
    31|Resolved | 1|Apache ServiceMix :: Bundles :: velocity (1.7.0.6)
    32|Active | 1|Cayenne Server (3.2.0.M2-SNAPSHOT)
    35|Resolved | 1|Commons Lang (2.4.0)

    Next step is to write a bundle that uses Cayenne and see what we need to
    do with the ClassLoader.

    A.

  • Andrus Adamchik at Nov 24, 2013 at 4:16 pm
    So this is done. Cristiano, appreciate if you could try it in your environment. An example of how to use Cayenne with OSGi is available on GitHub [1]. Here is how you bootstrap it in your own module:

       Module osgiModule = OsgiModuleBuilder.forProject(Activator.class).withDriver(Driver.class).module();
       return new ServerRuntime("cayenne-osgi-example.xml", osgiModule);

    As you see, no need to enumerate your classes. Also I suspect instead of binding the driver, in a real OSGi environment Cayenne stack will need to refer to some OSGi service that encapsulates the DataSource. We can provide integrations for that too. And don’t forget to stop it when you your bundle is stopped, as you don’t want to keep Cayenne threads and other resources hanging around, eventually killing your container:

       cayenneRuntime.shutdown();

    Cheers,
    Andrus


    [1] https://github.com/andrus/cayenne-osgi-example
  • Cristiano Ghersi at Nov 25, 2013 at 3:49 pm
    Hi Andrus, great job!

    I have to say that we always used it under Equinox implementation, so
    perhaps in Felix seems to be simpler.

    Just two notes on our experience under OSGi that may help to overcome
    eventual problems of class/resource loading.
    1) OSGi load of resources like xml config file: this sometimes is tricky
    under OSGi. We solved our problems creating another bundle as a fragment
    host of cayenne-osgi bundle, where we place the **.map.xml, the
    cayenne-MyDomain.xml and (optionally) the dbcp.properties (as we use
    org.apache.commons.dbcp for pooled connections).
    2) Class loading: if your bundle expose some methods to interact with DB,
    the lazy load of the classes inside OSGi environment may bring you some
    headache, as you cannot be sure on the order of class loading among the
    different bundles (this is why we provided the ClassRegistry and force the
    load of such classes in the start() of the bundle: to be sure that such
    classes are correctly loaded from the correct bundle when we want!). This
    strange behavior was discovered after one year that we were using Cayenne
    under OSGi! So, perhaps, the fact that now with the test bundle Andrus
    provided everything seems working can be misleading. But I cannot prove my
    sentence as this is a bug very difficult to reproduce.

    So, at the end, the implementation of Andrus seems effective and works well
    for me, but the test of someone else may give us more feeling about the
    resolution of the issue.

    Bye
    cghersi


    2013/11/24 Andrus Adamchik <andrus@objectstyle.org>
    So this is done. Cristiano, appreciate if you could try it in your
    environment. An example of how to use Cayenne with OSGi is available on
    GitHub [1]. Here is how you bootstrap it in your own module:

    Module osgiModule =
    OsgiModuleBuilder.forProject(Activator.class).withDriver(Driver.class).module();
    return new ServerRuntime("cayenne-osgi-example.xml", osgiModule);

    As you see, no need to enumerate your classes. Also I suspect instead of
    binding the driver, in a real OSGi environment Cayenne stack will need to
    refer to some OSGi service that encapsulates the DataSource. We can provide
    integrations for that too. And don’t forget to stop it when you your bundle
    is stopped, as you don’t want to keep Cayenne threads and other resources
    hanging around, eventually killing your container:

    cayenneRuntime.shutdown();

    Cheers,
    Andrus


    [1] https://github.com/andrus/cayenne-osgi-example

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupdev @
categoriescayenne
postedNov 14, '13 at 2:56p
activeNov 25, '13 at 3:49p
posts7
users2
websitecayenne.apache.org

People

Translate

site design / logo © 2022 Grokbase