Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 60 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
60
Dung lượng
250 KB
Nội dung
EnterpriseJava Beans, an Introduction Barbara Dellen Jeff Thomson Contents • Overview: What are EJB’s? • EJB Fundamentals • EJB’s and Gemstone The Model • Enterprise JavaBeans are Java components that fit together in a standard way. • The container provides a portability layer that lets anyone’s beans operate in anyone else’s container. Containers • Containers are software receptacles that know how to communicate with and manage the beans. – The container places itself between the client and the bean. This gives it the opportunity to implement services many developers don’t want to worry about. Container Services • Some services that can be provided by the container include: – Persistence management – Transactions – Concurrency – Thread management – Security Container Vendors • Many vendors have already supplied containers for EJB and their products. Among them are: – IBM – WebLogic – Sybase – Oracle – CORBA Object Request Brokers such as Inprise (Borland) Infoworld’s Example • Infoworld developed a sample application for EJB using: – WebLogic’s Tengah Java application server as the container – IBM as the server – Oracle as the database • The application’s use of servlets to act as clients to the EJB’s allows for browsers that don’t support Java. Example continued • The sample application was a J-Store that simulated an online-shopping service – EJB handled the business objects – Java servlets and JavaPages take care of the page transmission and display logic – Application authenticates users and lets them browse GIF images, load them into a shopping cart – and tallies up the sale. Behind the scenes • The container interposes itself between the client and the bean. • Beans that a client creates do not expose their functions directly to the client • The container exposes the methods of the remote interface • Which is assembled ahead of time by the container vendor. This is known as “wrapping” the object. The Container • You can specify to the container at deployment time how to treat your components • This is called Declarative programming. [...]... about the number of clients activating a bean Session Beans • Session beans are used by one client only, two clients may not access the same instance of a session bean • Session beans are lost in a server crash Two Session Beans • Stateless Beans – A stateless bean looks the same to a client before and after operation • Stateful Beans – A stateful bean is semipersistent – The developer can have them... Home Object Remote Interface EJB Object enterprise Bean Remote Interface EJB Object enterprise Bean Enterprise Bean Types • Session Beans – Executes on behalf of a single client (not shared) – Updates shared data in an underlying database – Does not represent directly shared data in the database – Is removed when the EJB server crashes Once again: EJB Types • Entity Beans – – – – – Represents data in the... object • Provided by the container • Supports enterprise Bean’s remote interface • Delegates invocation of a business method to the enterprise Bean instance • Supports methods of javax.ejb.EJBObject interface (getting the object’s container, etc.) Class Diagram for a session Bean javax.ejb.EJBHome BankBeanHome javax.ejb.EJBObject BankBeanRemote... JNDI - Java Naming and Directory Interface Back to the Example • The application’s server bean runs alone inside the Tengah container • But EJB lets multiple beans run side by side in the container • EJB also allows multiple instance of the same bean • Also, EJB allows multiple containers to run on a server Bean programmers don’t have to worry about the number of clients activating a bean Session Beans. .. disk, passivate the bean, then later reactivate it Entity Beans • Entity beans survive if the server crashes • Multiple clients can access a single entity bean via multiple instances • The container makes sure each instance is bound to the current data and passes info to the proper client References Tom Young and Yun Wang, Mixing Sun’s Magic Beans, Infoworld Publishing Company, June 29, 1998 www.infoworld.com/cgi-bin/displayTC.pl?/980629analysis.html... – – Represents data in the database Is transactional Allows shared access from multiple users Long-lived Survives crash of the EJB server Roles in EJB Development • Client • Enterprise Bean Provider • Container Provider Session Beans: client view Container BankBeanHome Client BankBean class :BankBeanRemote :BankBean Remote :BankBeanRemote AirlineBeanHome AirlineBean class :AirlineBeanRemote :AirlineBeanRemote... javax.ejb.EJBObject BankBeanRemote BankBean implements the business methods of the BankBeanRemote interface javax.ejb.SessionBean activate() passivate() remove() setSessionContext(SessionContext) BankBean Session Bean • Implements business methods of the Bean’s remote interface • Implements the javax.ejb.SessionBean interface – activate()/passivate() signals when the Bean is about to be activated/passivated... Entity Beans • Persistent • Multiple clients can access an entity Bean concurrently • Primary key provides a unique identifier • Deployment descriptors provide transaction characteristics Entity Bean’s Home Interface • Allows client to create new EJB objects • Allows client to remove EJB objects • Allows client to look up existing EJB objects by finder methods Entity Bean Class diagram javax.ejb.EJBHome... client to look up existing EJB objects by finder methods Entity Bean Class diagram javax.ejb.EJBHome javax.ejb.EJBObject BankBeanHome BankBeanRemote BankBean implements the business methods of the BankBeanRemote interface javax.ejb.EntityBean activate() passivate() remove() load() store() setEntityContext(EntityContext) unsetEntityContext() BankBean... objects BankBeanRemote myBean = myBeanHome.create(); • Allows client to remove EJB objects myBeanHome.remove(myBean); • Provides Bean meta-data Locating a (session) Bean’s home interface • Using JNDI (Java Naming and Directory Interface) • Code provider specific • Example (Gemstone): Context initialContext = new InitialContext(env); BankBeanHome myBeanHome = (BankBeanHome) initialContext.lookup("Systems/gsj21/Repository/Appli . 1998. www.infoworld.com/cgi-bin/displayTC.pl?/980629analysis.html EJB Architecture Client EJB Server Container Home Object EJB Object EJB Object enterprise Bean enterprise Bean Remote Interface Remote. inside the Tengah container • But EJB lets multiple beans run side by side in the container. • EJB also allows multiple instance of the same bean. • Also, EJB allows multiple containers to. Beans, an Introduction Barbara Dellen Jeff Thomson Contents • Overview: What are EJB s? • EJB Fundamentals • EJB s and Gemstone The Model • Enterprise JavaBeans are Java components that