520 likes | 749 Views
Building Good Components for Jaguar CTS 2.0: A Case Study. David Lance Wolf Product Line Specialist Jaguar Product Team dwolf@sybase.com news://forums.sybase.com/powersoft.public.jaguar.cts. Sybase Virtual University (or how to double my bonus).
E N D
Building Good Components for Jaguar CTS 2.0:A Case Study David Lance Wolf Product Line Specialist Jaguar Product Team dwolf@sybase.com news://forums.sybase.com/powersoft.public.jaguar.cts
Sybase Virtual University(or how to double my bonus) • SVU wants to take over the distributed education market • To demonstrate leadership in this market, they must deploy a successful distributed application • My developers are students!!!! • My bonus will double when the product ships!
Betting My Bonus on Enterprise Application Server • EAS answers the difficulties of robust, scalable and predictable OLTP on the web • Predictable Workloads • Open Standards • Cross Platform • Scalable • Language independent
A little vocabulary! • N-tier computing meant learning a little new vocabulary: • Package • Component • Implementation • Skeleton • Stub
Overview Overview of Component Based Computing Designing The Application Connection Management Transaction Management Component Lifecycles Scalability
What Are Components? • Components are pre-built stand alone ‘pieces’ of a larger application. • Ease development by encapsulating complex, reusable logic. • Components are designed to ‘plug’ together in endless combinations to build larger applications with minimal coding.
Existing component models • Microsoft • COM • DCOM • ActiveX • Object Modeling Group • CORBA • JavaSoft • JavaBeans • Enterprise JavaBeans
Think Components Not Applications • Plan applications and development around “components” rather than processes. • Modeling tools • Riverton’s HOW • Rational’s ROSE • Merging component development with RAD development • Separate layers • Define Interfaces
Overview Overview of Component Based Computing Designing Your Application Connection Management Transaction Management Component Lifecycles Scalability
You didn’t just say my programmers are our students did you? • Students are specialized in their studies • GUI specialty • DBA’s • Java Programmers • C++ Programmers • COM Programmers • I’ll have to divide and conquer to meet my deadline
Separate Business, Data and Presentation Layers Presentation Business Rules Data Access • When “Thinking Components” understand the “layers” of the application • Build components in these layers • Allows reuse of components by choosing layer deployment • Separation of layers allows each layer to live where it is most optimized
Data Access Layer Data Access • How, Where, When of data access • Allows for abstraction of data access methods, from the underlying data store • Often done with procedures, can be extended into components as well
Business Rules Layer Business Rules • Allows for abstraction of the Business Rules, from the Data, and the Presentation • Rapidly change Business Rules, without affecting deployed applications
Presentation Layer Presentation • Leaves final Presentation of the Data and the Rules to the application. • Allows for a Model/Controller/View design • Removes developers from needing to understand business processes, data location, and transactional boundries
Monolithic Computing Presentation Business Rules Data Access • All three layers live in one location • Advantages • Maintainability • Predictability • Disadvantages • Closed System • Poor use of computing resources Server
Client / Server Presentation Client Business Rules Data Access Server • Separates processing across a client and a server machine • Presentation and business logic live on the client • Advantages • Takes advantage of client resources • Disadvantages • Maintenance • Client Programmers need database and logic
Distributed Computing Client Presentation Business Rules CTS Data Access Data Access Server • Separate all three layers • Best use of computing resources • Increases scalability while decreasing system maintenance • Advantages • Scalability • Maintainability • Use of Resources • Disadvantages • Knowledge ramp up time (Integrated Builder Tools!)
Divide and conquer • I can keep my specialized developers working within their area of expertise • I can gain real reusability, even if my programmers graduate • I can maintain this
Overview Overview of Component Based Computing Designing Your Application Connection Management Transaction Management Component Lifecycles Scalability
You only bought a 10 user connection license? • The University has an ASE Server, but they only bought a 10 connection license! • Students use patterns are very unpredictable • The system must be available 24/7 • They need to be able to connect to any database they might buy in the future
Connection and Cache Management • Jaguar 2.0 includes connection pooling via connection caches • Increase scalability via finite connections • Three connection options • WAIT • FORCE • NOWAIT • Three connection pool types • ODBC • OpenClient • JDBC
Connection Options • JCM_WAIT • Causes the component to block until a connection becomes available. • JCM_FORCE • Force a new connection to be built and added to the cache • JCM_NOWAIT • Throw an exception to the calling thread informing it no connections are available
Connection Types • JDBC • Use any JDBC driver available in the CLASSPATH • Only Java components can use a JDBC cache • ODBC • Use a System Data Source Name which is installed by the ODBC Driver Manager • Can be accessed by • C/C++ • ActiveX • Java (via the JDBC/ODBC bridge) • OpenClient • C/C++
Connection Caches! • Connection caching provides a predictable workload on the database • Uses each connection to its fullest • Open design pattern. I can connect to any JDBC, ODBC or OpenClient source. I’d say that’ll cover it!
Overview Overview of Component Based Computing Designing Your Application Connection Management Transaction Management Component Lifecycles Scalability
My GUI developers don’t know a transaction from a tab control! • Seems ‘Introduction to RDBMS’ wasn’t in the GUI specialties required courses (who knew). • I just don’t have time to ramp up these developers • I’m dealing with financial data, I cant afford a mistake
Transactional Components • Declarative Transactions • completeWork • rollbackWork • continueWork • disallowCommit * • Carry Transactions across Components • Must use stubs • Same process space • Can’t carry Transactions across Servers • Client notification • CORBA User Defined Exceptions
Transaction Manager InterfacesObject Context (MTS), Instance Context (EJB) • completeWork() • Vote for commit and deactivate on return • rollbackWork() • Vote for rollback and deactivate on return • continueWork() • Vote for commit and maintain state • disableCommit()* • Vote for rollback and maintain state • inTransaction() • Returns true if the component is within a transaction • isRollbackOnly() • Returns true if the transaction is doomed
Using the Right Transaction Models • Several Transactional Models • Not Supported • Supported • Requires • Requires New • Jaguar opens a transaction on your behalf • Transactional Coordinators • Shared Connection • Microsoft DTC
Transaction Manager Property Definition • Required • If the caller does not have a transaction then a new transaction is started. Otherwise the caller’s transaction is inherited. • Not Supported • If the caller has a transaction then it is suspended and later resumed when the method invocation returns. • Supported • If the caller has a transaction then it is inherited. Otherwise the method is executed without a transaction. • Requires New • If the caller has a transaction then it is suspended. A new transaction is started with this component as its root.
Implicit Transactions • My GUI developers don’t have to worry about transactions • My RDBMS developers can encapsulate this • I can gain reuse from my components by using declarative transactions
Overview Overview of Component Based Computing Designing Your Application Connection Management Transaction Management Component Lifecycles Scalability
Keeping the Professors Happy too?? • Dr. Theory has asked that we reuse some of the code his students used in his “Good State Machines” course • The code wasn’t written explicitly for Jaguar • I need to be able to integrate this code to use transactions, and control state
Stateful/Stateless Instantiation Activation Method Invocation Deactivation Destruction • Component Life Cycle • Stateful Components • Hold state in instance members • Destroyed after use • Stateless Components • Hold no state in instance members • If pooled, after deactivation reenters activation on next method invocation • Can service many stubs instances
Instance Pooling Instantiation Activation Method Invocation Deactivation • Same component instance can re-enter Activate after Deactivation • Components advertise their interest in instance pooling • One component instance can service many client instances • Scalability
Making Your Components Poolable try { rs = stmt.execute(sql); trs = IDL.getResultSet(rs); rs.close(); rs = null; state.completeWork(); return trs; } catch(SQLException sqle) { state.rollbackWork(); } } public boolean canReuse() { return true; } • Return true from canReuse() • Store NO stateful data in instance members • Can store in the database • Can store in a Service component • Can store in a file • Set transactional primitives at method exit • Don’t forget to set primitives in catch() blocks too!
Automatic Transaction Demarcation Instantiation • Useful for pre-built components • Jaguar will deactivate the component at the completion of each method invocation • Synonomous with calling completeWork() or rollbackWork() at each method exit Activation Method Invocation Deactivation Destruction
Lifecycles • Property sheet configuration lets me set state and instance pooling without changing their code • I can now leverage Jaguar performance and scalability
Overview Overview of Component Based Computing Designing Your Application Connection Management Transaction Management Component Lifecycles Scalability
Tell me that student didn’t just say “What does thread safe mean?” • I need to create a scalable application • My developers have NO experience in creating multi-threaded applications • The university has thousands of students across the world, how do I support that kind of load?
Scalability • Jaguar provides a very scalable container thanks to • Early Deactivation • Automatic Demarcation • Instance Pooling • Connection Caches • Service Components • Threading Models • Shared • Poolable
Service Components • Service Components boot at engine start. • Should be Thread Safe for best scalability • Can be used to perform “service level tasks” • Can be used to cache data • Component connects to data source at boot and extracts data • Same instance services all stubs • Refresh data at intervals
Available Threading Models • Concurrency • Multiple invocations processed concurrently • Bind Thread • Allows for thread-local storage • Pooling • Instance pooling • Sharing • Single instance services all clients
Being Thread Safe & Scalable • Try to store state in non-instance member stores • Database • Files • Service Components • Consider using shared container objects as shared objects • Vectors • Hashtables • Make sure when pooling, that instance data is cleaned up in the deactivate stage.
Avoiding Memory Leaks • JDBC • Close Statement’s • Set Statements to null • Close ResultSet’s • General • Clean up in finalizers • set object references to null • Close all streams • Sockets • Files • Objects • Server-Side debugging
Jaguar provides me everything that makes writing servers hard! • Instance pooling, Connection Caching, and Service components let me build a very scalable server • I can have Jaguar do all my thread Synchronization • I can simply configure a components threading models from the property sheets