ALL, I am a newbie for EJB of Java World, After reading the good book named Ejb3.0 in Action, I have a question about Session Bean. What is the EJB Client for a session bean? Say we have some code looks like below.
//EJB definition
import javax.ejb.Remote;
@Remote
public interface PlaceOrder {
..
void addItem(Long itemId);
Long confirmOrder();
..
}
@Stateful
public class PlaceOrderBean implements PlaceOrder {
private List<Long> items;
public PlaceOrderBean () {
items = new ArrayList<Long>();
}
public void addItem(Long itemId) {
items.add(itemId);
}
@Remove
public Long confirmOrder() {
Order order = new Order();
...
return order.getOrderId();
}
}
//Client
import javax.ejb.EJB;
public class PlaceOrderTestClient {
@EJB
private static PlaceOrder placeOrder1;
@EJB
private static PlaceOrder placeOrder2;
public static void main(String [] args) throws Exception {
System.out.println("Exercising PlaceOrder EJB...");
placeOrder1.addItem(new Long(200));
placeOrder1.addItem(new Long(201));
Long orderId = placeOrder1.confirmOrder();
System.out.println("Order confirmation number: " + orderId);
}
}
Updated
The EJB Client means placeOrder1
and placeOrder2
or the main application ? Does it means multiple EJB clients? Another question is what if it is in Servlet
instead of main method ? thanks.
EJBClient
is a local program which can call and operate Remote
Bean
Here, in your scenario whatever triggers the PlaceOrderBean
is a client
InCase of Servlet, if Servlet
calls the EJB
it is technically client but often called Facade