510 likes | 578 Views
Chapter 8 Evaluating Candidate Technologies for Control and Entity Classes. 鄧姚文 joseph@im.knu.edu.tw http://w3.im.knu.edu.tw/~joseph. Agenda. RMI JDBC EJB 1.1 Sample technology selection. RMI. Remote method invocation
E N D
Chapter 8 Evaluating Candidate Technologies for Control and Entity Classes 鄧姚文 joseph@im.knu.edu.tw http://w3.im.knu.edu.tw/~joseph OOAD
Agenda • RMI • JDBC • EJB 1.1 • Sample technology selection OOAD
RMI • Remote method invocation • Allows a client on one host to call methods on an object that resides on another host OOAD
RMIGory Details OOAD
RMI Gory DetailsParameter Passing • Primitives • Serializable objects • Ignores transit objects • Implements java.io.serializable • Remote reference as parameters • Implements java.rmi.RemoteObject • Their stubs are serialized and sent in their place OOAD
RMI Gory DetailsThread Safety • Accessed by concurrent threads • It is up to the developer to make sure that any resources shared among client requests are thread-safe • Synchronize methods or code blocks OOAD
RMI Gory DetailsDevelopment and Deployment • Write remote interfaces and implementations for the server • Use the rmic command to generate stub classes • Write client applications • Distribute stub classes and any common domain classes to the client • Start the RMI registry • Run the main application to register the remote objects with the registry • Start the client OOAD
RMICommon Uses of RMI • Remote object that hides entity objects • Strict layering • Direct access to entity objects • Relaxed layering • Direct access to entity objects with event notification • The observer pattern OOAD
RMI • Strengths • Distributed application • Elegant and easy to assimilate • Cross platform • Weaknesses • Leave scalability, fault tolerance, load balancing, and data integrity concerns up to the developers OOAD
RMI • Compatible technologies • RMI + JDBC • RMI remote objects can be called by any java code • Cost of adoption • Architect • RMI developer OOAD
JDBC • Java DataBase Connectivity • Allows developers to write database-independent code while still getting the performance of drivers OOAD
JDBCGory Details • Drivers, connections, and statements • New and improved result sets OOAD
RMI • Strengths • Database-independent code • Weaknesses • Transaction management • Connection pooling OOAD
JDBC • Compatible technologies • Can be used to access a database from any java code • Cost of adoption • Architect • JDBC developer OOAD
JDBC Suitability of RMI and JDBC • Number and type of users • A small number of dedicated users, general use within an organization • A large audience with high interest • Do not scale well • Performance and scalability • For read-only systems and for systems that allow isolated updates OOAD
EJB 1.1 • Enterprise JavaBeans • Java 2 enterprise edition • A framework that exposes objects to remote clients • Object caching • Transaction management • Object-to-relational persistence • Security OOAD
Entity bean Home interface Session bean Remote interface Implementation Deployment descriptor Bean-managed persistence Container-managed persistence Transaction boundaries Container Persistence EJB 1.1Terminologies OOAD
EJB 1.1 • Entity bean • Remote accessible components • Expose business data and business logic • Each entity bean represents a single independent and persistent entity in the domain • Evolve from entity objects OOAD
EJB 1.1 • Home interface • Specify remotely accessible methods for the creation, location, and destruction of one type of entity bean • Evolve from lifecycle objects OOAD
EJB 1.1 • Session bean • Expose high-level business logic and workflow logic that spans multiple entity beans • Translate an individual high-level request into many requests to many entity beans • Stateful or stateless • Evolve from control objects OOAD
EJB 1.1 • Remote interface • Define the remotely accessible methods • The type of the returned entity objects OOAD
EJB 1.1 • Implementation • A class that realizes an EntityBean or a SessionBean interfaces • Entity bean • Implementation of the business logic • Session bean • Implementation of the workflow logic OOAD
EJB 1.1 • Deployment description • An XML document that describes how the entity and session beans are deployed • Location of the class file • Decisions about persistence • Decision about transactions • Security OOAD
EJB 1.1 • Container • The EJB container holds entity beans and session beans • Object caching • Concurrent access • Transaction management • Persistence OOAD
EJB 1.1 • Bean-managed persistence • The entity bean loads and saves its own data • Embed JDBC code within the bean’s implementation • Container-managed persistence • The developer specifies a mapping between each piece of persistent data and a field in a table in the database OOAD
EJB 1.1 • Transaction boundaries • Developers specify transaction boundary in the deployment descriptor • Whether a method should join an existing transaction, start its own transaction,or execute outside of any transaction OOAD
EJB 1.1Gory Details • Using EJB is infinitely better than trying to produce your own scalable remote object framework • Classes and interfaces • Remote interface, extends EJBObject • Home interface, extends EJBHome • Implementation class, implements EntityBean OOAD
EJB 1.1Gory Details • Stateful session bean • Maintain a dialog with the client • Remember past requests and use them to simplify subsequent requests • Take up memory • Must be managed by the container until the session is completed • Control objects that provide a conversational workflow OOAD
EJB 2.1Gory Details • Stateless session bean • Do not remember any conversational state from request to request • Container can keep a small pool of stateless session beans for use by many clients • Control objects that convert a single method into a series of smaller requests and consolidate the results OOAD
EJB 1.1Gory Details • Development workflow, assuming container-managed persistence • Allocation of business data, business logic, and control logic to entity and session beans • Mapping entity data to persistent data store • Determining transaction boundaries and security OOAD
EJB 1.1Strengths • Object lifecycle management • No JDBC code, reusable entity beans • Transaction management • Security • Persistence • Vendor neutrality • Portable and reuse OOAD
EJB 1.1Weaknesses • Expensive application servers • BEA WebLogic • IBM WebSphere • Oracle 9i AS • Borland BES • Sun ONE Application Server • Painful code-deploy-test cycle OOAD
EJB 1.1Compatible Technologies • Compatible with any kind of Java technologies OOAD
EJB 1.1Cost of Adoption • Commercial-quality application servers with EJB support are expensive • Architect • Bean developer • Deployer OOAD
EJB 1.1Suitability • Number and type of users • Valid choice for all types of audience • Performance and scalability • Not suitable for read-only systems • Scale well • Load balancing, clustering OOAD
Sample Technology Selection • Candidates • Custom implementation based on RMI and JDBC • EJB implementation • Technology requirements • Number and type of users: general use within an organization • Performance and scalability: concurrent updates OOAD