COMP 655: Distributed/Operating Systems - Winter 2015 2025-01-30 23:41:48 UTC | |||||||||||||||||||||||
| EJB
EJB (Enterprise Java Beans) are the primary technology in Java EE for building Java-speaking components that interact synchronously with their clients. (Servlets are the primary technology for building HTTP-speaking synchronous components.) EJB also includes message-driven beans (MDB). MDBs don't have clients; instead, they listen for and process JMS messages. EJB for DiNo
Finding an EJB in a remote GlassFish For another team to use your directory EJB, they have to get a reference to it. That's where your orb-listener-1 host:port information is needed. This code snippet looks up
Notes
EJB Deployment An EJB is deployed in a jar file. The classes that define its API are typically collected into a jar file, which is made available to developers building clients of the EJB. For that reason it's usually called the "client jar". Both the EJB and the clients include the client jar in their classpaths, to ensure that they are using the same interface classes. Using the same interface classes is required for them to communicate. In the DiNo project, the DiNo directory client jar contains the directory service interface classes. You will include this jar on the classpath for both your notebook service implementation (the client) and your directory service implementation (your directory EJB). You can see it in both the notebook service reference implementation and the directory service reference implementation (that is, you can see dino-directory-client.jar if you open these archives or download them and extract them to folders) Getting a client jar onto an EJB's classpath is not terribly intuitive - see the DiNo implementation page for more information. Sample code Here is an EJB that implements the data management behind the menu service Here is a menu service implementation that uses the EJB Both include source code. They should be ready to deploy in GlassFish. I enhanced the RESTful client slightly to include menu-ejb on the base URL drop-down. The menu-ejb-svc is also available on einstein. Note that the menu-ejb-svc includes menu-ejb-client.jar in its WEB-INF/lib. This jar includes the EJB's API, but not the implementation. The service needs it so that it can work with the EJB's interface and the types mentioned in the interface. Note also that the menu.api.Menu class has to implement the java.io.Serializable interface; if it doesn't, Java RMI will refuse to transfer it from the EJB to the client. Exercise The menu-ejb-svc will only work with a menu EJB deployed in the same GlassFish instance. Enhance it so that it can be re-directed at runtime to menu EJBs deployed in other GlassFish instances (unfortunately, you won't be able to test this with einstein, because of its JNDI issues) |