?? chap15.htm
字號:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<!--
This document was converted from RTF source:
By rtftohtml 4.19
See http://www.sunpack.com/RTF
Filename:TIJ2.rtf
Application Directory:C:\TOOLS\RTF2HTML\
Subject:
Author:Bruce Eckel
Operator:Bruce Eckel
Document Comments:
Version Comments:
Comments:
Keywords:
Translation Date:05/21/2001
Translation Time:10:39:29
Translation Platform:Win32
Number of Output files:23
This File:Chap15.htm
SplitDepth=1
SkipNavPanel=1
SkipLeadingToc=1
SkipTrailingToc=1
GenContents=1
GenFrames=1
GenIndex=1
-->
<HEAD lang="en"><META http-equiv="Content-Type" content="text/html">
<TITLE>15: Distributed Computing</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF"><DIV ALIGN="CENTER">
<a href="http://www.MindView.net">
<img src="mindview.gif" alt="MindView Inc." BORDER = "0"></a>
<CENTER>
<FONT FACE="Verdana" size = "-1">
[ <a href="README.txt">Viewing Hints</a> ]
[ <a href="RevHist.htm">Revision History</a> ]
[ <a href="http://www.mindview.net/Books/TIJ/">Book Home Page</a> ]
[ <a href="http://www.mindview.net/Etc/MailingList.html">Free Newsletter</a> ] <br>
[ <a href="http://www.mindview.net/Seminars">Seminars</a> ]
[ <a href="http://www.mindview.net/CDs">Seminars on CD ROM</a> ]
[ <a href="http://www.mindview.net/Services">Consulting</a> ]
</FONT>
<H2><FONT FACE="Verdana">
Thinking in Java, 2nd edition, Revision 12</FONT></H2>
<H3><FONT FACE="Verdana">©2000 by Bruce Eckel</FONT></H3>
<FONT FACE="Verdana" size = "-1">
[ <a href="Chap14.htm">Previous Chapter</a> ]
[ <a href="SimpCont.htm">Short TOC</a> ]
[ <a href="Contents.htm">Table of Contents</a> ]
[ <a href="DocIdx.htm">Index</a> ]
[ <a href="AppendA.htm">Next Chapter</a> ]
</FONT>
</CENTER>
</P></DIV><A NAME="Chapter_17"></A><A NAME="_Toc375545491"></A><A NAME="_Toc477690735"></A><A NAME="_Toc481064866"></A><A NAME="Heading510"></A><FONT FACE = "Verdana"><H1 ALIGN="LEFT">
15: Distributed Computing</H1></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia" SIZE=4><backtalk:display ID=TIJ3_CHAPTER15_I0>
Historically,
programming across multiple machines has been error-prone, difficult, and
complex.</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">The programmer had to know many details
about the network and sometimes even the hardware. You usually needed to
understand the various “layers” of the networking protocol, and
there were a lot of different functions in each different networking library
concerned with connecting, packing, and unpacking blocks of information;
shipping those blocks back and forth; and handshaking. It was a daunting task.
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I0'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I1>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">However, the basic idea of distributed
computing is not so difficult, and is abstracted very nicely in the Java
libraries. You want to:</FONT><BR></P></DIV>
<UL>
<LI><FONT FACE="Wingdings"> </FONT><FONT FACE="Georgia">Get some information
from that machine over there and move it to this machine here, or vice versa.
This is accomplished with basic network programming.
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I1'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I2>
</FONT><LI><FONT FACE="Wingdings"> </FONT><FONT FACE="Georgia">Connect
to a database, which may live across a network. This is accomplished with
<I>Java DataBase Connectivity</I> (JDBC), which is an abstraction away from the
messy, platform-specific details of SQL (the <I>structured query language</I>
used for most database transactions).
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I2'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I3>
</FONT><LI><FONT FACE="Wingdings"> </FONT><FONT FACE="Georgia">Provide
services via a Web server. This is accomplished with Java’s
<I>servlets</I> and <I>Java<STRIKE> </STRIKE>Server Pages</I> (JSPs).
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I3'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I4>
</FONT><LI><FONT FACE="Wingdings"> </FONT><FONT FACE="Georgia">Execute
methods on Java objects that live on remote machines transparently, as if those
objects were resident on local machines. This is accomplished with Java’s
<I>Remote Method Invocation</I> (RMI).
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I4'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I5>
</FONT><LI><FONT FACE="Wingdings"> </FONT><FONT FACE="Georgia">Use
code written in other languages, running on other architectures. This is
accomplished using the <I>Common Object Request Broker Architecture</I> (CORBA),
which is directly supported by Java.
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I5'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I6>
</FONT><LI><FONT FACE="Wingdings"> </FONT><FONT FACE="Georgia">Isolate
business logic from connectivity issues, especially connections with databases
including transaction management and security. This is accomplished using
<I>Enterprise JavaBeans </I>(EJBs). EJBs are not actually a distributed
architecture, but the resulting applications are usually used in a networked
client-server system.
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I6'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I7>
</FONT><LI><FONT FACE="Wingdings"> </FONT><FONT FACE="Georgia">Easily,
dynamically, add and remove devices from a network representing a local system.
This is accomplished with Java’s Jini.
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I7'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I8>
</FONT></UL><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Each
topic will be given a light introduction in this chapter. Please note that each
subject is voluminous and by itself the subject of entire books, so this chapter
is only meant to familiarize you with the topics, not make you an expert
(however, you can go a long way with the information presented here on network
programming, servlets and JSPs).
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I8'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I9>
</FONT><A NAME="_Toc481064867"></A><BR></P></DIV>
<A NAME="Heading511"></A><FONT FACE = "Verdana"><H2 ALIGN="LEFT">
Network programming<A NAME="_Toc375545492"></A><BR><A NAME="Index2044"></A></H2></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">One of Java’s great strengths is
painless networking. The Java network library designers have made it quite
similar to reading and writing files, except that the “file” exists
on a remote machine and the remote machine can decide exactly what it wants to
do about the information you’re requesting or sending. As much as
possible, the underlying details of networking have been abstracted away and
taken care of within the JVM and local machine installation of Java. The
programming model you use is that of a file; in fact, you actually wrap the
network connection (a “socket”) with stream objects, so you end up
using the same method calls as you do with all other streams. In addition,
Java’s built-in multithreading is exceptionally handy when dealing with
another networking issue: handling multiple connections at once.
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I9'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I10>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">This section introduces Java’s
networking support using easy-to-understand examples.
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I10'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I11>
</FONT><A NAME="_Toc481064868"></A><BR></P></DIV>
<A NAME="Heading512"></A><FONT FACE = "Verdana"><H3 ALIGN="LEFT">
Identifying a machine</H3></FONT>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">Of course, in order to tell one machine
from another and to make sure that you are connected with a particular machine,
there must be some way of uniquely <A NAME="Index2045"></A>identifying machines
on a network. Early networks were satisfied to provide unique names for machines
within the local network. However, Java works within the Internet, which
requires a way to uniquely identify a machine from all the others <I>in the
world</I>. This is accomplished with the
<A NAME="Index2046"></A><A NAME="Index2047"></A><A NAME="Index2048"></A>IP
(Internet Protocol) address which can exist in two
forms<A NAME="Index2049"></A><A NAME="Index2050"></A>“<A NAME="Index2051"></A><A NAME="Index2052"></A>:
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I11'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I12>
</FONT><BR></P></DIV>
<OL>
<LI><FONT FACE="Verdana"> </FONT><FONT FACE="Georgia">The familiar DNS
(<I>Domain Name System</I>) form. My domain name is <B>bruceeckel.com</B>, and
if I have a computer called <B>Opus</B> in my domain, its domain name would be
<B>Opus.bruceeckel.com</B>. This is exactly the kind of name that you use when
you send email to people, and is often incorporated into a World Wide Web
address.</FONT><LI><FONT FACE="Verdana"> </FONT><FONT FACE="Georgia">Alternatively,
you can use the dotted quad” form, which is four numbers separated by
dots, such as
<B>123.255.28.120</B>.</FONT></OL><DIV ALIGN="LEFT"><P><FONT FACE="Georgia">In both
cases, the IP address is represented internally as a 32-bit
number</FONT><A NAME="fnB72" HREF="#fn72">[72]</A><FONT FACE="Georgia"> (so each
of the quad numbers cannot exceed 255), and you can get a special Java object to
represent this number from either of the forms above by using the <B>static</B>
<B>InetAddress.getByName( )</B> method that’s in <B>java.net</B>. The
result is an object of type <B>InetAddress</B> that you can use to build a
“socket,” as you will see later.
</backtalk:display>
[ <a href='http://www.mindview.net/backtalk/CommentServlet?ID=TIJ3_CHAPTER15_I12'
target="_blank">Add Comment</a> ]
<backtalk:display ID=TIJ3_CHAPTER15_I13>
</FONT><BR></P></DIV>
<DIV ALIGN="LEFT"><P><FONT FACE="Georgia">As a simple example of using
<B>InetAddress.getByName( )</B>, consider what happens if you have a
dial-up Internet service provider (ISP). Each time you dial up, you are assigned
a temporary IP address. But while you’re connected, your IP address has
the same validity as any other IP address on the Internet. If someone connects
to your machine using your IP address then they can connect to a Web server or
FTP server that you have running on your machine. Of course, they need to know
your IP address, and since a new one is assigned each time you dial up, how can
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -