3. Preface
In Java SE, we used to develop desktop applications. Now imagine the situation where
many desktops should be involved in a certain system; it's found in customer support
centers, modern retailer shops, eGov systems, eLearning systems, and so on. Those types of
systems consist of many computers connected together via a network, and all operating in
a central database, cooperating to form a single and concrete system. These systems are
called distributed systems.
1. Distributed Systems
A distributed system is a collection of computers connected together via a network, and
appear to the users as a single system. Different characteristics are common to all distributed
systems, including resource sharing, openness, concurrency, scalability, fault tolerance, and
transparency. The web is a common example for a distributed system.
Resource Sharing: in a distributed system, resources are used by many users and
computers in the network. So resources like files, printers, databases, and so on
should be shared. Resource sharing includes naming each resource in the system,
and provide it with a standardized interface to be accessed with.
Openness: Openness describes the ability of interacting with others. We use
openness term for describing one's ability of making communication with the
others. It's the same in distributed systems, openness describes system's ability for
interacting with other systems.
Concurrency: many users will access the system simultaneously, use resources
like files and databases in the same time. Concurrency is a property of a distributed
system describing its ability for managing many users access to resources
instantaneously.
Scalability: the ability of a distributed systems to adding new resources and users.
Fault Tolerance: computers fail! When a computer in a distributed system is down,
the distributed system should continue working and functioning properly.
Transparency: resources should be decoupled from the users. Users should be
able to access resources transparently without caring where the resource is actually
located in. Many users should access the same resource without taking in concern
that many other users may access the resource in the same time. In addition,
resources may be moved from a location to other while in use, without stopping the
system or notifying the users, where the component should continue working and
functioning properly. This's called transparency.
We're going to study distributed systems from two prescriptives:
• Application architecture.
• Application design.
3
4. 1.1. Application Architecture
A distributed system is a collection of computers connected together via a network. We have
studied client/server architecture (where the application is divided into two tiers: server tier
that provides a service, and a client tier that consumes the service) in two contexts: socket
programming in the ShoutBox application, and database programming when we used JDBC
API together with the JDBC driver to connect to a relational database server (PostgreSQL).
Most distributed systems are implemented in what's called Three-Tier architecture. Three-
Tier architecture is an extension to the client/server architecture where business data,
application processing, and presentation are separated from each other.
A common example is separating Database (business data), business logic (application
processing), and user interface (presentation) from each other. In other words, the database
is an independent subsystem, the business logic is an independent subsystem, and the user
interface is an independent subsystem, as well. Some issues should be concerned when
designing an application with such architectures:
Protocols as computers connect together, protocols should be defined. Most
protocols are too complex to implement and abstractions are needed.
Security as computers connect together, they are exposed to each others. Only
authenticated users should access the systems, and only authorized users should be
able to access resources. In addition, protocols may provide some type of security
by encrypting conversation using encryption techniques like public/private key.
1.2. Application Design
Most distributed systems are designed in what's called component-based model. The system
is composed of well-defined software components that are assembled together to form the
final system. The definition may seem similar to the object-oriented concept, but they differ.
A software component is a logical term describing a self-contained software unit that's
accessible using standard interfaces. A software component is different to software objects
in that software components are accessible within the scope of a distributed systems (i.e.
components can be accessed remotely), where software objects are accessible only within
the scope of single application (i.e. objects cannot be accessed remotely).
2. Middleware
As we just seen, distributed systems require heavy system programming. It's too complex
to build a distributed system; it requires too complex implementaiton of the system
architecture, communication protocols, t architecture, support to components, etc. In
addition, the purpose of the system target mainly the business itself (not the distributed
system), developers should focus on implementing the business logic itself, not the complex
distributed system requirements. Hence, the term middleware has been introduced.
A middleware is a class of software that's developed to manage a distributed system. It's
responsible for implementing the complex details of a distributed system, and providing a
4
5. virtual development platform of a single system with component-based model, that's actually
distributed over many computers.
You're (as the application developer) responsible only for developing software-components
and deploy them on the middleware, which will run them in managed environment of a
distributed computing model, providing them was all needed system services.
3. Java Enterprise Edition Platform
The Java EE is complete platform for developing multi-tiered distributed applications. It
consists of:
• The Java Virtual Machine (JVM).
• The Java SE APIs (SE APIs).
• The Java EE Application Server.
• The Java EE APIs (EE APIs).
As you must have noticed, the Java EE Platform consists of the Java SE Platform (JVM and
SE APIs), with two additions:
- The Java EE Application Server
A middleware that supports the distributed system. It implements the system
programming part of the distributed system, and provides a platform for
developing component-based applications that run in a managed environment.
- The Java EE APIs
5
6. A set of APIs that provides the common functionalities needed in enterprise
systems.
3.1. Application Architecture
In Java EE, applications are divided into four teirs: Enterprise Information System (EIS)
tier, business tier, web tier, and client tier.
3.1.1. EIS Tier
The Enterprise information system tier contains the enterprise information system
server that contains the data of the application. It is usually the Relational DBMS.
3.1.2 Business Tier
The Business tier contains business components where business logic is
2
implemented.
6
7. 3.1.3 Web Tier
3
The web tier contains web components that generate dynamic web pages over
hyper text transfer protocol (HTTP). Pages are accessed using the web browser,
that's known in Java EE as the thin client.
3.1.4 Client Tier
The client tier access system services. There are two variations of the client tier:
1. Swing Application: in case the client access the business components.
2. Web Browser: in case the client access the web components.
3.2. Application Design
In Java EE, applications are developed using a component-based model. The Java EE
platform provides different types of components that can be developed and deployed on the
application server. We will study two different types of components: business components
and web components.
3.2.1 Business Components
Business components (known as: Enterprise JavaBeans, or EJB in short) are
developed to implement business logic. EJBs are standard components that can be
4
accessed remotely using RMI . There're two types of EJBs:
- Session Beans.
- Message-Driven Beans.
3.2.2 Web Components
Web components are responsible for generating web pages and documents. There're
two types of Web components:
- Servlets.
- JSPs (JavaServer Pages).
2. Business logic includes processing data for operations like accounting, inventory, HR
management, and so on.
3. Web pages are usually HTML pages that are either static or dynamic. In case of static
web pages, content does not change and every time the browser visits the page it receives
the same content. Dynamic pages however, are created dynamically when the browser
request the page. The page is generated dynamically and the browser may receives
different content each time it visits the page.
4. Remote Method Invocation: a Java API for implementing remote procedure calls (RPCs).
7
8. 5
There are significant differences between Plain Old Java Objects (POJOS) and Java EE
components:
- Components are standardized.
Java EE components should implement certain interfaces, extend some class, or
following any other standard required by the specification to be certified as a
component in Java EE platform. Unlike POJOs, classes should not follow any certain
standard requirement.
- Components are managed by the Java EE Application Server.
Enterprise applications do not run by themselves as standalone applications,
instead, they should run in a managed environment provided by the Java EE
application server. Thus, components are developed and compiled, then deployed
on the Java EE application server. Application server then runs them in its managed
environment. Unlike POJOs, where we used to run the class with the main() method.
In other words, Java EE applications does not have main() method.
In addition, components are not accessed directly. The client tier access components
using standard interfaces. Unlike POJOs, where we used to access the object directly
using its reference. In other words, the application server acts as a service layer
between the client tier and other tiers.
- Components are not instantiated using new operator.
In distributed systems, components are not accessed directly. Instead, component
are named and located. When the developer deploys a component on the application
server, she gives the component a unique name. The client then asks the application
server to locate the component, and instantiate it for him, using its name.
In other words, the client does not instantiate the component, but the application
server is responsible for instantiating and returning a reference to the component
for the sake of the client.
- All components are developed for the sake of the client.
Take in concentration that the ultimate purpose of Java EE is to develop distributed
multi-tiered applications. Thus, all components are developed and deployed to
provide a service that's actually used by a consumer, the client.
Every EE application we are going to develop will has clients to access our developed
system. Either we will develop the client ourselves in case of Swing Application
clients, or the client will be the web browser in case of accessing web components.
5. The ordinary java objects we used to develop and use in Java SE applications.
8
9. 4. The Java EE Application Server
The Java EE application server is a specification by Sun Microsystems that describes
a middleware system. The system should provide a managed environment for Java EE
components, in addition to an implementation to the Java EE APIs. Java EE APIs are a
specification, as well.
Any system that implements the Java EE application server and Java EE APIs specification
is called Java EE application server, or application server in short. In fact, any vendor can
implement the specification, but should get certified first by Sun that her implemntation is a
valid application server.
There are dozens of application servers in the market. Here is a list of some application
servers and their vendors:
Application Server Vendor Type
Glassfish Sun Open Source/Free
JBoss RedHat Open Source/Free Edition
WebSphere IBM Open Source/Free Edition
OC4J ORACLE Commercial
We will use JBoss application server, that can be downloaded from: http://www.jboss.org/.
Your role, as the application developer, is to only develop Java EE components according to
the specification, then deploy them on the application server. Since both the components and
application servers are developed according to the specification, any Java EE application can
run on any Java EE application server, which is the sexiest property of the Java EE platform.
4.1. Runtime
The application server provides the runtime platform in the form of containers. A container
is a component of the application server that manages a specific type of components and
provide them with all the needed services and Java EE API implementaiton. We will study two
types of containers:
- Business Container
The business container is responsible for managing business components and
providing them with runtime services like: RMI communication, database
manipulation, transaction services, etc.
- Web Container
The web container is responsible for managing web components and providing them
with runtime services like: HTTP communication, database manipulation, etc.
9
10. 4.2. Services
The application server provides each container with a set of required services. The service is
implemented and supported to the application developer via Java EE APIs. Services include:
- Remote Method Invocation (RMI).
- HTTP (Hypertext transfer protocol).
- HTTPs (HTTP over SSL).
- Java Messaging Service (JMS). Supported via JMS APIs.
- Java Naming and Directory Interface. Supported via JNDI APIs.
- Distributed Transactions Management. Supported via Java Transactions APIs
(JTA).
- Java Database Connectivity. Supported via JDBC APIs.
- Persistence. Supported via Java Persistence API (JPA).
- Java Authentication and Authorization Service (JAAS).
4.3. Final Image - Java EE Architecture
10