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

📄 lookup.html

📁 jdbc书
💻 HTML
📖 第 1 页 / 共 3 页
字号:
RMI-IIOP, including <CODE>rmi</CODE> in the URL will save confusion later on.
Once you have a reference to <CODE>SellerHome</CODE>, you can call its methods.
<P>
In contrast to the JNDI lookup performed by
<CODE>AuctionServlet.java</CODE>,
which requires a two-stage lookup to create a context and then the
actual lookup, RMI initializes the connection to the RMI name server,
<CODE>rmiregistry</CODE>, and also gets the remote reference with one call.

<P>
This remote reference is leased to the client from the
<CODE>rmiregistry</CODE>.
The lease means that unless the client informs the server it still
needs a reference to the object, the lease expires and the memory is
reclaimed.
This leasing operation is transparent to the user, but can be tuned by
setting the server property <CODE>java.rmi.dgc.leaseValue</CODE> value
in milliseconds when starting the server as follows:

<PRE>
  java -Djava.rmi.dgc.leaseValue=120000 myAppServer
</PRE>

<A NAME="iiop"></A>
<H3>RMI Over Internet Inter-ORB Protocol (IIOP)</H3>

The advent of RMI over Internet Inter-ORB Protocol (IIOP), means
existing RMI code can reference and look up an object with the CORBA
<CODE>CosNaming</CODE> service. This gives you greater interoperability
between architectures with little change to your existing RMI code.

<BLOCKQUOTE>
<HR>
<STRONG>Note:</STRONG>
The <CODE>rmic</CODE> compiler provides the <CODE>-iiop</CODE> option to
generates the stub and tie classes necessary for RMI-IIOP.
<HR>
</BLOCKQUOTE>

<H4>IIOP Server</H4>

The RMI-IIOP protocol is implemented as a JNDI plug-in, so as before,
you need to create an <CODE>InitialContext</CODE>:

<PRE>
  Hashtable env = new Hashtable();
  env.put("java.naming.factory.initial",
        "com.sun.jndi.cosnaming.CNCtxFactory");
  env.put("java.naming.provider.url",
        "iiop://localhost:1091");
  Context ic = new InitialContext(env);
</PRE>

The naming factory should look familiar as it is the same CORBA naming
service used in the CORBA section. The main difference is the addition of a
URL value specifing the naming service to which to connect. The naming
service used here is the <CODE>tnameserv</CODE> program
started on port 1091.

<PRE>
  tnameserv -ORBInitialPort 1091
</PRE>

<P>
The other main change to the server side is to replace calls
to <CODE>Naming.rebind</CODE> to use the JNDI <CODE>rebind</CODE>
method in the <CODE>InitialContext</CODE> instance. For example:

<P>
Old RMI code:
<PRE>
  SellerHome shome=(SellerHome)Naming.lookup(
  "rmi://appserver:1090/seller");
</PRE>

New RMI code:
<PRE>
  Hashtable env = new Hashtable();
  env.put("java.naming.factory.initial",
	"com.sun.jndi.cosnaming.CNCtxFactory");
  env.put("java.naming.provider.url",
	"iiop://localhost:1091");
  Context ic = new InitialContext(env);

  SellerHome shome= 
	(SellerHome)PortableRemoteObject.narrow(
	ic.lookup("seller"), SellerHome)
</PRE>

<H4>IIOP Client</H4>

On the client side, the RMI lookup is changed to use an instance of
the <CODE>InitialContext</CODE> in the place of RMI
<CODE>Naming.lookup</CODE>.
The return object is mapped to the requested object by using the
<CODE>narrow</CODE> method of the
<CODE>javax.rmi.PortableRemoteObject</CODE> class.
<CODE>PortableRemoteObject</CODE> replaces
<CODE>UnicastRemoteObject</CODE> that was previously available in the RMI
server code.

<P>
Old RMI lookup code:
<PRE>
  SellerHome shome= new SellerHome("seller");
  Naming.rebind("seller", shome);
</PRE>

<P>
New RMI code:
<PRE>
   Hashtable env = new Hashtable();
   env.put("java.naming.factory.initial",
	"com.sun.jndi.cosnaming.CNCtxFactory");
   env.put("java.naming.provider.url", 
	"iiop://localhost:1091");
   Context ic = new InitialContext(env);
   
   SellerHome shome= new SellerHome("seller");
   ic.rebind("seller", shome);
</PRE>

The <CODE>PortableRemoteObject</CODE> replaces
<CODE>UnicastRemoteObject</CODE>
previously available in the RMI server code. The RMI code would either
extend
<CODE>UnicastRemoteObject</CODE> or call the <CODE>exportObject</CODE>
method
from the <CODE>UnicastRemoteObject</CODE> class. The
<CODE>PortableRemoteObject</CODE>
also contains an equivalent <CODE>exportObject</CODE> method. In the
current
implementation, is is best to explicitly remove unused objects by
calling <CODE>PortableRemoteObject.unexportObject()</CODE>.

<A NAME="jini"></A>
<H3>JINI lookup services</H3>

(To be done later)


<A NAME="perf"></A>
<H3>Improving Lookup Performance</H3>

When you run your application, if you find it would be faster
to walk the object to the other computer on a floppy, you
have a network configuration problem. The source of the problem
is how host names and IP addresses are resolved, and there is
a workaround.  

<P>
RMI and other naming services use the <CODE>InetAddress</CODE> class to
obtain resolved host name and IP addresses. <CODE>InetAddress</CODE> 
caches lookup results to improve subsequent calls, but when it is 
passed a new IP address or host name, it performs a cross-reference
between the IP address and the host name to prevent address spoofing. 
If you supply the host name as an IP address, <CODE>InetAddress</CODE> 
still tries to verify the name of the host.

<P>
To workaround this problem, include the host name and IP address
in a hosts file on the client.

<P>
<STRONG>Unix Systems:</STRONG>
On Unix, the hosts file is usually <CODE>/etc/hosts</CODE>.

<P>
<STRONG>Windows:</STRONG>
On Winddows 95 or 98, the hosts file is 
<CODE>c:\windows\hosts</CODE>, (the <CODE>hosts.sam</CODE>
file is a sample
file). On Windows NT, the hosts file is
<CODE>c:\winnt\system32\drivers\etc\hosts</CODE>

<P>
All you need to do is put these lines in your hosts file. 
The <CODE>myserver1</CODE> and <CODE>myserver2</CODE> entries
are the hosts running the remote server and <CODE>rmiregistry</CODE>

<PRE>
127.0.0.1  localhost
129.1.1.1  myserver1
129.1.1.2  myserver2
</PRE>

<P ALIGN="RIGHT">
<FONT SIZE="-1">[<A HREF="#top">TOP</A>]</FONT>

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



<!-- ================ -->
<!-- End Main Content -->
<!-- ================ -->

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

<!-- Copyright Insert -->

<BR CLEAR="ALL">

<FORM ACTION="/cgi-bin/search.cgi" METHOD="POST">
<TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="5">   
  <TR>
    <TD VALIGN="TOP">
	
    <P ALIGN=CENTER>
    <FONT SIZE="-1" COLOR="#999999" FACE="Verdana, Arial, Helvetica, sans-serif">
    [ This page was updated: <!-- new date --> 13-Oct-99 ]</font></P>
    </TD>
  </TR>
  
  <TR>
    <TD BGCOLOR="#CCCCCC">
    <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
  </TR>
  
  <TR>
    <TD>
    <CENTER>
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <A HREF="http://java.sun.com/products/">Products &amp; APIs</A> | 
    <A HREF="/developer/index.html">Developer Connection</A> | 
    <A HREF="/developer/infodocs/index.shtml">Docs &amp; Training</A> | 
    <A HREF="/developer/support/index.html">Online Support</A><BR>
    <A HREF="/developer/community/index.html">Community Discussion</A> |
    <A HREF="http://java.sun.com/industry/">Industry News</A> | 
    <A HREF="http://java.sun.com/solutions">Solutions Marketplace</A> | 
    <A HREF="http://java.sun.com/casestudies">Case Studies</A>
    </FONT>
    </CENTER>
    </TD>
  </TR>
  
  <TR>
    <TD BGCOLOR="#CCCCCC">
    <IMG SRC="/images/pixel.gif" HEIGHT="1" WIDTH="1" ALT=""></TD>
  </TR>

  <TR>
    <TD ALIGN="CENTER">
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <A HREF="http://java.sun.com/docs/glossary.html">Glossary</A> - 
    <A HREF="http://java.sun.com/applets/">Applets</A> - 
    <A HREF="http://java.sun.com/docs/books/tutorial/">Tutorial</A> - 
    <A HREF="http://java.sun.com/jobs/">Employment</A> - 
    <A HREF="http://java.sun.com/nav/business/">Business &amp; Licensing</A> - 
    <A HREF="http://java.sun.com/javastore/">Java Store</A> -
    <A HREF="http://java.sun.com/casestudies/">Java in the Real World</A>
    </FONT>
    </TD>
  </TR>

  <TR>
    <TD>
    <CENTER>
    <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
    <a href="/siteinfo/faq.html">FAQ</a> |
    <a href="/feedback/index.html">Feedback</a> | 
    <a href="http://www.dynamicdiagrams.net/mapa/cgi-bin/help.tcl?db=javasoft&dest=http://java.sun.com/">Map</a> | 
    <A HREF="http://java.sun.com/a-z/index.html">A-Z Index</A>
    </FONT>
    </CENTER>

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

    <TABLE WIDTH="100%" CELLPADDING="0" BORDER="0" CELLSPACING="0">
      <TR>
        <TD WIDTH="50%">
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        For more information on Java technology<BR>
        and other software from Sun Microsystems, call:<BR>
        </FONT>
        <FONT SIZE="-1" FACE="Verdana, Arial, Helvetica, sans-serif">
        (800) 786-7638<BR></FONT>
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        Outside the U.S. and Canada, dial your country's 
        <A HREF="http://www.att.com/business_traveler/attdirecttollfree/">AT&amp;T&nbsp;Direct&nbsp;Access&nbsp;Number</A> first.<BR>
        </FONT>
        </TD>

        <TD ALIGN="RIGHT" WIDTH="50%">
        <A HREF="http://www.sun.com"><IMG SRC="/images/lgsun.gif" width="64" height="30" border="0" ALT="Sun Microsystems, Inc."></A><BR>
        <FONT SIZE="-2" FACE="Verdana, Arial, Helvetica, sans-serif">
        Copyright &copy; 1995-99
        <A HREF="http://www.sun.com">Sun Microsystems, Inc.</A><BR>
        All Rights Reserved. 
        <a href="http://www.sun.com/share/text/SMICopyright.html">Legal Terms</a>. 
        <A HREF="http://www.sun.com/privacy/">Privacy&nbsp;Policy</A>.
        </FONT>
        </TD>
      </TR>
    </TABLE>
	
    </TD>
  </TR> 
</TABLE>
</FORM>

<!-- End Copyright Insert -->


</BODY>
</HTML>

⌨️ 快捷键说明

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