Section 6.12. Local and Remote Interfaces


6.12. Local and Remote Interfaces

The Local and Remote Interfaces define the business methods that an EJB exposes to its clients. These interfaces are sometimes called an EJB's Component Interfaces in EJB books and other related literature. An EJB's Local and Remote Interface methods serve the same purpose as public methods for a POJO.

6.12.1. Local Interface

The Local Interface defines an EJB's business methods accessed by local, or co-located, clients (Servlets, POJOs, or EJB) that run inside the container. When accessing an EJB though its local interface, there is no overhead for a network call and object serialization because everything runs in the same JVM. A client running outside the container cannot access a Session Bean using local interfaces. All methods in the Local Component Interface throw an EJBException. Our Local Interface, InventoryFacadeLocal, looks like Example 6-9.

Example 6-9. InventoryFacadeLocal.java
 package com.jbossatwork.ejb; public interface InventoryFacadeLocal extends javax.ejb.EJBLocalObject {     public java.util.List listAvailableCars(  ) throws javax.ejb.EJBException;     public CarDTO findCar(int id) throws javax.ejb.EJBException;     public void deleteCars(String[  ] ids) throws javax.ejb.EJBException;     public void saveCar(CarDTO car) throws javax.ejb.EJBException;     public void buyCar(int carId, double price) throws javax.ejb.EJBException; } 

6.12.2. Remote Interface

The Remote Interface defines an EJB's business methods accessed by remote clientsapplications that run outside the EJB container. All methods in the Remote Component Interface throw a RemoteException. Invoking an EJB though its remote interface incurs overhead for a network call and object serialization because the client and the EJB run in separate JVMs. Example 6-10 is our Remote Interface, InventoryFacadeRemote.

Example 6-10. InventoryFacadeRemote.java
 package com.jbossatwork.ejb; public interface InventoryFacadeRemote extends javax.ejb.EJBObject {     public java.util.List listAvailableCars(  ) throws javax.ejb.RemoteException;     public CarDTO findCar(int id) throws javax.ejb.RemoteException;     public void deleteCars(String[  ] ids) throws javax.ejb.RemoteException;     public void saveCar(CarDTO car) throws javax.ejb.RemoteException;     public void buyCar(int carId, double price) throws javax.ejb.RemoteException; } 

We've shown the Local and Remote Interfaces that define the EJB's business methods, but now we need to talk about the Home Interfaces.



JBoss at Work. A Practical Guide
JBoss at Work: A Practical Guide
ISBN: 0596007345
EAN: 2147483647
Year: 2004
Pages: 197

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net