architecture of esobi club based on j2ee
DESCRIPTION
TRANSCRIPT
Architecture of eSobi club based on J2EE
Allan Huang @ eSobi Inc.
Agenda
Software Layers for J2EE Application Table Schema structure and Domain Object
design Look from Top-Down, Carry out from Bottom-
Up
Integration Tier
Business Tier
Presentation Tier
Software Layers for J2EE Application
Arc
hite
ctur
e C
ompo
nent
Lay
er(F
ram
ewor
k)
Dom
ain
Obj
ect
Laye
r(D
omai
n M
odel
/ E
ntity
)Presentation Layer
(Servlet / JSP)
Deployment Layer
Business Logic Layer(Business Object)
Data Access Object Layer
Business Delegate Layer
Architecture Component Layer Generic application utilities Often, these objects are good candidates for
enterprise-wide use Well-known open source projects
Jakarta commons, dom4j, log4j, xerces, quartz, java mail, jasypt, captcha …
Domain Object Layer
Lightweight structures for related business information
Enterprise Java Bean BMP Entity Bean (EJB1.0) CMP Entity Bean (EJB2.0) POJO (EJB3.0)
Ratings of Data Persistence Methods
Goal JDBC EJB/BMP EJB/CMP JDO O/R Tool
Min Learning curve High Low Low Medium Medium
Min Code and configuration
Low Low Low Medium Medium
Max Ability to tune High Medium Low Low Low
Min Deployment effort High Low Low Medium Medium
Max Code portability Medium Medium High High High
Min Vendor reliance High Medium Medium Medium Low
Max Availability and fail-over
Low High High Low Low
Manageable via JTA Yes Yes Yes Yes Yes
Data Access Object Layer
Encapsulate data access and manipulation in a separate layer DB CRUD, File, XML, FTP Server, Mail Server ...
1:1 correspondence between VO and DAO Traditional JDBC DAO vs. Spring DAO Bean
Aspect-oriented programming (AOP) Cross-cutting concerns
Inverse of Control (IOC)
Business Logic Layer
Manages business processing rules and logic Maximize the possibility of reuse Access Business Objects (BO) via Service Locator
(Pattern) Stateless Session Bean vs. Spring Bean Fast Lane Reader (Pattern)
A more efficient way to access tabular, read-only, potentially stale data
Transfer Object (Pattern) Carry any multiple data elements across a tier Previously known as Value Object (is not Pattern) ?
Deployment Layer
Publishes business object capabilities Web Server (e.g. Tomcat) acted business
client, Application Server (e.g. Weblogic) acted business server
Remote session bean, Message-driven bean, RMI service, Web service, CORBA service ...
Features of Deployment Wrapper Types
Feature EJB Web Service
JMS RMI HTTP CORBA
Caller platform requirements
Java-complaint only
Any Any Java-complaint only
Any Any
Communication method supported
Synch. only Both Both Synch. only Synch. only
Synch. only
Coupling Tight Loose Loose Tight Loose Loose
Transaction support
Local and JTA Local and JTA Local Local Local Local
Requires J2EE container?
Yes No No No No No
Supports clustering for scalability and availability?
Yes Yes Yes No Yes Yes
Business Delegate Layer
Hide clients from the complexity of remote communication with business service components
Service Locator (Singleton) Transparently locate business components and
services in a uniform manner Class BeanFactoryLocator or
ApplicationContext of Spring Context
Presentation Layer
Controls display to the end user Servlet 2.4 & JSP 2.0 Servlet & Java Bean (View Object) JSP & Tag library JavaScript & DHTML & CSS
Asynchronous JavaScript And XML (AJAX)
AJAX
Only reload some part and difference of web page each time the user requests a change
A implementation of design style, not a framework
Consists of HTML, JavaScript, DHTML, and DOM, is an outstanding approach
Help you to transform clunky Web interfaces into interactive AJAX applications
AJAX Web or AJAX Application ?
Table Schema structure and Domain Object design
User-centric Tables & Classes ER Diagram Class Diagram
Table per subclass User, Supervisor, Member MemberFeed, SubscribeFeed, FavoriteFeed, Recomme
ndFeed, BackupFeed 1:1 Lazy initialization between Member and Memb
erProfile Nested MemberFolder
Tree structure 4 default folders per member
Feed-centric Tables & Classes ER Diagram Class Diagram
Nested FeedCategory Tree structure
Nested RecommendReply Tree structure While malicious of Reply == true, this reply would be removed from u
ser’s view FeedRecommend
While malicious of Recommend == true, this reply would be removed from user’s view
FeedTagCase between PublicFeed and FeedTag FeedVote between PublicFeed and User RecommendVote between FeedRecommend and User M:M between FeedTag and FeedRecommend
Mail-centric Tables & Classes ER Diagram Class Diagram
OutMail & InMail While trashed of OutMail == true, this mail would be rem
oved from sender’s view While trashed of InMail == true, this mail would be remo
ved from receiver’s view While one trashed of OutMail == true and trashed of it’s I
nMails == true simultaneously, these mails will be deleted from database
My Space-centric Tables & Classes ER Diagram Class Diagram
MySpaceSetting between MySpace and MySpaceChoice
MySpaceAnswer between MySpace and MySpaceQuestion
1:1 Lazy initialization between MemberProfile and MySpace
Access Control-centric Tables & Classes ER Diagram Class Diagram
Table per class hierarchy AccessControl, UserControl, RoleControl, GroupControl AccessRule, SupervisorRule, MemberRule
Nested Group Tree structure
M:M between Role and User M:M between Group and User Access Rule
Priority UserControl > RoleControl > GroupControl Resolves conflicts when the same type of AccessControl are
assigned
Forum-centric Tables & Classes ER Diagram Class Diagram
Nested TopicReply Tree structure While malicious of Reply == true, this reply would be re
moved from user’s view Topic Watch
Update last replied time when user replies Between User and ForumTopic
Look from Top-Down, Carry out from Bottom-Up
Ready for APIs & Components I User Authenticator
Related Tables & Classes User-centric
Login & Logout Cookie mechanics Password Digester Random 12-characters Password Generator
Ready for APIs & Components II eSobi Feed Subscriber
Related Tables & Classes User-centric Feed-centric
Public Feed count & Member Feed record eSobi Feed Recommender
Related Tables & Classes User-centric Feed-centric
Ready for APIs & Components III eSobi Folder Backup
Related Tables & Classes User-centric Feed-centric
eSobi Folder Restorer Related Tables & Classes
User-centric Feed-centric
Ongoing for APIs & Components I Data Migration
Old data is migrated to the new schema Data List Handler
A pattern for Large Search Result Sets Paging Controller applied to web page
RSS Parser Parse RSS XML to find information of feed
User Authorizer According to Access-Controls to find Access-Rules
Mail Carrier
Java Naming Convention
According to Java Bean convention Attribute firstly, Getter method secondly, Sett
er method lastly Collection-type Attribute, add extra Adder and
Remover method Convenient findXXXByZZZ method
SQL Syntax Convention
Statement Spells SQL keywords in upper case SQL statements are often broken into multiple
lines Table & Column name
Primary key should be the table name suffixed with "_id“
Separate words and prefixes with underlines, never use spaces
Logging Service Convention
Replace System.out / System.err println with Logger
Level warning & error & fatal on Production machine
Level trace & debug & info on SIT / UAT machine
Logging necessary messages about our logic. if log.isXXXEnabled, then log.XXX message
Centralized Controlling & Distributed Computing There’s no need to reinvent the wheel
Open Source Community Bitter design vs. Appropriate design
J2EE Pattern & GoF Pattern Hard code vs. Sophisticated Algorithm
Tree traverse method Universal entry between up-tier and down-tier
e.g. Service Locator & Session Façade Divide and conquer inside the same tier
Concurrent Access Risk
Deadlock while insert & update concurrently Dirty columns of table for performance gain AJAX seems delicious, but ...
Performance Issue & Tuning
High availability & High scalability Clustering & Load Balancing Fail Over & Session Persistence
Code Refactoring SQL statement (DAO) Tuning Business Logic (BO) Tuning Cached Result Page
Event-Driven: JMS (Synchronous) Scheduling: Quartz (Asynchronous)
Database Refactoring Re-Index on Tables Database Trigger Database Stored Procedure
Test-driven development
Planning Release planning creates the schedule Make frequent small releases The project is divided into iterations Iteration planning starts each iteration
Designing Simplicity Choose a system metaphor Refactoring whenever and wherever possible
Test-driven development
Coding Code must be written to agreed standards Integrate often Use collective code ownership Leave optimization till last
Testing All code must have unit tests All code must pass all unit tests before release When a bug is found tests are created Acceptance tests are run often
Reference
Core J2EE Patterns J2EE Patterns Catalog GoF Patterns AJAX Patterns Java Naming Convention Essential Database Naming Conventions SQL Syntax Conventions Extreme Programming
Q&A