290 likes | 388 Views
E nterprise J ava B ean. Matt. J2EE. J2EE Overview. J2EE 1.4 API. Distributable Components. Components should provide services to clients running locally or remotely SelfContained Components Components should only contain the code necessary to implement their services
E N D
Enterprise Java Bean Matt
Distributable Components • Components should provide services to clients running locally or remotely • SelfContained Components • Components should only contain the code necessary to implement their services • Infrastructure services should be injected by the execution environment • Standard infrastructure services include • Directory Services • Distributed transaction management • Security management • Concurrent access management • Persistence management • Resource pooling (e.g. DB connections) • Administration interface • Load Balancing • Fault tolerance An application server provides the infrastructure and services to run components/applications
Object Pooling • An application server may create a pool of bare objects that may be used as EJBs when requests are made
Container • A Container • provides the environment in which a bean executes • generates Home Object • generates EJB Object • manages individual bean instances
EJB • Enterprise Java Bean包括了 • Session Bean: Session beans are essentially service providers • Stateless • Stateful • Entity Bean: Entity beans are used to represent data in a database. • BMP • CMP • Message-Driven Bean: Message driven beans are capable of responding to JMS messages
EJB Overview • EJB simplified distributed development • Develop EJB implementation logic • Define Home/Local Remote/Local interfaces • Container delegates client calls • Container manages resources/lifecycle/callbacks
EJB Design Approaches • Remote interface • Home interface • Bean class
EJB clients utilizes the Java Naming and Directory Interface (JNDI) to look up for the references to home interfaces use home and remote EJB interfaces to utilize all EJB-based functionality EJB Home interface create EJBs remove EJBs find handles to EJB remote interface objects EJB remote interfaces provide business-specific functionality of an EJB are similar to RMI Remote interface EJB implementation (Bean Class) business method invocation database loading logic passivation, database storage Session Context The Container has already reference to the bean The bean interacts with the Container through SessionContext and retrieves home interfaces gets and sets transactions attributes obtains security attribute The setSessionContext method is used to inform the bean about the session context EJB
Session EJBs View • Stateless • Stateful
Stateful Bean A stateful bean contains a conversational state that is retained across method calls and transactions. The create method takes argumentse.g. create(String id) , create(int I , String id) There can be one or more arguments in a create method e.gAn EJB that unzips 100 bytes of data An EJB that checks to see if a stock symbol is valid Stateless Bean A stateless bean does not have any state between calls to its methods The create method does not take argumentse.g create() There can be no arguments in a create method e.gAn EJB that books a flight and rents a car at a travel agent’sweb site. Stateful vs Stateless