You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Chetan Mehrotra <ch...@gmail.com> on 2012/09/06 12:31:19 UTC

Improving Jackrabbit integration within OSGi and other managed environment

<<Reposting the mail to dev DL as per Michael Duerig's suggestion>>

While using jackrabbit in managed environment like Sling, Spring etc
its easy for other components to access the Repository service.
However its tricky to use managed components of those env within
Jackrabbit as it creates the instances on its own. To simplify such
integration it would be helpful if JR exposes a factory service which
is used to create the various beans from the JR configuration.

To achieve that I have done a small poc which introduces a BeanFactory
service and uses that within BeanConfig to create the class instances.
The relevant changes are available at Git fork [1] and changes done
can be seen at [2]. To demonstrate the use of such a feature I took
the usecase of externalizing the AuthorizableAction [3] in Sling env.
So it should be possible to use an OSGi service which implements the
AuthorizableAction within JR. An implementation of that is available
at [4].

Usage
======

Any JR component which needs to be provided via external service would
need to have a factoryType attribute set. The class would be set to
the interface name of the service

<AuthorizableAction
class="org.apache.jackrabbit.core.security.user.action.AuthorizableAction"
factoryType="osgi"/>

Then in Sling side we provide an OsgiBeanFactory which is passed to JR
through ConfigurationParser. This factory would internally lookup the
service and provide it to JR. It can also ensure that Repository
service is restarted if the service is not available or through proxy
it can handle the dynamic nature of OSGi.

An improved implementation can make use of BeanConfigVisitor interface
to determine the services which are required from OSGi and can ensure
that it only starts the repository after all the required services are
present. It can use the Felix Dependency manager [5] to achieve that.
Further in static env like Spring the implementation of BeanFactory
would be much simpler as it does not have to worry about services
going away at runtime.

Would such a feature be useful to be part of JR Core. Thoughts?

Chetan Mehrotra

[1] https://github.com/chetanmeh/jackrabbit/tree/osgi-factory
[2] https://github.com/chetanmeh/jackrabbit/compare/osgi-factory
[3] http://jackrabbit.apache.org/api/2.4/org/apache/jackrabbit/core/security/user/action/AuthorizableAction.html
[4] https://github.com/chetanmeh/sling/compare/osgi-factory
[5] https://felix.apache.org/site/apache-felix-dependency-manager-getting-started.html

Re: Improving Jackrabbit integration within OSGi and other managed environment

Posted by Michael Dürig <md...@apache.org>.
Hi Chetan,

This seems very useful to me. I created 
https://issues.apache.org/jira/browse/JCR-3420 for the Jackrabbit part 
of this. Could you attach the relevant changes as patch to the issue?

Michael

On 6.9.12 11:31, Chetan Mehrotra wrote:
> <<Reposting the mail to dev DL as per Michael Duerig's suggestion>>
>
> While using jackrabbit in managed environment like Sling, Spring etc
> its easy for other components to access the Repository service.
> However its tricky to use managed components of those env within
> Jackrabbit as it creates the instances on its own. To simplify such
> integration it would be helpful if JR exposes a factory service which
> is used to create the various beans from the JR configuration.
>
> To achieve that I have done a small poc which introduces a BeanFactory
> service and uses that within BeanConfig to create the class instances.
> The relevant changes are available at Git fork [1] and changes done
> can be seen at [2]. To demonstrate the use of such a feature I took
> the usecase of externalizing the AuthorizableAction [3] in Sling env.
> So it should be possible to use an OSGi service which implements the
> AuthorizableAction within JR. An implementation of that is available
> at [4].
>
> Usage
> ======
>
> Any JR component which needs to be provided via external service would
> need to have a factoryType attribute set. The class would be set to
> the interface name of the service
>
> <AuthorizableAction
> class="org.apache.jackrabbit.core.security.user.action.AuthorizableAction"
> factoryType="osgi"/>
>
> Then in Sling side we provide an OsgiBeanFactory which is passed to JR
> through ConfigurationParser. This factory would internally lookup the
> service and provide it to JR. It can also ensure that Repository
> service is restarted if the service is not available or through proxy
> it can handle the dynamic nature of OSGi.
>
> An improved implementation can make use of BeanConfigVisitor interface
> to determine the services which are required from OSGi and can ensure
> that it only starts the repository after all the required services are
> present. It can use the Felix Dependency manager [5] to achieve that.
> Further in static env like Spring the implementation of BeanFactory
> would be much simpler as it does not have to worry about services
> going away at runtime.
>
> Would such a feature be useful to be part of JR Core. Thoughts?
>
> Chetan Mehrotra
>
> [1] https://github.com/chetanmeh/jackrabbit/tree/osgi-factory
> [2] https://github.com/chetanmeh/jackrabbit/compare/osgi-factory
> [3] http://jackrabbit.apache.org/api/2.4/org/apache/jackrabbit/core/security/user/action/AuthorizableAction.html
> [4] https://github.com/chetanmeh/sling/compare/osgi-factory
> [5] https://felix.apache.org/site/apache-felix-dependency-manager-getting-started.html
>