Coming in Karaf 3.0.0: new enterprise JNDI feature
In previous Karaf version (2.x), the JNDI support was “basic”.
We just leveraged Aries JNDI to support the osgi:service JNDI scheme to reference the OSGi services using JNDI name.
However, we didn’t provide a fully functionnal JNDI initial context, nor any tooling around JNDI.
In part of the new enterprise features coming with Karaf 3.0.0, the JNDI support is now more “complete”.
Add JNDI support
As most of the other enterprise features, the JNDI feature is an optional one. It means that you have to install the jndi
feature first:
karaf@root()> feature:install jndi
The jndi
feature installs several parts.
Ready to use initial context
Like in previous version, Karaf provides a fully compliant implementation of the OSGi Alliance JNDI Service Specification. This specification details how to advertise InitialContextFactory and ObjectFactories in an OSGi environment. It also defines how to obtain services from services registry via JNDI.
Now, it’s possible to use directly the JNDI initial context. Karaf now provides a fully functionnal initial context where you can lookup both the osgi:service
scheme or a regular JNDI name.
You can do:
Context context = new InitialContext();MyBean myBean = (MyBean) context.lookup("my/bean/name");
You can use the osgi:service
scheme to access to the OSGi service registry using JNDI:
Context context = new InitialContext();MyBean myBean = (MyBean) context.lookup("osgi:service/mybean");
JNDI Service, Commands and MBean
Karaf 3.0.0 provides a OSGi service dedicated to JNDI.
The interface of this JNDI service is org.apache.karaf.jndi.JndiService
and it’s registered when installing the jndi
feature.
You can manipulate the JNDI service using shell commands.
You can list the JNDI name using jndi:names
:
karaf@root()> jndi:namesJNDI Name | Class Name ------------------------------------------------------------------osgi:service/jndi | org.apache.karaf.jndi.internal.JndiServiceImpl
You can create a new JNDI name using anoher one (a kind of alias) using the jndi:alias
command:
karaf@root()> jndi:alias osgi:service/jndi local/service/jndikaraf@root()> jndi:namesJNDI Name | Class Name -------------------------------------------------------------------osgi:service/jndi | org.apache.karaf.jndi.internal.JndiServiceImpllocal/service/jndi | org.apache.karaf.jndi.internal.JndiServiceImpl
For instance, here, we bind a name from the “special” osgi:service
scheme as a “regular” JNDI name.
You can directly bind a OSGi service (identifiy by its service.id
) with a JNDI name:
karaf@root()> jndi:bind 344 local/service/karkaraf@root()> jndi:namesJNDI Name | Class Name ------------------------------------------------------------------local/service/kar | org.apache.karaf.kar.internal.KarServiceImpl osgi:service/jndi | org.apache.karaf.jndi.internal.JndiServiceImpl
You can alias the local/service/kar
name with directly service/kar
:
karaf@root()> jndi:alias local/service/kar service/karkaraf@root()> jndi:namesJNDI Name | Class Name ------------------------------------------------------------------local/service/kar | org.apache.karaf.kar.internal.KarServiceImpl service/kar | org.apache.karaf.kar.internal.KarServiceImpl osgi:service/jndi | org.apache.karaf.jndi.internal.JndiServiceImpl
You can unbind the service/kar
name:
karaf@root()> jndi:unbind service/karkaraf@root()> jndi:namesJNDI Name | Class Name ------------------------------------------------------------------local/service/kar | org.apache.karaf.kar.internal.KarServiceImpl osgi:service/jndi | org.apache.karaf.jndi.internal.JndiServiceImpl
You can get all JNDI names, and manipulate the JNDI service using a new JMX JNDI MBean. The object name to use is org.apache.karaf:type=jndi,name=*
.
Conclusion
One of our purpose for Karaf 3.0.0 is to provide more services, commands, MBeans to move Karaf as a more complete full enterprise OSGi container.
If we already provide a bunch of features, a lot are not really “visible” to the end users due to some “missing” commands or MBeans.
It’s a key point for Karaf 3.x releases.
Comments
Post a Comment