Java Dynamic Management Kit 5.1 Tutorial

10.4.3 Running the JNDI/LDAP Lookup Service Example

In addition to the actions you performed in 10.1 Initial Configuration, before you can run the lookup service examples that use the JNDI/LDAP lookup service, you must perform some further initial actions that are specific to this example. You can then start looking up connectors using the JNDI/LDAP network technology.

When you run the examples, to help you keep track of which agent has been created with which connector and transport, the agent names include a letter suffix. For example, the agent from the example of an RMI connector over JRMP, without an external directory is called test-server-a.

To Set up the JNDI/LDAP Lookup Service Example

The following steps are required by all of the different connector/transport combinations you can run in this example.

  1. Stop the LDAP server you started in 10.1 Initial Configuration.

    Do this according to the type of LDAP server you are using.

  2. Copy the JMX schema into your LDAP server's schema directory.

    For example, if you are using Sun ONE Directory Server 5.0, you would type:


    $ cp 60jmx-schema.ldif /var/ds5/slapd-hostname/config/schema
    

    Otherwise, do this according to the type of LDAP server you are using.

  3. Restart the LDAP server.

    Do this according to the type of LDAP server you are using.

  4. Define the root under which the Server will register its service URL.

    You must provide the Server with the path to the domain component suffix dc=Test that you created in 10.1 Initial Configuration.


    $ provider="ldap://$ldaphost:$ldapport/dc=Test" 
    
  5. Compile the Client and Server classes.


    $ javac -d . -classpath classpath Server.java Client.java
    
To Run the JNDI/LDAP Lookup Service Example with an RMI Connector

This example demonstrates the use of the JNDI/LDAP lookup service to look up RMI connector servers that use RMI's default transport, JRMP, as well as the IIOP transport. In addition, as described in 10.1 Initial Configuration, different external directories are used to register the RMI connector stubs.

The combinations of transports and external directories demonstrated here are:

Perform the following steps to run the example:

  1. Start the Server.

    The command you use to start the Server varies according to which external directory you are using. You can start one or more of the following instances of Server with different transports and external registries before starting the Client.

    • RMI connector over JRMP, without an external directory:


      $ java -classpath classpath -Ddebug=true \
           -Dagent.name=test-server-a \
           -Durl="service:jmx:rmi://" \
           -Djava.naming.provider.url="$provider" \
           -Djava.naming.security.principal="$principal" \
           -Djava.naming.security.credentials="$credentials" \
           jndi.Server & 
      

      In this command:

      • debug is set to true to provide more complete screen output when the Server runs

      • The name of the agent to be created is test-server-a

      • The service URL specifies that the chosen connector is an RMI connector, running over the RMI default transport JRMP.

      When Server is launched, you will see confirmation of the creation of the RMI connector, and the registration of its URL in the JNDI/LDAP lookup service.

    • RMI connector over JRMP, using an RMI registry as an external directory:


      $ java -classpath classpath -Ddebug=true \
           -Dagent.name=test-server-b \
           -Durl="service:jmx:rmi:///jndi/${jndirmi}/server" \
           -Djava.naming.provider.url="$provider" \
           -Djava.naming.security.principal="$principal" \
           -Djava.naming.security.credentials="$credentials" \
           jndi.Server &
      

      In this command:

      • The name of the agent created is test-server-b

      • The service URL specifies the chosen connector as RMI over JRMP, and the external directory in which the RMI connector stub, server, is stored is the RMI registry you identified as jndirmi in 10.1 Initial Configuration

      When Server is launched, you will see confirmation of the creation of the RMI connector, and the registration of its URL in the JNDI/LDAP lookup service.

    • RMI connector over JRMP, using LDAP as the external directory:


      $ java -classpath classpath -Ddebug=true \
           -Dagent.name=test-server-c \
           -Durl="service:jmx:rmi:///jndi/${jndildap}/cn=x,dc=Test" \
           -Djava.naming.provider.url="$provider" \
           -Djava.naming.security.principal="$principal" \
           -Djava.naming.security.credentials="$credentials" \
           jndi.Server &
      

      In this command:

      • The name of the agent created is test-server-c

      • The service URL specifies the chosen connector as RMI over JRMP, and the external directory in which the RMI connector stub is stored is the LDAP server you identified as jndildap in 10.1 Initial Configuration

      • The stub is registered in the Test domain component in the LDAP server.

      • The common name attribute principal and password credentials are given to gain access to the LDAP server.

      When Server is launched, you will see confirmation of the creation of the RMI connector, and the registration of its URL in the JNDI/LDAP lookup service under the agent name test-server-c.

    • RMI connector over IIOP, without an external directory:


      $ java -classpath classpath -Ddebug=true \
           -Dagent.name=test-server-d \
           -Durl="service:jmx:iiop://" \
           -Djava.naming.provider.url="$provider" \
           -Djava.naming.security.principal="$principal" \
           -Djava.naming.security.credentials="$credentials" \
           jndi.Server &
      

      In this command:

      • The name of the agent created is test-server-d

      • The service URL specifies the chosen connector as RMI connector over IIOP.

      When the Server is launched, you will see confirmation of the creation of the RMI connector, and the registration of its automatically generated URL in the JNDI/LDAP lookup service.

    • RMI connector over IIOP, using CORBA naming as the external directory.


      $ java -classpath classpath -Ddebug=true \
           -Dagent.name=test-server-e \
           -Durl="service:jmx:iiop:///jndi/${jndiiiop}/server" \
           -Djava.naming.provider.url="$provider" \
           -Djava.naming.security.principal="$principal" \
           -Djava.naming.security.credentials="$credentials" \
           jndi.Server &
      

      In this command:

      • The name of the agent created is test-server-e

      • The service URL specifies the chosen connector as RMI connector over IIOP. The external directory in which the RMI connector stub server is stored is the CORBA naming service you identified as jndiiiop in 10.1 Initial Configuration.

    • RMI connector over IIOP, using LDAP as the external directory.


      $ java -classpath classpath -Ddebug=true \
           -Dagent.name=test-server-f \
           -Durl="service:jmx:iiop:///jndi/${jndildap}/cn=x,dc=Test" \
           -Djava.naming.provider.url="$provider" \
           -Djava.naming.security.principal="$principal" \
           -Djava.naming.security.credentials="$credentials" \
           jndi.Server &
      

      In this command:

      • The name of the agent created is test-server-f

      • The service URL specifies the chosen connector as RMI over IIOP, and the external directory in which the RMI connector stub is stored is the LDAP server you identified as jndildap in 10.1 Initial Configuration.

      • The stub is registered in the Test domain component in the LDAP server.

      • The common name attribute principal and password credentials are given to gain access to the LDAP server.

      When Server is launched, you will see confirmation of the creation of the RMI connector, and the registration of its URL in the JNDI/LDAP lookup service under the agent name test-server-f.

  2. Start the Client.

    After starting the Server using the transport and external directory of your choice, start the Client:


    $ java -classpath classpath -Ddebug=true \
         -Djava.naming.provider.url="$provider" \
         -Djava.naming.security.principal="$principal" \
         -Djava.naming.security.credentials="$credentials" \
         jndi.Client
    

    You will see output confirming the detection of the agents created by the Server and registered in the lookup service. You will also see the identification and confirmation of the connection made to the agents.

    To look up a specific agent, type the following command:


    $ java -classpath classpath -Ddebug=true \
         -Djava.naming.provider.url="$provider" \
         -Djava.naming.security.principal="$principal" \
         -Djava.naming.security.credentials="$credentials" \
         -Dagent.name=agentName \
         jndi.Client
    

    In the command shown above, agentName is the name of the agent you want to look up. You can also specify a partial agent name by using *; for example, x* for all agent names beginning with the letter x.

To Run the JNDI/LDAP Lookup Service Example with a JMXMP Connector

This example demonstrates the use of the JNDI/LDAP lookup service to look up JMXMP connector servers.

  1. Start the Server.


    $ java -classpath classpath -Ddebug=true \
         -Dagent.name=test-server-g \
         -Durl="service:jmx:jmxmp://" \
         -Djava.naming.provider.url="$provider" \
         -Djava.naming.security.principal="$principal" \
         -Djava.naming.security.credentials="$credentials" \
         jndi.Server &
    

    In this command:

    • The name of the agent created is test-server-g

    • The service URL specifies the chosen connector as the JMXMP connector, running on the first available port.

    When the Server is launched, you will see confirmation of the creation of the JMXMP connector, and the registration of its automatically generated URL in the JNDI/LDAP lookup service. JMXMP connector servers can be used alongside RMI connectors, and will be detected by the Client in exactly the same way as RMI connector servers.

  2. Start the Client.

    After starting the Server, start the Client:


    $ $ java -classpath classpath -Ddebug=true \
         -Djava.naming.provider.url="$provider" \
         -Djava.naming.security.principal="$principal" \
         -Djava.naming.security.credentials="$credentials" \
         jndi.Client 
    

    You will see output confirming the detection of the agents created by the Server and registered in the JNDI/LDAP lookup service. You will also see the identification and confirmation of the connection made to the agents.

    To look up a specific agent, type the following command:


    $ $ java -classpath classpath -Ddebug=true \
         -Djava.naming.provider.url="$provider" \
         -Djava.naming.security.principal="$principal" \
         -Djava.naming.security.credentials="$credentials" \
         -Dagent.name="agentName" \ 
         jndi.Client 
      
    

    In the command shown above, agentName is the name of the agent you want to look up. You can also specify a partial agent name by using *; for example, x* for all agent names beginning with the letter x.