📄 rmi.html
字号:
<H3>RegistrationHome Interface</H3>
The <A HREF="./Code/rmi/RegistrationHome.java">RegistrationHome</A> interface
declares the methods implemented by the<CODE>RegistrationServer</CODE> class.
These methods mirror the Home interface defined in the Enterprise JavaBeans
example. The <CODE>findLowCreditAccounts</CODE> method takes a remote interface
as its only parameter.
<PRE>
package registration;
import java.rmi.*;
import java.util.*;
public interface RegistrationHome extends Remote {
RegistrationPK create(String theuser,
String password,
String emailaddress,
String creditcard)
throws CreateException,
RemoteException;
Registration findByPrimaryKey(RegistrationPK theuser)
throws FinderException, RemoteException;
public void findLowCreditAccounts(ReturnResults rr)
throws FinderException, RemoteException;
}
</PRE>
<A NAME="ret"></A>
<H3>ReturnResults Interface</H3>
The <A HREF="./Code/rmi/ReturnResults.java">ReturnResults</A> interface declares the
method implemented by the <CODE>SellerBean</CODE> class. The
<CODE>updateResults</CODE> method is called from <CODE>RegistrationServer</CODE>.
<PRE>
package registration;
import java.rmi.*;
import java.util.*;
public interface ReturnResults extends Remote {
public void updateResults(ArrayList results)
throws FinderException, RemoteException;
}
</PRE>
<A NAME="seller"></A>
<H3>SellerBean Class</H3>
The <A HREF="./Code/rmi/SellerBean.java">SellerBean</A> class includes
the callback method implementation and calls the <CODE>RegistrationServer</CODE>
object using RMI. The <CODE>updateAccounts</CODE> method is made accessible by
a call to <CODE>UnicastRemoteObject.exportObject(this);</CODE>. The
<CODE>auditAccounts</CODE> method waits on a <CODE>Boolean</CODE> object.
<P>
The <CODE>updateAccounts</CODE> method sends a notify to all methods
waiting on the <CODE>Boolean</CODE> object when it has been called from the server
and receives the search results.
<PRE>
<PRE>
package seller;
import java.rmi.RemoteException;
import java.rmi.*;
import javax.ejb.*;
import java.util.*;
import java.text.NumberFormat;
import java.io.Serializable;
import javax.naming.*;
import auction.*;
import registration.*;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
public class SellerBean
implements SessionBean, ReturnResults {
protected SessionContext ctx;
javax.naming.Context ectx;
Hashtable env = new Hashtable();
AuctionServlet callee=null;
Boolean ready=new Boolean("false");
ArrayList returned;
public int insertItem(String seller,
String password,
String description,
int auctiondays,
double startprice,
String summary)
throws RemoteException {
try{
RegistrationHome regRef = (
RegistrationHome)Naming.lookup(
"//phoenix.eng.sun.com/registration2");
RegistrationPK rpk= new RegistrationPK();
rpk.setUser(seller);
Registration newseller = (
Registration)regRef.findByPrimaryKey(rpk);
if((newseller == null) ||
(!newseller.verifyPassword(password))) {
return(Auction.INVALID_USER);
}
AuctionItemHome home = (
AuctionItemHome) ectx.lookup(
"auctionitems");
AuctionItem ai= home.create(seller,
description,
auctiondays,
startprice,
summary);
if(ai == null) {
return Auction.INVALID_ITEM;
}else{
return(ai.getId());
}
}catch(Exception e){
System.out.println("insert problem="+e);
return Auction.INVALID_ITEM;
}
}
public void updateResults(java.util.ArrayList ar)
throws RemoteException {
returned=ar;
synchronized(ready) {
ready.notifyAll();
}
}
public ArrayList auditAccounts() {
this.callee=callee;
try {
RegistrationHome regRef = (
RegistrationHome)Naming.lookup(
"//phoenix.eng.sun.com/registration2");
regRef.findLowCreditAccounts(this);
synchronized(ready) {
try {
ready.wait();
} catch (InterruptedException e){}
}
return (returned);
}catch (Exception e) {
System.out.println("error in creditAudit "+e);
}
return null;
}
public void ejbCreate()
throws javax.ejb.CreateException,
RemoteException {
env.put(
javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.TengahInitialContextFactory");
try{
ectx = new InitialContext(env);
} catch (NamingException e) {
System.out.println(
"problem contacting EJB server");
throw new javax.ejb.CreateException();
}
Properties env=System.getProperties();
env.put("java.rmi.server.codebase",
"http://phoenix.eng.sun.com/registration");
env.put("java.security.policy","java.policy");
UnicastRemoteObject.exportObject(this);
}
public void setSessionContext(SessionContext ctx)
throws RemoteException {
this.ctx = ctx;
}
public void unsetSessionContext()
throws RemoteException {
ctx = null;
}
public void ejbRemove() {}
public void ejbActivate() throws RemoteException {
System.out.println("activating seller bean");
}
public void ejbPassivate() throws RemoteException {
System.out.println("passivating seller bean");
}
}
</PRE>
<P>
_______<BR>
<A NAME="TJVM"><SUP>1</SUP></A> As used on this web site,
the terms "Java virtual
machine" or "JVM" mean a virtual machine
for the Java platform.
<P ALIGN="RIGHT">
<FONT SIZE="-1">[<A HREF="#top">TOP</A>]</FONT>
<HR>
<P>
</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 --> 28-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 & APIs</A> |
<A HREF="/developer/index.html">Developer Connection</A> |
<A HREF="/developer/infodocs/index.shtml">Docs & 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 & 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&T Direct Access 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 © 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 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 + -