Chapter 4. JNDI Naming Server

Table of Contents

4.1. Overview
4.2. Basic Concepts and Structure
4.2.1. Basic Concepts
4.2.2. Checking Bound Objects
4.2.3. JNDI Naming Server Architecture
4.2.4. JNDI Clustering
4.3. Configuring JNDI Naming Server
4.3.1. Configuring JNSServer
4.3.2. Configuring JNSClient
4.4. JNDI in Clustered Environment
4.4.1. Lookup
4.5. JNDI Programming
4.5.1. Configuring JEUS Environment
4.5.2. Configuring InitialContext Properties
4.5.3. Looking up Named Objects Using the Context
4.5.4. Using a Named Object
4.5.5. Closing a Context
4.5.6. Creating a Clustered Context
4.5.7. Remote Lookup

This chapter describes basic concepts and terminologies of JEUS JNDI. It also describes how to set the environment configuration and develop applications.

Java Naming and Directory Interface™ (JNDI) is a standard API used by Java applications to find and get an object in the network by using the logical name of the object. From the user perspective, it provides an environment where applications can find an use objects more easily than in the previous enterprise environment.

JEUS JNDI is compatible with JNDI 1.2 API and supports Sun Microsystem's JNDI API standards. It also provides JNDI Service Provider Interface(SPI) for compatibility with the enterprise environment. This means that any product that implements JNDI SPI can use the objects of JEUS JNDI Tree.

The JEUS JNDI service is used through out JEUS system and can be seen whenever the EJB, servlet/JSP, JMS, and JDBC are used.

JEUS JNDI has a unique architecture that binds and looks up objects. This section will first describe the basic concepts and structure of JEUS JNDI.

This section describes the operation of the JNDI Tree structure.

The JNDI Tree consists of JNSServers and JNSClients. A JNSServer is on the JVM of the MS, and a JNSClient is on the JVM of an MS or a client. As the main element of the JEUS JNDI architecture, the JNS server creates and manages the JNDI Tree. A JNSClient resides below the JNS Server and is managed by the JNSServer.

The following shows the relationship between a JNSServer and JNSClients.


To access the entire JNDI Tree, a JNSClient must send a request to the JNSServer.

A JNSServer is connected to other JNSServers on other MSs to form a cluster. A JNS client interacts with a JNSServer on an MS and handles client access requests. The client does not directly access the JNSServer, but instead binds and looks up objects through a JNSClient.

JNSServer

A JNSServer manages the JNDI Tree. It is an independent naming server that allows a JNSClient to access the JNDI Tree. Multiple JNSServers can be connected to expand the JNDI Tree. This is because a JNSServer can be directly connected to other JNSServers on other MSs. In JEUS, after an MS starts, the JNSServer automatically waits for JNSClient access requests.

JNSClient

The basic function of a JNSClient is to send application requests to a JNSServer and return the result from the JNSServer. On each JVM, there is one JNSClient singleton instance per server. Since only one JNSClient is used to lookup an object, it can be used effectively with an EJB or a servlet in the enterprise environment.

The following is a list of important JNSClient features.

  • Accessing a JNDI Tree

    Provides a way to access the JNDI Tree that is managed by the MS accessing the JNSServer. The objects that are bound and looked up can be shared by the entire JNDI Tree or only by specific clients depending on the client configuration.

  • Caching looked up objects

    A JNSClient caches frequently used objects for faster access. A JNSClient caches the objects while communicating with a JNSServer.

  • Managing JNSServer connections

    A JNSClient receives a request from a client and sends it to JNSServer and returns the result from the server. Since a JNS client is on the JVM where the client exists, communication can be made efficiently without incurring additional IOs.

The following table describes the two types of JNS clients distinguished by where the JNSServer is.

JNSClientDescription
Server-side

Used by EJB Beans, servlets, and JSPs on each engine of the MS.

To use a server-side JNSClient, configure the java.naming.factory.initial property as jeus.jndi.JNSContextFactory. This value is usually configured when the MS starts, and it does not need to be configured separately.

Client-side JNSClient

Used by applets, applications, and clients that are not running on the MS.

To use a client-side JNSClient, configure the java.naming.factory.initial property as jeus.jndi.JNSContextFactory.

A Client-side JNSClient manages resources efficiently by closing any connections that are idle for a specified time period and reconnecting if necessary. The applications running in the client container do not need to configure this value since it is set as a system property when the client container starts.

The JNDI tree consists of connections between a JNSServer and JNSClients. This structure allows a JNS Client to let other JNSClients know about modified objects and supports multiple MSs (clustering).

In other words, individual JNDIs form an extensive JNDI tree through clustering. When there are any modified objects in a JNDI Tree, the changes are propagated to other JNDIs. Therefore, in the JNDI Naming clustered environment, objects bound to a naming server can be looked up from other naming servers.

For example, as shown in the following figure, a cluster environment is composed of four types of MSs (A,B,C,D). If an object called obj1 on MS A is bound as objName1, then this object is sent to all the other MSs (B,C,D). As a result, objName1 can also be looked up on MS B, C, and D to obtain obj1.

Not all bound objects can be replicated to other MSs in the cluster. Only the objects bound to the cluster can be replicated. For example, objects like data sources that are configured to a specific MS can only be bound to the JNSServer of each MS.


Each MS is responsible for managing each JNSServer. Each JNSServer starts when JEUS system starts and is connected to JNSServers on other MSs. When each JEUS engine gets an InitialContext object, a JNSClient connects to the JNSServer. When a client looks up a JNDI tree object, the request is sent to the JNSClient and then to the JNSServer on the MS. As a result, the client obtains the requested object.

Remote Lookup in a Clustered Environment

Without a separate configuration, JNDI Lookup executes in the JEUS/JNDI cluster that it belongs to. Objects on a JNDI server of an MS that is not in the cluster can be looked up by creating a context by specifying the PROVIDER URL (refer toJEUS Reference Book. "1.4. JNDI System Properties") or by using the name that uses the jh(JEUS host) protocol created in JEUS. For more information, refer to "4.5. JNDI Programming".

JNS Server Replication

Each JNSServer of JEUS is connected to other servers and waiting to interact with them. When a new MS joins an existing cluster, its JNSServer sends a notification to other connected JNSServers. Each JNSServer also sends its data to the new JNS server so that the existing bound objects can be looked up on the new JNS server.

Owing to such scalability, a JNS server that is restarted due to an error can continue to operate normally by receiving the JNDI Tree information from the other JNSServers.

A JNDI naming server consists of a JNSServer and a JNSClient, each with different configurations.

A JNSServer needs configurations to accept JNSClient connection requests and access other JNSServers. A JNSClient needs configurations to access the JNSServer and modify the JNDI tree.

This section describes how to configure the JNSServer and JNSClient.

Select [Servers] from the left menu of WebAdmin to go to the server list screen.

Select a server from the list to go to the server configuration screen. Select [Naming Server] to go to the JNSServer configuration screen.

The following is the naming server configuration screen.


Configuring a Common Thread Pool

A thread pool that is shared on the server can be configured in WebAdmin or the console tool. For basic information about thread pools, refer to "2.3.3. Thread Pool Configuration".

  • Using WebAdmin

    The following is the common thread pool configuration screen in WebAdmin. Check the Pooling checkbox and select the Shared button, and then configure the common thread pool and click [OK].


  • Using the console tool

    A common thread pool can be configured using the console tool.

    [DAS]domain1.adminServer>modify-system-thread-pool adminServer -service namingse
    rver -r 10
    Successfully performed the MODIFY operation for The namingserver thread pool of
    the server (adminServer)., but all changes were non-dynamic. They will be applie
    d after restarting.
    Check the results using "show-system-thread-pool adminServer -service namingserv
    er or modify-system-thread-pool adminServer -service namingserver"
    
    [DAS]domain1.adminServer>modify-system-thread-pool adminServer -service namingse
    rver
    show the current configuration.
    The namingserver thread pool of the server (adminServer) 
    ================================================================================
    +----------------------------------------------------------------------+-------+
    | Reserved Threads for the Service namingserver                        | 10    |
    +----------------------------------------------------------------------+-------+
    ================================================================================

Configuring service thread pool

Configure the service thread pool in WebAdmin or the console tool.

  • Using the console tool

    The service thread pool can also be configured using the console tool.

    [DAS]domain1.adminServer>modify-service-thread-pool server1 -service namingserver -min 0 -max 20
    Successfully performed the MODIFY operation for The namingserver thread pool of
    the server (server1)., but all changes were non-dynamic. They will be applied af
    ter restarting.
    Check the results using "show-service-thread-pool server1 -service namingserver
    or modify-service-thread-pool server1 -service namingserver"
    
    [DAS]domain1.adminServer>modify-service-thread-pool server1 -service namingserver
    Shows the current configuration.
    The namingserver thread pool of the server (server1). 
    ===================================================================
    +-------------------------------------------------------+---------+
    | Min                                                   | 0       |
    | Max                                                   | 20      |
    | Keep-Alive Time                                       | 60000   |
    | Queue Size                                            | 4096    |
    | Max Stuck Thread Time                                 | 3600000 |
    | Action On Stuck Thread                                | NONE    |
    | Stuck Thread Check Period                             | 300000  |
    +-------------------------------------------------------+---------+
    ===================================================================
    

Note

Since the thread pool configuration can be changed dynamically, the server does not need to be restarted. However, the server must be restarted in order to change from a common thread pool to a dedicated thread pool.

When a clustered environment is configured for the MSs, each JNSServer becomes automatically clustered. Refer to JEUS Domain Guide. "Chapter 5. JEUS Clustering" about how to cluster MSs.

By default, a JNSClient connects to a local JNSServer.

The JNSClient recognizes the address of the MS's JNSServer as Context.PROVIDER_URL. Each MS address in the cluster must be added to Context.PROVIDER_URL as in the following.

JNSClients perform load balancing and failover by using the provided Context.PROVIDER_URL value.

Hashtable ht = new Hashtable();
ht.put(Context.PROVIDER_URL, "host1:9736,host2:9736"); //host1 and host2 participate in the cluster

When an MS that is assigned to Context.PROVIDER_URL fails, the JNSClient detects the failure when it tries to execute the JNSServer's JNDI operation on the failed MS and performs failover to another JNSServer. The JNSClient regularly checks the failed MS to see if it is in the RUNNING state. This configuration can be set by using the '-Djeus.jndi.cluster.recheckto' option (Default value:5, Unit:min).

If a JNSClient runs on an MS managed by the Domain Admin Server (DAS), use the cluster name that was configured on DAS as in the following.

Hashtable ht = new Hashtable();
ht.put(Context.PROVIDER_URL, "jeus://cluster1"); //cluster1 is the cluster name configured on DAS

By using the cluster name, the latest status information of the MS can always be obtained from DAS to configure the cluster regardless of the "jeus.jndi.cluster.recheckto" setting on the JNSClient.

In other words, if an MS in the cluster is in a FAILED state or a new MS is added, the server is updated before performing JNDI operation on the JNSClient.

Therefore, it is recommended to use the cluster name when the JNSClient is running on an MS that is managed by DAS.

This section describes how to use JEUS JNDI for programming.

Java clients can access a JNDI Tree by using the InitialContext object. The InitialContext object uses the Standard JNDI standard properties and JEUS properties.

First, configure the JNDI environment, and then look up objects by using the InitialContext. Next, get the object reference. Finally, close the InitialContext after use.

The following are the steps used by a Java client to use the JEUS JNDI.

  1. Configure the JEUS environment.

  2. Configure properties for the InitialContext.

  3. Use the context to look up the named object.

  4. Use the named object to get the object reference.

  5. Close the context.

The following is a detailed description of each step.

Java clients configure environment properties for the InitialContext before using JEUS JNDI services.

There are two configuration methods.

  • Using the '-D' option of the JVM.

  • Creating a hash table and sending it to the InitialContext constructor.

Using the '-D' option of the JVM is more preferable than creating a hash table.

The following are the properties that must be configured to create the InitialContext of JEUS JNDI.

  • Context.INITIAL_CONTEXT_FACTORY (required)

  • Context.URL_PKG_PREFIXES

  • Context.PROVIDER_URL

  • Context.SECURITY_PRINCIPAL

  • Context.SECURITY_CREDENTIALS

Add these properties to the hash table and use them to create an InitialContext. Use the default InitialContext if the InitialContext is only used in the objects on the server (EJBs, servlets or JSPs).

The following are the client program configurations.

Context ctx = null;
Hashtable ht = new Hashtable();
ht.put(Context.INITIAL_CONTEXT_FACTORY, "jeus.jndi.JNSContextFactory”);
ht.put(Context.URL_PKG_PREFIXES, “jeus.jndi.jns.url”);
ht.put(Context.PROVIDER_URL, “<hostname>”);
ht.put(Context.SECURITY_PRINCIPAL, “<username>”);
ht.put(Context.SECURITY_CREDENTIALS, “<password>”);

try {
    ctx = new InitialContext(ht);
    // use the context
} catch (NamingException ne) {
    // fail to get an InitialContext
} finally {
    try{
        ctx.close();
    catch (Exception e) {
        // an error occurred
    }
}

When JNDI is used in a cluster environment, additional environment properties for jeus.jndi.JNSContext can be used to create a JNDI Tree and effectively manage the internal operations of a JNSClient.

  • Creating a context using the hash table

    To configure an environment property of the InitialContext, the property name is assigned to a hash table (java.util.Hashtable) key and the property data is assigned to the hash table (java.util.Hashtable) value. The key value pair is passed to the InitialContext constructor as a parameter.

  • Creating a Security Context

    Multiple security-related environment properties can be used to allow a user of the JEUS security domain to access an execution thread. When the InitialContext is created, the following properties are configured for the Security Context.

    • User name property: java.naming.security.principal

    • Password property: java.naming.security.credentials

After a successful authentication, the authenticated user information is configured for an execution thread, and the user can access the resources that are managed by the JEUS Security Manager. If the authentication fails, the thread recognizes the user as a guest user.

Even when the Security Context is configured, the context is ignored when the JEUS security API is used to log on before the InitialContext is created. In this case, the already logged on subject is used for JNDI communication.

Note

1. Refer to "JEUS Security guide" for more information about configuring the user information and JEUS security service.

2. Refer to JEUS Reference Book. "1.4. JNDI System Properties" for more information about the InitialContext properties and environment properties.