⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rmi.html

📁 jdbc书
💻 HTML
📖 第 1 页 / 共 4 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
  <TITLE>Writing Advanced Applications, Chapter 4: Distributed Computing</TITLE>
  <META NAME="AUTHOR" CONTENT="Monica Pawlan and Calvin Austin">
  <META NAME="KEYWORDS" CONTENT="programming, advanced, Java 2">
  <META NAME="OWNER" CONTENT="Editorial/JDC">
  <META NAME="revision" CONTENT="@(#)rmi.src    1.5 06/04/99  JDC">
</HEAD>

<!-- Start Body Insert-->
<BODY BGCOLOR="#ffffff">
<!-- End Body Insert-->

<!-- Start PageTop Insert -->

<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="0" WIDTH="100%">
  <TR ALIGN="CENTER" VALIGN="TOP">
    <TD WIDTH="157" ALIGN="LEFT">
    <IMG SRC="/images/pixel.gif" HEIGHT="40" WIDTH="40" ALT="">
    <A HREF="http://java.sun.com/index.html"><IMG SRC="/images/javalogo52x88.gif" WIDTH="52" HEIGHT="88" ALT="Java Technology Home Page" BORDER="0"></A>
    <BR>
    <IMG SRC="/images/pixel.gif" WIDTH="157" HEIGHT="1" ALT=""></TD>

    <TD>

    <FORM NAME="seek1" METHOD="GET" ACTION="http://search.java.sun.com/query.html">
    <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
      <TR>
        <TD ALIGN="RIGHT">
        <IMG SRC="/images/stripelt.gif" WIDTH="6" HEIGHT="14" ALT=""></TD>
        
        <TD WIDTH="100%">
        
        <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0" WIDTH="100%">
          <TR>
            <TD BGCOLOR="#CC9966" WIDTH="100%">
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD>
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD BGCOLOR="#CC9966">
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD>
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD BGCOLOR="#CC9966">
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD>
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
          
          <TR>
            <TD BGCOLOR="#CC9966">
            <IMG SRC="/images/pixel.gif" HEIGHT="2" WIDTH="1" ALT=""></TD>
          </TR>
        </TABLE>
        </TD>
        
        <TD ALIGN="LEFT">
        <IMG SRC="/images/stripert.gif" WIDTH="6" HEIGHT="14" ALT=""></TD>

        <TD>
        
        <TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
          <TR>
            <TD VALIGN="CENTER">
            <A HREF="http://java.sun.com/a-z/index.html"><IMG SRC="/images/azindex.gif" BORDER="0" WIDTH="72" HEIGHT="11" ALT="A-Z Index"></A></TD>
              
            <TD VALIGN="CENTER">
            <FONT FACE="Helvetica" SIZE="1">
            <INPUT TYPE="text" SIZE="15" MAXLENGTH="128" NAME=qt></FONT></TD>
            
            <TD VALIGN="CENTER">
            <INPUT TYPE="image" SRC="/images/search.button.gif" 
              value="search" BORDER="0" WIDTH="55" HEIGHT="14" ALT="Search"></TD>
          </TR>
        </TABLE>
        </TD>
      </TR>
    </TABLE>
    </FORM>
    <P>

    <TABLE BORDER="0" WIDTH="100%" CELLPADDING="0" CELLSPACING="0">
      <TR VALIGN="TOP">
        <TD WIDTH="100%"><IMG SRC="/images/chiclet.row.gif" WIDTH="55" 
          HEIGHT="18" ALT=""></TD>
          
        <TD ROWSPAN="4" ALIGN="RIGHT" WIDTH="152">
        <A HREF="/developer/index.html"><IMG SRC="/images/developer.connection.header.gif" BORDER="0" HEIGHT="42" WIDTH="319" ALT="Java Developer Connection(SM)"></A></TD>
      </TR>
      
      <TR VALIGN="TOP">
        <TD BGCOLOR="#FFFFFF" HEIGHT="1" WIDTH="100%">
        <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
      </TR>
      
      <TR VALIGN="TOP">
        <TD BGCOLOR="#CC9966" HEIGHT="1" WIDTH="100%">
        <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
      </TR>
      
      <TR VALIGN="TOP">
        <TD><A HREF="/developer/onlineTraining/"><IMG SRC="/images/online-training.gif" ALT="Online Training" BORDER=0></A></TD>
      </TR>
    </TABLE>

    </TD>
  </TR>
</TABLE>

<!-- End PageTop Insert -->

<!-- Start NavBar Insert -->
<TABLE BORDER="0" CELLSPACING="0" CELLPADDING="3" BGCOLOR="#FFFFFF" WIDTH="157" ALIGN="LEFT">

<!-- tab categories -->

<TR>
<TD><A HREF="http://java.sun.com/products/"><IMG SRC="/images/side.tab.products.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Downloads, APIs, Documentation"></A></TD>
</TR>

<TR>
<TD><A HREF="/developer/index.html"><IMG SRC="/images/side.tab.developer.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Java Developer Connection"></A></TD>
</TR>

<TR>
<TD><A HREF="/developer/infodocs/index.shtml"><IMG SRC="/images/side.tab.docs.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Tutorials, Tech Articles, Training"></A></TD>
</TR>

<TR>
<TD><A HREF="/developer/support/index.html"><IMG SRC="/images/side.tab.support.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Online Support"></A></TD>
</TR>

<TR>
<TD><A HREF="/developer/community/index.html"><IMG SRC="/images/side.tab.community.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Community Discussion"></A></TD>
</TR>

<TR>
<TD><A HREF="http://java.sun.com/industry/"><IMG SRC="/images/side.tab.news.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="News &amp; Events from Everywhere"></A></TD>
</TR>

<TR>
<TD><A HREF="http://java.sun.com/solutions"><IMG SRC="/images/side.tab.solutions.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="Products from Everywhere"></A></TD>
</TR>

<TR>
<TD><A HREF="http://java.sun.com/casestudies"><IMG SRC="/images/side.tab.case.gif" HEIGHT="15" WIDTH="130" BORDER="0" ALT="How Java Technology is Used Worldwide"></A></TD>
</TR>

<TR><TD>&nbsp;</TD></TR>


<!-- End NavBar Insert -->


<!-- START SUB-NAV -->

<TR>
  <TD><!-- INSERT SUB-NAV INFO -->
  </TD>
</TR>


<!-- END SUB-NAV -->

</TABLE>

<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR>
<TD>

<!-- Template Version 2.0 -->

<!-- ================== -->
<!-- Start Main Content -->
<!-- ================== -->


<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="0">
<TR>
<TD VALIGN="TOP">

<FONT FACE="Verdana, Arial, Helvetica, sans-serif">

  <A NAME="top"></A>
  <DIV ALIGN="RIGHT">
  <H2>Writing Advanced Applications<BR>
  <FONT SIZE="3">Chapter 4: Remote Method Invocation</FONT></H2>
  
  <FONT SIZE="-1">[<A HREF="lookup.html">&lt;&lt;BACK</A>] [<A HREF="index.html#contents">CONTENTS</A>] [<A HREF="corba.html">NEXT&gt;&gt;</A>]</FONT></DIV>

<P>
The Remote Method Invocation (RMI) application programming interface (API) enables 
client and server communications over the net between programs written in the Java<FONT SIZE="-2"><SUP>TM</SUP></FONT> 
programming language. The Enterprise JavaBeans<FONT SIZE="-2"><SUP>TM</SUP></FONT> server transparently 
implements the necessary Remote Method Invocation (RMI) code so the client 
program can reference the Enterprise Beans running on the server and access 
them as if they are running locally to the client program. 

<P>
Having RMI built into the Enterprise JavaBeans server is very convenient and saves
you coding time, but if you need to use advanced RMI features or integrate RMI 
with an existing application, you need to override the default RMI
implementation and write your own RMI code.

<P>
This chapter replaces the container-managed <CODE>RegistrationBean</CODE> from 
<A HREF="code3.html">Chapter 2: Entity and Session Beans</A> with an RMI-based 
registration server. The container-managed <CODE>SellerBean</CODE> from Chapter 2 
is also changed to call the new RMI registration server using a Java 2 
RMI <CODE>lookup</CODE> call.

<P>
<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#about">About RMI</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#auction">RMI in the Auction Application</A></FONT>
<UL>
  <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
  <A HREF="#class">Class Overview</A></FONT>
  <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
  <A HREF="#file">File Summary</A></FONT>
  <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
  <A HREF="#compile">Compile the Example</A></FONT>
  <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
  <A HREF="#rmiregis">Start the RMI Registry</A></FONT>
  <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
  <A HREF="#start">Start the Remote Server</A></FONT>
</UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#remote">Establishing Remote Communications</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#regserver">RegistrationServer Class</A></FONT>
<UL>
	<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
	<A HREF="#export">Exporting a Remote Object</A></FONT>
        <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
        <A HREF="#pass">Passing by Value and by Reference</A></FONT>
        <LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
        <A HREF="#garbage">Distributed Garbage Collection</A></FONT>
</UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#int">Registration Interface</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#ret">ReturnResults Interface</A></FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">
<A HREF="#seller">SellerBean Class</A></FONT>
</UL>

<HR>

<A NAME="about"></A>
<H3>About RMI</H3>

The RMI API lets you access a remote server object from a client program
by making simple method calls on the server object. 
While other distributed architectures for accessing remote server objects such as
Distributed Component Object Model (DCOM) and Common Object Request Broker
Architecture (CORBA) return references to the remote object, the RMI API 
not only returns references, but provides these additional benefits. 

<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">The RMI API handles remote object references (call by reference) and
can also return a copy of the object (call by value).</FONT> 

<P>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">If the client program does not have local access to the class from
which a local or remote object was instantiated, RMI services can download 
the class file.</FONT>
</UL>

<H4>Serialization and Data marshaling</H4>

To transfer objects, the RMI API uses the Serialization API to wrap (marshal)
and unwrap (unmarshal) the objects. To marshal an object, the
Serialization API converts the object to a stream of bytes, and to unmarshal
an object, the Serialization API converts a stream of bytes into an
object.

<H4>RMI over IIOP</H4>

One of the initial disadvantages to RMI was that its sole reliance on
the Java platform to write the interfaces made integration into existing
legacy systems difficult. However, RMI over Internet Inter-ORB Protocol
(IIOP) discussed in <A HREF="lookup.html">Chapter 4: Lookup Services</A>
lets RMI communicate with any system or language that CORBA supports.

<P>
If you combine improved integration with the ability of RMI
to work through firewalls using HTTP firewall proxying, you might find
distributing your business logic using RMI is easier than
a socket-based solution.

<BLOCKQUOTE>
<HR>
<STRONG>Note:</STRONG>
Transfering code and data are key parts of the Jini<FONT SIZE="-2"><SUP>TM</SUP></FONT> System software
specification. In fact, adding a discovery and join service to the RMI services
would create something very similar to what you get in the Jini architecture.
<HR>
</BLOCKQUOTE>

<A NAME="auction"></A>
<H3>RMI in the Auction Application</H3>

<P>
The RMI-based <A HREF="./Code/rmi/RegistrationServer.java">RegistrationServer</A>
has the following new methods:

<UL>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">A new <CODE>create</CODE> method for creating a new user.</FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">A new <CODE>find</CODE> method for finding a user.</FONT>
<LI><FONT FACE="Verdana, Arial, Helvetica, sans-serif">A new <CODE>search</CODE> method for the custom search of 
users in the database.</FONT>

</UL>

The new custom search passes results back to the calling client by way
of an RMI callback. The RMI callback custom search is similar to the 
<CODE>finder</CODE> methods used in the Bean- and container-managed
examples from Chapters 2 and 3, except in the RMI version, it can take more
time to generate the results because the remote registration server calls a 
remote method exported by the RMI-based 
<A HREF="./Code/rmi/SellerBean.java">SellerBean</A>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -