Академический Документы
Профессиональный Документы
Культура Документы
Design v. Design
The distinction between designing applications and designing distributed applications is key; the technology is not.
Technologies provide the raw materials to build distributed systems, they are not distributed systems.
Examples: Sockets, ONC-RPC, DCE, CORBA, Java RMI, .NET, JMS, Java EE, Web Services
Factors: Availability
Defining availability Two perspectives host and application Uptime of a machine/software Accessible for use Nines How to describe the level of availability Percent the system is available (accumulative) Down Mon, Tue, Wed, Thu is bad 7.2 hours of planned maintenance and upgrades per month is okay
Availability (%) 90% 99% 99.9% 99.99% Down/Year 36.5 days 3.65 days 8.76 hrs 52.6 min Down/Month 72 hrs 7.2 hrs 43.2 min 4.32 min
99.999%
5.26 min
25.9 sec
Factors: Scalability
Scalability is the ability to allow more concurrent access to a service (resource) Scalability is not performance
Performance is how fast a request can be processed
Architecture solutions
Messaging, routing allows distribution of requests Clustering provides the ability to bring additional services online to support demand
Complexity
Additional servers increases the burdens to the infrastructure (people, power, floor space, cooling)
Designs (cont.)
Shard - a bladed architecture with no collective memory - truly independent.
Finding data is important if shards do not share databases Hops to find the data may be a performance issue Separation of data is a referential integrity (RI) defeating design breaks optimization and reduction of duplication of normal form database design
1. Application Servers
In the beginning, there was darkness and cold. Then,
mainframe terminals terminals
Centralized, non-distributed
Application Servers
In the 90s, systems should be clientserver
Application Servers
Today, enterprise applications use the multi-tier model
Application Servers
Multi-tier applications have several independent components An application server provides the infrastructure and services to run such applications
Application Servers
Application server products can be separated into 3 categories:
J2EE-based solutions Non-J2EE solutions (PHP, ColdFusion, Perl, etc.) And the Microsoft solution (ASP/COM and now .NET with ASP.NET, VB.NET, C#, etc.)
HTTP(S)
App Server 2
2. What is J2EE?
It is a public specification that embodies several technologies Current version is 3.x J2EE defines a model for developing multi-tier, web based, enterprise applications with distributed components
J2EE Benefits
High availability Scalability Integration with existing systems Freedom to choose vendors of application servers, tools, components Multi-platform
J2EE Benefits
Flexibility of scenarios and support to several types of clients Programming productivity:
Services allow developer to focus on business Component development facilitates maintenance and reuse Enables deploy-time behaviors Supports division of labor
Main technologies
JavaServer Pages (JSP) Servlet Enterprise JavaBeans (EJB)
JSPs, servlets and EJBs are application components
JSP
Used for web pages with dynamic content Processes HTTP requests (non-blocking calland-return) Accepts HTML tags, special JSP tags, and scriptlets of Java code Separates static content from presentation logic Can be created by web designer using HTML tools
Servlet
Used for web pages with dynamic content Processes HTTP requests (non-blocking call-andreturn) Written in Java; uses print statements to render HTML Loaded into memory once and then called many times Provides APIs for session management
EJB
EJBs are distributed components used to implement business logic (no UI) Developer concentrates on business logic Availability, scalability, security, interoperability and integrability handled by the J2EE server Client of EJBs can be JSPs, servlets, other EJBs and external aplications Clients see interfaces
JavaBean
POJO plus naming, metadata, and access rules
Getter/Setter methods:
void setName(String name) void setCool(boolean yes) String getName() boolean isCool()
Bean Info
JMS
Point-to-point
Destination is queue
JMS
Publish-subscribe
Destination is topic
Stop the JVM Native library access Override/Use object substitution features of the Java serialization API Directly read or write from/to a file descriptor (java.io) Use sockets Modify class loaders
Remote Interface
Remote interfaces can be used to invoke an
EJB across a network in a client-server fashion At minimum the interface must be annotated with @Remote either in the interface itself or in the bean class
@Remote public interface CalculatorRemote { public int sum(int add1, int add2); }
Local Interface
Local interfaces in EJB are pass-byreference interfaces. Meaning that normal java semantics are used Unless specified otherwise, every interface your bean implements is considered to be a local business interface
@Local public interface CalculatorLocal { public int sum(int add1, int add2); }
Types of EJB
EJB Taxonomy
EnterpriseBean
SessionBean Stateful EntityBean BMP MessageDrivenBean
Stateless
CMP
Session Bean
Stateless session bean:
Contains no user-specific data Business process that provides a generic service Container can pool stateless beans Example: shopping catalog New EJB 3.0 introduces a simplified declaration and lifecycle (e.g., no ejbCreate(),) Annotation: @Stateless Best for handling blocking requests, Instance pooling, timer capable, WS capable
Note: ejbCreate(), ejbRemove() are EJB 2.x methods that in EJB 3.x are replaced by lifecycle annotation
Stateless example
public interface EchoPoint extends Serializable { String echo(String what); }
@Local EchoPointLocal
@Remote EchoPointRemote
@Stateless public class EchoPointEJB implements EchoPointLocal, EchoPointRemote { public String echo(String what) { System.out.println("Echo: " + what); return what; } }
Session Bean
Stateful session bean:
Retains conversational state (data) on behalf of an individual client If state changed during this invocation, the same state will be available upon the following invocation Example: shopping cart EJB 3.0 simplified declaration and lifecycle methods (no ejbCreate(),) Annotation: @Stateful Best for mult-part (steps) input without persisting data between steps No pooling, not timer capable, not WS capable
Stateful passivation
Unlike stateless which can be limited to the number of instances (pooled), a stateless is created per client, which can create a memory burden on the server. The lifecycle includes passivation and activation of a stateful instance
Invoked when the server is experiencing heavy memory usage or the instance is idle for a period of time (configurable) Data contained in the instance is saved to disk or database A passivated object is activated before removing
@Local AccountCreatorLocal
@Remote AccountCreatorRemote
Annotation to indicate that once this method is called, the stateless EJB instance can be removed.
Latency not found in POJO/JavaBeans (single JVM). JEE changes how distributed services (objects) are designed
Fine grain access pattern
Singe JVM/Process
getFirstName()
Requesting Object
Application space ( single JVM): Access time per method ~0 msec Distributed space: The connection between the requestor and remote system introduces a tax (time and load) to marshal / unmarshal data and transmit across the network. Assume access time per method is ~1000 msec (example requires ~4000 msec per object)
EJB3.1 (JSR 318) proposes to remove the need to declare remote and local interfaces more POJO-like
Deployment Descriptors
XML file defining what is being deployed
Jars Declarative transaction statements for methods Security
Easy to use scheduling Provides scheduling through Single action timer expire once Interval timer - multiple After the timer expires, the container will call the ejbTimeout() method Annotation: @Timeout Specify a the callback method within a stateless or message beans Container invoked method Transactional - can rollback
Timer Example: http://www.java2s.com/Code/Java/EJB3/UseTimerService.htm
Entity Bean
Represents business data stored in a database persistent object Underlying data is normally one row of a table A primary key uniquely identifies each bean instance Allows shared access from multiple clients Can live past the duration of clients session Example: shopping order
Message-Driven Bean
Message consumer for a JMS queue or topic Benefits from EJB container services that are not available to standard JMS consumers Has no home or remote interface Example: order processing stock info
References
Tutorials and References
http://www.addsimplicity.com/adding_simplicity_an_engi/2008/08/shardlessons.html http://www.perfdynamics.com/Test/gcaprules.html http://java.sun.com/javaee/5/docs/tutorial/doc/
Books
Beginning EJB 3 Application Development, Kodali, et. al (2006) EJB3 In Action, panda, Rahman, Lane (2007) Pro EJB 3: Java Persistence API, Keith, Schincariol (2006)
Pattern Books
Java Enterprise Design Patterns, Grand (2002) Core J2EE Patterns 2nd Ed., Alur, Crupi, Malks (2003) EJB Design Patterns, Marinescu (2002)