John M. Thompson
- Assign a unique Id to every dynamically created object - runtime performance must be considered.
- Id number space need only be unique to a specific class.
- Like objects may be created by multiple threads 'simultaneously.'
- Ids must be unique across multiple server startup/shutdown cycles.
- Use database table (IGlobalIds) to track next available Id for each class.
- Table is read at system startup by a singleton caching object.
- Caching object can 'serve' new ids for all classes without database server hits.
- Caching object knows how to 'replenish' its available ids from database server as required.
- Caching object maintains uniqueness through threadsafe implementation.
ClassName VARCHAR(32) Primary Key AvailableId INTEGER BlockSize INTEGER
|Initializing The App|
System 'Dead Start' - Initial System Install
- Done once for a production system; innumerable times during development.
- Java server-side app is run (Linux and/or Windows) to handle entire environment creation -
- Database tables are created by each IPersistable object through call to its inherited createTable() method (below).
- Data loading (eg, sample assessments and their owning Administrators, GlobalIds table intialization) proceeds by instantiating appropriate Java objects and, again, using their inherited JDBC encapsulation methods (dbWrite(), dbUpdate(), etc.).
Web App Servers are easy - all handled at Linux bootup
- DBMS (MySQL - mysqld)
- Webserver (Apache - httpd)
- Servlet Engine (Tomcat - Java app)
Web App Runtime Initialization
- IConfigSingleton, the configuration-file manager object, is initialized within the ServletBase.init() method - Tomcat is configured to load this servlet upon startup, insuring config file processing.
- Database Manager, Connections, Pool, et al, is also a singleton and will self-initialize on first use.
- Other servlets - loaded as invoked (per Servlets spec)
|Encapsulating The SQL Encapsulation(!)|
Selected Objects -- Tables (20 total)
ITestAdmin A goAskem assessment Administrator ITest Any assessment - test or survey ITestElement Any assessment element - text or question ITestRespondent A Respondent to any assessment - single-access ITestResponse An assessment element's response data
A New Table - IAdminAction: An account action taken by its Admin.
Question: How to introduce this class and table into the Web App?
- Abstract base class iwaypublishing.db.IPersistable contains complete SQL-based object persistence capabilities (JDBC).
- Key abstract methods, marshallData() and unMarshallData() can be mechanically created from the data members to be persisted in the database.
- Class iwaypublishing.util.IPersistableGenerator can write these methods, as well as most of the class, from brief table-based input.
- Build code generator input table.
- Run code generator as single-use, server-side process.
- 'Touch up' generated code, adding required business logic.
- Add IAdminAction.createTable() call to system 'dead start' code.
- Implement use of IAdminAction objects within various servlets, including dbRead(), dbWrite(), dbUpdate(), etc. inherited methods.
Generator Input:Tablename: IAdminActionsXXX int id Id true 12 int testAdminId TestAdminId true 12 Date actionDate ActionDate tru byte actionType actionType true 4 0 String notes Notes true IGlobals.gVarChar100
Code walkthrough of generated code - especially
marshallData() and unMarshallData().
|Everybody Into The Pool|
Connection management can be the most performance-critical aspect of database application performance.
- Need resource pool to manage set of database Connection objects - all database access comes through this pool.
- Need a configuratble Connection count.
- Must be initialized at server startup (no waiting at runtime).
- Connection expiration problems must be managed.
- Pool management must be multithread-safe.
- Due to Connection access frequency, acquisition and release must be super lightweight.
- A wrapper for java.sql.Connection is defined (IConnection) that eases enforcement of proper connection use.
- The singleton IDBManager creates a pool of IConnections and initialized upon first access.
- The configuration file content managed by IConfigSingleton holds a pool size entry.
- Both Oracle and MySQL JDBC Connections expire after some period of time (12+ hours for MySQL) - an aging mechanism must be implemented to age-out Connections.
- Since Connection acquisition must be lightweight and multithread-safe, it's desirable to avoid checking the age of a Connection (using system call to get time) with every use.
- Create a separate thread (IDBConnPoolRefresher) to wake up periodically and tell each IConnection to check itself and regenerate its contained JDBC Connection if it has aged out - checks occur only when refresher decides to (configurable) and are disassociated from time of Connection acquisition.
|Client-side Application Logic Without Applets|
Chief advantages to Applets
- Accessible from within common browsers.
- Full control over user interface within browser.
- Maintain state on client-side across server hits.
Chief problems with Applets
- Browser compatibility problems.
- Lengthy download times.
- Using HTML frames, it's possible to maintain state in one frame across server refreshes in other frames.
- User data need not be sent to server and back again with each page update.
- Server fetches are the size of typical static pages.
- The goAskem Wizard is implemented entirely in this fashion.
- Must rely upon user for more careful management of data saves (no auto-save).
- Must hide browser menu and toolbar to discourage use of browser Back and Forward functions.
- Screen updates slightly impacted by required server hits.
Code walkthrough on goAskem.com Assessment Creation Wizard
Originals are accessible from http://www.iwaytechnology.com/jt/index.html.
by John M. Thompson
Boulder, Colorado USA
limited right to copy this page for
educational use only
is hereby granted.