| Contents | Previous | Next | Home | ||||||
|
|
||||||
| Abi Rajan resources on SCJA Module 2 | ||||||
|
|
||||||
|
Java Technology Architecture
Customer
Application
Consider:
The study of software architecture concerns itself
with achieving non-functional qualities (portability, scalability, performance,
modifiability, integrability, etc.) in large systems.
Software architectural analysis, in particular,
looks at how to analyze existing systems, or designed (but not yet built)
systems, with a view to predicting its non-functional qualities. Achieving
software quality through architecture level analysis
Two tier software architecture
The two tier design allocates the user system
interface exclusively to the client. It places database management on the
server and splits the processing management between client and server,
creating two layers.
Advantage of two tier architecture
Disdvantage of two tier architecture
Costs and Limitations
Scalability.
The two tier design will scale-up to service 100 users on a network. It
appears that beyond this number of users, the performance capacity is exceeded.
This is because the client and server exchange "keep alive" messages
continuously,
even when no work is being done, thereby saturating the network
Interoperability
. The two tier architecture
limits interoperability by using stored procedures to implement complex
processing logic (such as managing distributed database integrity) because
stored procedures are normally implemented using a commercial database
management system's proprietary language. This means that to change or
interoperate with more than one type of database management system, applications
may need to be rewritten. Moreover, database management system's proprietary
languages are generally not as capable as standard programming languages
in that they do not provide a robust programming environment with testing
and debugging, version control, and library management capabilities.
System administration and configuration
.
Two tier architectures can be difficult to administer and maintain because
when applications reside on the client, every upgrade must be delivered,
installed, and tested on each client. The typical lack of uniformity in
the client configurations and lack of control over subsequent configuration
changes increase administrative workload.
Batch jobs
. The two tiered architecture
is not effective running batch programs. The client is typically tied up
until the batch job finishes, even if the job executes on the server; thus,
the batch job and client users are negatively affected
The three tier software architecture
Isolation of concerns
A client may require data from a number of servers.
This can be handled easily because a Controller which automatically
splits the data operation request into several sub-operations. Each
sub-operation
is then performed by the appropriate data agent and the combined results
forwarded to the calling client.
Application Architecture Design
Applications, Servlets and CGI Scripts
What is a Servlet?
What is a Servlet Container?
A servlet container can either be built into a
host web server or installed as an add-on component to a Web Server via
that server’s native extension API. Servlet Containers can also be built
into or possibly installed into web-enabled Application Servers.
All servlet containers must support HTTP as a
protocol for requests and responses, but may also
In a Java 2 Platform Standard Edition 1.2 (J2SE)
or Java 2 Platform Enterprise Edition 1.2 (J2EE) environment, these restrictions
should be placed using the permission architecture defined by Java 2 Platform.
For example, high end application servers may limit certain action, such
as the creation of a Thread object, to insure that other components of
the container are not negatively impacted.
Java Servlets
provide web developers with a simple, consistent mechanism for extending
the functionality of a web server and for accessing existing business systems.
A servlet can almost be thought of as an applet that runs on the server
side -- without a face. Java Servlets have made many web applications possible.
Servlets are the Java platform technology of choice
for extending and enhancing Web servers. Servlets provide a component-based,
platform-independent method for building web-based applications, without
the performance limitations of CGI programs. And unlike proprietary server
extension mechanisms (such as the Netscape Server API or Apache modules),
Servlets are server- and platform-independent. This leaves you free to
select a "best of breed" strategy for your servers, platforms, and tools.
Written in Java, Servlets have access to the entire
family of Java APIs, including the JDBC API to access enterprise databases.
Servlets also access library of HTTP-specific calls, and all the benefits
of the mature Java language, including portability, performance, reusability,
and crash protection.
Today, Servlets are a popular choice for building
interactive web applications. Third-party Servlet containers are available
for Apache Web Server, iPlanet Web Server (formerly Netscape Enterprise
Server), Microsoft IIS, and others. Servlet containers can also be integrated
with web-enabled application servers, such as BEA WebLogic Application
Server, IBM WebSphere, Netscape Application Server, and others.
You might want to check out the latest information
on JavaServer Pages (JSP). JSP technology is an extension of the servlet
technology created to support authoring of HTML and XML pages. It makes
it easier to combine fixed or static template data with dynamic content.
Even if you're comfortable writing servlets, there are several compelling
reasons to investigate JSP technology as a complement to your existing
work.
Comparing Servlets with Other Technologies
The main performance hit in three-tier communication
is the trip between tiers one and two (imagine a user in Australia using
a browser to access an applet which is being downloaded from the UK, and
the server application and database live on a LAN situated in the UK).
HTTP is slow.
For an Internet / intranet / extranet based
application:
The advantage of deploying an application using
applets is that the user automatically gets the latest version of the
application
because a new copy is downloaded each time (there are settings on browsers
to change this policy). This clearly reduces client-side administration
drastically. If applications are chosen for tier one then these must
be kept up-to-date manually. The advantage of using applications
on tier one is that the applet security restrictions do not apply.
Applet security restrictions mean that untrusted applets cannot access
local hard disk or local print services and may not connect to any machine
other than that which it was downloaded from. Untrusted applets cannot
obtain information about the client platform and they cannot load client
libraries or DLLs. The cannot run any programs or scripts on the
client machine either. All JDK1.0 applets are untrusted. In
JDK1.1 and JDK1.2 applets may be signed, and signed applets may access
local hard disks and print services if the user chooses to trust them.
In JDK1.2 the concept of protection domains and policies is introduced,
whereby the user can assign a degree of trust to a particular class or
classes.
Tier Two Choices: Servlet, Application
If HTML forms (with or without JavaScript) are
employed in the first tier, these must communicate using HTTP to a Web
server on the second tier. The Web server may communicate with non-Java
code using, for example, CGI (Common Gateway Interface). CGI requests
are handled by creating a new process for each request, which takes up
considerable server resources, and severely limits the number of requests
which can be handled.
If applets are employed in the first tier, these
are initially downloaded using HTTP and then may connect back to a servlet
running within the Web server on tier two using RMI, or alternatively connect
back to an application running on tier two using RMI. Servlet requests
are handled in separate threads rather than separate processes, and so
use far less system resources than CGI requests. Consequently the
system can support many more servlet requests than CGI requests
Tier Three Choices:
The existence of legacy data often means there
is no choice on this tier. Java applications/servlets can interface
to a RDBMS (Relational DataBase Management System) using JDBC (it is possible
to obtain JDBC drivers for almost all RDBMSs from either the database vendor
or from a third-party vendors if the database vendor cannot supply one).
Non-Java programs (e.g. CGI programs) access RDBMSs using ODBC.
Object-oriented applications sitting on the third
tier can be accessed using CORBA (read about Java IDL), and non object
oriented applications sitting on the third tier can be accessed using sockets
(if a published interface exists).
Obviously, a Java application sitting on the third
tier can be accessed from the second tier using RMI if the second tier
app is Java.
Map names to network objects like you would use
a telephone directory. Naming services bind names to objects. A context
is a se of name-to-binding objects. A naming service lookup results in
the named object being retrieved based on its name. The process of using
a name to look up a named resource is called name resolution. Names can
be atomic (index.html), compound (/java/index.class) or composite
(http://ww.k.com/java/bu.class).
Directory services build upon naming services.
X.500, NDS and NIS are examples of Directory services of which NDS and
NIS are proprietary. LDAP was created as a front end for X500 directory
services but has replaced it on many servers. It is non-proprietary, runs
over TCP/IP and is a manageable subset of X.500. version 3 is current.
X.500 is for large directory services on WANs and LDAP is suited to large
enterprises. X.500 requires the use of the higher-level OSI protocol layers;
LDAP works over TCP/IP JNDI is an API for developing
naming and directory service clients that work with multiple naming and
directory services such as LDAP and NIS+ JMAPI provides an integrated solution
for system, network and service management of distributed systems. Java
is suitable due to the heterogeneous state of distributed systems.
Communication Protocols in a Three-Tier Architecture
HTTP, RMI, IIOP, JDBC, JDBC – DBC
(See module 1 also)
The different methods of tier-to-tier communication
are RMI (Remote Method Invocation), IIOP (Internet Inter-ORB Protocol),
RPC (Remote Procedure Call) and Sockets.
RMI
: (Java app to Java app), runs
over Java Remote Method Protocol (JRMP)
Both RMI and IIOP are object oriented: object
call to method on another object. With RMI the return values and
parameters are objects. With IIOP the return values and parameters
are structures. With RPC the return values and parameters are
structures.
RMI and CORBA are usually implemented on top of RPCs or sockets.
There are different communication models between
the tiers:
Asynchronous communication
: Publish/subscribe
model (based on events - like the JDK1.1 event model) Calling application
just carries on processing after making a request. An example of
this is message queuing. This model is not compromised by the network
being temporarily unavailable.
Synchronous communication
: Calling application
waits for a response to its request before continuing. This type
of communication requires the network to be available.
Conversationalcommunication
: Calling
application can either wait for a reply before continuing processing, or
carry on without waiting. This type of communication also requires
the network to be available.
Remote Method Invocation (RMI)
Remote Method Invocation (RMI) enables the programmer
to create distributed Java technology-based to Java technology-based
applications,
in which the methods of remote Java objects can be invoked from other Java
virtual machines, possibly on different hosts. A Java technology-based
program can make a call on a remote object once it obtains a reference
to the remote object, either by looking up the remote object in the
bootstrapnaming service provided by RMI or by receiving the reference as an
argument
or a return value. A client can call a remote object in a server, and that
server can also be a client of other remote objects. RMI uses object
serialization
to marshal and unmarshal parameters and does not truncate types, supporting
true object oriented polymorphism.
RMI applications are often comprised of two separate
programs: a server and a client. A typical server application creates some
remote objects, makes references to them accessible, and waits for clients
to invoke methods on these remote objects. A typical client application
gets a remote reference to one or more remote objects in the server and
then invokes methods on them. RMI provides the mechanism by which the server
and the client communicate and pass information back and forth. Such an
application is sometimes referred to as a distributed object application.
Distributed object applications need to
( To add fig rmi later)
Advantages of Dynamic Code Loading
One of the central and unique features of RMI
is its ability to download the bytecodes (or simply code) of an object's
class if the class is not defined in the receiver's virtual machine. The
types and the behavior of an object, previously available only in a single
virtual machine, can be transmitted to another, possibly remote, virtual
machine. RMI passes objects by their true type, so the behavior of those
objects is not changed when they are sent to another virtual machine. This
allows new types to be introduced into a remote virtual machine, thus extending
the behavior of an application dynamically. The compute engine example
in this chapter uses RMI's capability to introduce new behavior to a distributed
program.
Like any other application, a distributed application
built using Java RMI is made up of interfaces and classes.
The interfaces define methods, and the classes
implement the methods defined in the interfaces and, perhaps, define additional
methods as well. In a distributed application some of the implementations
are assumed to reside in different virtual machines. Objects that have
methods that can be called across virtual machines are remote objects.
An object becomes remote by implementing a remote
interface, which has the following characteristics.
A stub for a remote object implements the same
set of remote interfaces that the remote object implements. This allows
a stub to be cast to any of the interfaces that the remote object implements.
However, this also means that only those methods defined in a remote interface
are available to be called in the receiving virtual machine.
RMI provides a simple and direct model for distributed
computation with Java objects. These objects can be new Java objects, or
can be simple Java wrappers around an existing API. Java embraces the "Write
Once, Run Anywhere model. RMI extends the Java model to be run everywhere."
Because RMI is centered around Java, it brings
the power of Java safety and portability to distributed computing. You
can move behavior, such as agents and business logic, to the part of your
network where it makes the most sense. When you expand your use of Java
in your systems, RMI allows you to take all the advantages with you.
RMI connects to existing and legacy systems using
the standard Java native method interface JNI. RMI can also connect to
existing relational database using the standard JDBC? package. The RMI/JNI
and RMI/JDBC combinations let you use RMI to communicate today with existing
servers in non-Java languages, and to expand your use of Java to those
servers when it makes sense for you to do so. RMI lets you take full advantage
of Java when you do expand your use.
Advantages
Object Oriented:
RMI can pass full objects
as arguments and return values, not just predefined data types. This means
that you can pass complex types, such as a standard Java hashtable object,
as a single argument. In existing RPC systems you would have to have the
client decompose such an object into primitive data types, ship those data
types, and the recreate a hashtable on the server. RMI lets you ship objects
directly across the wire with no extra client code.
Mobile Behavior
: RMI can move behavior
(class implementations) from client to server and server to client. For
example, you can define an interface for examining employee expense reports
to see whether they conform to current company policy. When an expense
report is created, an object that implements that interface can be fetched
by the client from the server. When the policies change, the server will
start returning a different implementation of that interface that uses
the new policies. The constraints will therefore be checked on the client
side-providing faster feedback to the user and less load on the server-without
installing any new software on user's system. This gives you maximal
flexibility,
since changing policies requires you to write only one new Java class and
install it once on the server host.
Design Patterns:
Passing objects lets you
use the full power of object oriented technology in distributed computing,
such as two- and three-tier systems. When you can pass behavior, you can
use object oriented design patterns in your solutions. All object oriented
design patterns rely upon different behaviors for their power; without
passing complete objects-both implementations and type-the benefits provided
by the design patterns movement are lost.
Safe and Secure:
RMI uses built-in Java
security mechanisms that allow your system to be safe when users downloading
implementations. RMI uses the security manager defined to protect systems
from hostile applets to protect your systems and network from potentially
hostile downloaded code. In severe cases, a server can refuse to download
any implementations at all.
Easy to Write/Easy to Use
: RMI makes it
simple to write remote Java servers and Java clients that access those
servers. A remote interface is an actual Java interface. A server has roughly
three lines of code to declare itself a server, and otherwise is like any
other Java object. This simplicity makes it easy to write servers for full-scale
distributed object systems quickly, and to rapidly bring up prototypes
and early versions of software for testing and evaluation. And because
RMI programs are easy to write they are also easy to maintain.
Connects to Existing/Legacy Systems
: RMI
interacts with existing systems through Java's native method interface
JNI. Using RMI and JNI you can write your client in Java and use your existing
server implementation. When you use RMI/JNI to connect to existing servers
you can rewrite any parts of you server in Java when you choose to, and
get the full benefits of Java in the new code. Similarly, RMI interacts
with existing relational databases using JDBC without modifying existing
non-Java source that uses the databases.
Write Once, Run Anywhere
: RMI is
part of Java's "Write Once, Run Anywhere" approach. Any RMI based system
is 100% portable to any Java Virtual Machine*, as is an RMI/JDBC system.
If you use RMI/JNI to interact with an existing system, the code written
using JNI will compile and run with any Java virtual machine.
Distributed Garbage Collection:
RMI uses
its distributed garbage collection feature to collect remote server objects
that are no longer referenced by any clients in the network. Analogous
to garbage collection inside a Java Virtual Machine, distributed garbage
collection lets you define server objects as needed, knowing that they
will be removed when they no longer need to be accessible by clients.
Parallel Computing:
RMI is multi-threaded,
allowing your servers to exploit Java threads for better concurrent processing
of client requests.
The Java Distributed Computing Solution
:
RMI is part of the core Java platform starting with JDK? 1.1, so it exists
on every 1.1 Java Virtual Machine. All RMI systems talk the same public
protocol, so all Java systems can talk to each other directly, without
any protocol translation overhead.
Architecture Overview
Object Naming and Locating
Overview of the Architecture
|