Jump to: navigation, search

Gemini/Naming/Documentation/JNDI Providers

JNDI Providers

A JNDI Provider, in the context of Gemini Naming, is usually an OSGi bundle that publishes JNDI-related services to be consumed by JNDI clients.

The simplest example of a JNDI provider is an implementation of the "javax.naming.spi.InitialContextFactory" interface. In JNDI, the InitialContextFactory is a factory for JNDI Context instances, which in turn can be used to retrieve objects from the naming service. Objects can also be added to the naming service using the "javax.naming.Context" interface.

Creating a JNDI provider to use with Gemini Naming requires the following steps:

  1. Create an OSGi bundle with an Activator.
  2. In the Activator, register the JNDI Provider implementation as an OSGi service, according to the rules in the JNDI Services Chapter of the OSGi Enterprise Specification, v4.2.

The following code snippet demonstrates the simplest way to publish a JNDI Provider to the OSGi Service Registry:

    InitialContextFactory initialContextFactory = new TestContextFactory(testContext);
    String[] interfaceNames ={ InitialContextFactory.class.getName(),
    // register context factory
    ServiceRegistration serviceRegistration = 
        bundleContext.registerService(interfaceNames, initialContextFactory, null);

While the example above demonstrates how to register the JNDI Provider with the OSGi BundleContext API, it should be noted that this is only one way to register the provider. There are other OSGi frameworks that exist to simplify the process of registering OSGi Services (Declarative Services, Blueprint, Spring-DM). JNDI Providers are free to use these frameworks to publish JNDI services, as long as the framework publishes the OSGi service according to the rules in the JNDI Services Specification.