Sun Java System Application Server Enterprise Edition 8.2 Developer's Guide

ProcedureTo access an EJB component from a server-side module

A server-side module can be a servlet, another EJB component, or another type of module.

  1. In your module code, instantiate the InitialContext:

    InitialContext ctx = new InitialContext();

    It is not necessary to explicitly instantiate a naming context that points to the CosNaming service.

    To set up load balancing and remote EJB reference failover, define the endpoints property as follows:

    Hashtable env = new Hashtable();
    InitialContext ctx = new InitialConext(env);

    The endpoints property specifies a comma-separated list of one or more IIOP endpoints used for load balancing. An IIOP endpoint is in the form host:port, where the host is an IPv4 address or host name, and the port specifies the port number.

    If the endpoints list is changed dynamically in the code, the new list is used only if a new InitialContext is created.

  2. In the module code, look up the home object by specifying the JNDI name of the home object. For example:

    Object ref = ctx.lookup("jndi-name");
    BeanAHome = (BeanAHome)PortableRemoteObject.narrow(ref,BeanAHome.class);

    If load balancing is enabled as in Step 1 and the EJB components being accessed are in a different cluster, the endpoint list must be included in the lookup, as follows:


    For more information about naming and lookups, see Accessing the Naming Context.

  3. Deploy the EJB component to be accessed.

    For more information on deployment, see Tools for Deployment.

  4. To access EJB components that are residing in a remote system, set the values for the Java Virtual Machine startup options:

    jvmarg value = "-Dorg.omg.CORBA.ORBInitialHost=${ORBhost}"jvmarg value = "-Dorg.omg.CORBA.ORBInitialPort=${ORBport}"

    Here ORBhost is the Application Server hostname and ORBport is the ORB port number (default is 3700 for the default instance).

    This information can be obtained from the domain.xml file on the remote system. For more information on domain.xml file, see the Sun Java System Application Server Enterprise Edition 8.2 Administration Reference.

  5. Deploy the module.

    For more information on deployment, see Tools for Deployment.

Example 8–3 Client Load Balancing and Failover

The following sample application demonstrates client load balancing and failover: