BEA Logo BEA WebLogic Enterprise Release 5.1

  Corporate Info  |  News  |  Solutions  |  Products  |  Partners  |  Services  |  Events  |  Download  |  How To Buy

 

   WebLogic Enterprise Doc Home   |   J2EE Topics   |   Previous Topic   |   Next Topic   |   Contents   |   Index

Using RMI with EJBs

 

All clients of EJBs use RMI on IIOP. There is really no difference in creating an RMI client of a traditional RMI server or of an EJB server. (See Figure 5-1 and the topic A Note About Type Narrowing.) The difference is in the way the servers handle the calls. This topic explains the relationship between BEA WebLogic Enterprise RMI on IIOP and EJBs.

This topic includes the following sections:

 


EJBs and Clients of EJBs

To talk to an EJB server, a client of an EJB must first obtain an object reference for the EJB server. This is the same task as an RMI client obtaining a reference to a remote object. The EJB server is always treated as a remote object. To obtain the object reference, BEA WebLogic Enterprise clients of EJBs use the Java Naming and Directory Interface (JNDI). The JNDI call returns a reference to an object that can implement the EJB server's Home interface. The client can use the Home interface on an EJB server to look up existing EJB instances or create new ones. The client uses the Remote interface to interact with EJB objects on the server.

In short, a client of an EJB is an RMI client that is talking to an EJB.

 


Client Callbacks from EJBs

In BEA WebLogic Enterprise, a particularly useful feature of RMI is that you can use it to do client callbacks from Enterprise Java Bean (EJB) servers. Clients cannot advertise EJB implementations, but they can advertise RMI implementations. So if a client wants to be called back from an EJB instance, it should create an RMI object and pass the reference to the EJB instance. The EJB instance can then invoke the client callback by using the RMI reference.

 


Clients of EJBs and BEA WebLogic Enterprise RMI Servers

Notice that by definition all clients of EJBs use RMI on IIOP. Therefore, clients of EJBs can also talk to BEA WebLogic Enterprise RMI servers.

 


A Note About Type Narrowing

A client program that is intended to be interoperable with all compliant EJB container implementations must use the method javax.rmi.PortableRemoteObject.narrow to perform type-narrowing of the client-side representations of the home and remote interface. Once an object reference is obtained, the client must narrow it to the appropriate type. If you are creating a generic RMI client, you could use the cast operator instead of PortableRemoteObject.narrow. However, we recommend the use of PortableRemoteObject.narrow to ensure interoperability with compliant EJB container implementations.

 


Where Can I Find Examples of Clients of EJBs?

All clients of EJBs use RMI on IIOP. For a description of the EJB examples, see the Guide to EJB Sample Applications in the BEA WebLogic Enterprise online documentation.