Distributed Computing
and Java™
Sang Shin
Java™ Technology Evangelist
sang.shin@sun.com
Topics
Overview of Distributed computing
Java APIs for distributed computing
JDBC
RMI
Java IDL (Corba)
Java Servlets and JSP
J2EE™
Jini™ Network Technology and
JavaSpaces (We will learn from next week)
2
Objectives
Understand the value of distributed
computing (network computing)
Get some exposure to the evolution of
distributed computing
Understand the 7 fallacies of
distributed computing
Get some exposure to distributed
computing technologies of Java
3
Overview of
Distributed Computing
(Network Computing)
Virtual Fish Tank
“Most people grow up with a 'centralized
mindset,' assuming that organized patterns can
be created only by centralized control. The VFT
exhibit helps people move beyond the
centralized mindset, giving them a chance to
create and participate in an artificial ecosystem
-- and learn how patterns can, in fact, arise from
decentralized interactions.”
- Michael Resnick, MIT Media Lab
5
Waves of Embedded
Things - 1014
Computers
Network Computing 1011 Thermostats
Cars
Switches
Computers TVs
Packages
108 Phones
Games Clothes
Desktops
Clients
Functions Transfers Transactions Content Telemetry
Control IP v4 IP Layer IP v6
Protocols
Organization
Waves of Embedded
Things - 1014
Computers
Network Computing 1011 Thermostats
Cars
Switches
Computers TVs
Packages
108
Phone
s Games Clothes
Desktops
Clients
Functions Transfers Transactions Content Telemetry
Control IP v4 IP Layer IP v6
Protocols FT SMTP
T
Pelnet RPC/XDR
X RMI/IIOP
LDAP SOAP Identity
Organization HTTP
Client/Server Jini
UDDI JXTA
N-tier Web Applications
Web Polyarchical
Services
Fractal
Platform Evolution
The Network The Computer Network of
Catch Is the Legacy to Is the Embedded Network
Phrase Computer Objects the Web Network Things of Things
Scale 100s 1,000s 1,000,000s 10,000,000s 100,000,000s 100,000,000
s
When/Peak 1984/1987 1990/1993 1996/1999 2001/2003 1998/2004 2004/2007
Leaf +HTTP +XML +RMI Unknown
X X
Protocol(s) (+JVM) Portal
+UDDI +Jini
Directory(s) NS, NS+ +CDS +LDAP(*) +ebXML Lookup +?
reg/rep service
Session RPC, XDR +CORBA +CORBA, +SOAP, +RMI/Jini +?
RMI XML
Schematic
Design Patterns
Client- Web Web Hybrid
Server 3-Tier Application Services P2P Fractal
Three Laws of Computing
Moore's Law
Computing power doubles every 18
months
Gilder's Law
Network bandwidth capacity doubles
every 12 months
Metcalfe's Law (Net Effect)
Value of network increases
exponentially as number of
participants increases
10
Current Enterprise Reality
Video
Web Server Solaris™
Telco Server
Server Workstation
Pager
Public Firewall
Corporate
Internet Internet
Thin Client
Cell Phone
NT
Thin Client Solaris Workstation
Workgroup
Workstation Server
PDA
11
What is a distributed system?
A collection of processes/processors
that do not share memory or a clock
12
Why Distributed Systems?
Resource sharing
Higher performance
Flexible
Reliable
Scalable
Cheaper
Manage’able (it depends)
13
Characteristics of Distributed
Systems
Complex programming
Heterogeneous
Hardware, OS, networking behavior,
object model, programming language
Inherent problems
Network latency
Concurrency issues
Partial Failure
14
7 Fallacies of Distributed
Computing
The network is reliable
Latency is zero
Bandwidth is infinite
The network is secure
Topology doesn't change
There is one administrator
Transport cost is zero
15
Terminology
Naming and Transparency
Location transparency
Location Independence
Stateful vs. Stateless
Failure Detection and Recovery
Replication
Log based Recovery
Parameter Marshaling/Unmarshaling
16
Distributed Coordination
Mutual Exclusion
Atomicity
Concurrency Control
Deadlock Handling
Election Algorithms
Transaction
2 phase commit
17
Distributed Systems
Evolution
RPC ORB RMI
(procedural) (object based) (object oriented)
80s 90s
18
Early Distributed Systems
RPC
DCE, ONC
Distributed File Systems
example - NFS, SMB
Databases
example - Oracle
Transaction Processing Monitors
example - CICS
19
At the root of it all ...
Sockets
Socket, ServerSocket, SocketImpl classes
Uses
Data compression
multicast
custom protocols, etc.
20
JDBC
What is JDBC?
Java APIs for manipulating relational
databases
Uses standardized SQL
22
JDBC Architecture
Java application Java application
JDBC API
JDBC Driver Manager
SPI
Bridge Sybase DB2 Oracle
ODBC driver driver driver
MS SQL Sybase DB2 Oracle
23
A 2-tier Example
JDBC
Front
end Database
Front
end
Front Database
end
24
JDBC Status
Core API in JDK 1.1 onwards
JDBC 3.0 Core and Extension API
currently available
JDBC drivers available for wide-range
relational databases
25
JDBC Resources
Java Packages
java.sql
javax.sql
Websites
java.sun.com/products/jdbc
Books
DatabaseProgramming with JDBC and
Java by George E. Reese, George H.
Reese
26
RMI
(Remote Method Invocation)
What is RMI?
New Distributed system paradigm
Naturalextension of the OO paradigm
Seamless integration of objects (objects
everywhere)
Allows method invocation across JVM
boundaries
Can pass or receive objects to/from
remote object
Code moves with the object (code movement)
Distributed garbage collection
Activation 28
A 3-tier Example
RMI JDBC
Front
end Database
Front Business Logic
end
Front Database
end
29
RPC Architecture (General)
Client Wire Server
Proxy Proxy
The proxies deal with parameter
marshaling/unmarshaling
30
RMI Architecture
Java Java
Client Server
JRMP
Stub Skeleton
The Stubs/Skeletons deal with
Serializing/De-serializing
31
Class Loading
RMI loads classes if not available
locally
Remote object, stub, skeleton, parameter
and return value classes
Loaded classes subject to installed
security manager
Remote Reference + stub code
Lookup
Server
Client
32
Object Serialization
Used for passing objects by value
Write/read objects and graphs of objects
Lightweight Persistence
Objects are converted into byte streams
Customization on a per-class basis is
possible
33
RMI Development Process
Four step development
Define the interfaces to your remote
objects
Implement the remote objects
Run rmic on remote implementation
classes
Make code network-accessible
34
RMI Deployment
rmiregistry
Provides a bootstrap service to locate the
first server object
Start the server
Start the client
35
RMI Status
Core since JDK 1.1
New Features in JDK 1.2
Activation
Custom socket types
API enhancements
Performance improvements
36
Customer Feedback
Many customers like RMI:
Easy to program
No need to learn separate IDL
Supports full Java programming language
semantics (value objects)
Ideal for communication between Java
applications
37
Customer Feedback (Cont’d)
Many customers like CORBA:
Standardizing on CORBA IDL and IIOP
Multi-vendor
Cross-language
Allowscommunication between Java
applications and C++
Common input: Why not RMI over
IIOP?
38
RMI over IIOP
RMI over IIOP supports a large subset
of JDK 1.1 RMI API over CORBA IIOP
Joint work between: IBM, Netscape,
Oracle, Sun, Visigenic
With input from many other partners
39
RMI over IIOP
40
RMI over IIOP (Simplified)
Java Any
Client Server
ORB IIOP ORB
The ORBs deal with parameter
marhalling/unmarshalling
41
RMI over IIOP Features
True subset of RMI over JRMP
Uses CORBA objects-by-value
extension
Allows genuine interoperability with
C++ and other languages
RMI over IIOP combines:
RMI style ease of use plus cross-language
interoperability
No Distributed Garbage Collection
42
What is Java IDL
Java IDL
Uses OMG's Java Language Mapping
Layered on Internet Inter ORB Protocol
(IIOP)
Generates Portable Stubs/Skeletons
43
Java IDL Development
44
Java IDL runtime
45
XML
What Is XML?
eXtensible Markup metaLanguage
Universal Data description
mechanism
Language Description Pros cons
SGML Language for Complete Complex
describing and
documents extensible
HTML HyperText Simple Focus on
Markup rendering;
Language Not Extensible
XML eXtensible Simple, Need other
Markup extensible technologies
metaLanguage in conjunction
47
XML and Java Technology
Complementary technologies
XML is portable reusable data
Java Technology is portable behavior
Both are Web-friendly, open, vendor
neutral, Unicode support
48
What is Needed?
XML “Basic Plumbing” classes:
Ability to parse XML:
Parser(s)
SAX
DOM
Namespaces
Support in parser(s)
49
XML Schema
XML = Data without syntax?
Schemas specifies syntax of XML
document
DTD
XML schema
50
J2EE
What Is the Java™ 2 Platform,
Enterprise Edition (J2EE)?
Open and standard based platform
for
developing, deploying and managing
n-tier, Web-enabled, server-centric
enterprise applications
52
The Java™ 2 Platform
Java Technology Java Technology Workgroup High-End
Enabled Devices Enabled Desktop Server Server
53
What Do You Get from J2EE?
API and Technology specifications
Development and Deployment
Platform
Reference implementation
Compatibility Test Suite (CTS)
J2EE BluePrints
54
J2EE 1.3APIs and Technologies
Version
Java 2 SDK, Standard Edition 1.3
RMI/ IIOP 1.0
JDBC™ 3.0
Java Messaging Service 1.0.2b
JNDI 1.2.1
Servlet 2.3
JavaServer Pages™ 1.2
JavaMail 1.2
JavaBeans™ Activation Framework 1.0.1
Enterprise JavaBeans 2.0
Java Transaction API 1.0.1
Java Transaction Service 1.1
Connector Architecture 1.0
ECPerf™ 1.0
55
What is EJB Technology?
Cornerstone of J2EE
A server-side component technology
Easy development and deployment of
Java technology-based application
that are:
Transactional,distributed, multi-tier,
portable, scalable, secure, …
56
Why EJB Technology?
Leverages the benefits of component-
model on the server side
Separates business logic from system
code
Provides framework for portable
components
Over different J2EE-compliant servers
Over different operational environments
Enables deployment-time configuration
Deployment descriptor
57
EJB Architecture
58
What is a Servlet?
Java™ objects which extend the
functionality of a HTTP server
Dynamic contents generation
Better alternative to CGI, NSAPI,
ISAPI, etc.
Efficient
Platformand server independent
Session management
Java-based
59
Servlets vs. CGI
Request CGI1
Child for CGI1
Request CGI2 CGI
Based Child for CGI2
Webserver
Request CGI1
Child for CGI1
Request Servlet1
Servlet Based Webserver
Request Servlet2 Servlet1
JVM
Request Servlet1 Servlet2
60
Code for a Simple Servlet
01 public class ExampleServlet extends HttpServlet {
02 public void doGet(HttpServletRequest request,
03 HttpServletResponse response)
04 throws ServletException, IOException
05 {
06 response.setContentType(“text/html”);
07 PrintWriter out = response.getWriter();
08 out.println(“Good Day USA!<BR>”);
09 Date rightNow = new Date();
10 out.println(“The time is: “ + rightNow);
11 }
12 }
61
What is JSP Technology?
Enables separation of business logic
from presentation
Presentation is in the form of HTML or
XML/XSLT
Business logic is implemented as Java
Beans or custom tags
Better maintainability, reusability
Extensible via custom tags
Builds on Servlet technology
62
Big Picture
HTML/XML
HTTP(S)
Client
63
Servlets and JSP - Comparison
Servlets JSP
HTML code in Java-like code in
Java HTML
Any form of Data Structured Text
Not easy to author Very easy to author
Underlying Code is compiled
semantics into a servlet
64
JTS/JTA (Transaction
Processing)
Distributed transaction processing
JTS: Mapping to CORBA Object
Transaction Service (OTS)
Access to standard object transaction
coordination
Who: IBM, Inprise, Bull, WebLogic
JTA: API for transactions
Javainterface to transactional systems
Who: Transaction/DB server vendors
65
•JNDI (Naming and Directory)
JNDI: Java Naming and Directory
Unified field theory for naming
LDAP, NIS, NIS+, DNS, File, etc.
Industry support
Benefits:
Single interface to enterprise network objects
Cross platform
66
JMS (Messaging and Pub/Sub)
JMS: Java Message Service API
Asynchronous communications
Publish and Subscribe
Reliable Queues
Guaranteed delivery
Benefits:
Single interface to MOM
Open and cross platform
Who: TIBCO, IBM, Modulus, Active
67
Java 2 Platform,
Enterprise Edition
API and Technology specifications
Development and Deployment
Platform
Reference implementation
Compatibility tests with branding
J2EE BluePrints
68
Platform Value to Developers
Unified platform
Choice of platform implementation
Performance
Scalability
Reliability
Manageability
Tools
Increased productivity
Portability of code
Ready-to-use security framework 69
J2EE is End-to-End Solution
Firewall J2EE
Application
Client Server
Enterprise
Enterprise Information
JavaBeans™
Client Systems (EIS):
Client Relational
Database,
Web Enterprise Legacy
Client Server JavaBeans Applications,
JSP, ERP Systems
Servlets
Client
HTML/XML
Other Services:
JNDI, JMS, Enterprise
Client Middle JavaMail™ Information
Tier Tier Tier
70
J2EE Containers & Components
Applet Container Web Container EJB Container
Applet HTTP/
HTTPS JSP Servlet RMI EJB
J2SE
RMI/IIOP
RMI/IIOP
JavaMail JavaMail
JDBC
JDBC
JMS
JTA
JNDI
JMS
JTA
JNDI
App Client JAF JAF
Container
App
Client
HTTP/
HTTPS J2SE
RMI
RMI/IIOP
JDBC
JNDI
JMS
J2SE J2SE
Database
71
Containers and Components
Containers Components
Handle Handle
Concurrency Presentation
Security Business Logic
Availability
Scalability
Persistence
Transaction
Lifecycle
management
Management
72
Lifecycle illustration
Creation Assembly Deployment
Created by Assembled
J2EE Modules and Augmented J2EE APP Processed
Component by Application by Deployer
Developer Assembler
Deploy
J2EE Container
Enterprise
Components
73
Java 2 Platform,
Enterprise Edition
API and Technology specifications
Development and Deployment
Platform
Reference implementation
Compatibility Test Suite (CTS)
J2EE BluePrints
74
What and Why a Reference
Implementation?
Validates specification
Fully-compliant
Fully-functional
Not commercial quality
Scalability
Performance
Use it for prototyping J2EE based
applications
75
Compatibility Test Suite (CTS)
Ultimate Java™ technology mission:
Write Once, Run Anywhere™
My Java-based application runs on any
compatible Java virtual machines
My J2EE based technology-based
application will run on any J2EE based
Compatible platforms
76
J2EE BluePrints
Best practice guidelines, design
patterns and design principles
MVC pattern
Covers all tiers
Clienttier
Web tier
Business logic (EJB) tier
Database access tier
Sample code
Java Pet Store
77
Summary
Java is unifying the fragmented
distributed systems arena
The ability to be able to move code
makes Java unique
Java is able to inter-operate with
legacy applications
78