📄 jndi五、参考资料.htm
字号:
<html>
<head>
<title>新时代软件教程:操作系统 主页制作 服务器 设计软件 网络技术 编程语言 文字编辑</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
<!--
body, table {font-size: 9pt; font-family: 宋体}
a {text-decoration:none}
a:hover {color: red;text-decoration:underline}
.1 {background-color: rgb(245,245,245)}
-->
</style>
</head>
<p align="center"><script src="../../1.js"></script></a>
<p align="center"><big><strong>五、参考资料</strong></big></p>
<div align="right">---(文/王静翊)</div>
<DL>
<DT>
<DD>[1] 王静翊, "Jini -
Java实现分散式计算的最佳利器," Java Letter Vol. 1 No. 2, 1999.
<DD>[2] 卢惠杰, "Java的分散式环境 - RMI,"
Java Letter Vol. 1 No. 1, 1999.
<DD>[3] Jini Starter Kit 1.0 's DOC.
<DD>[4] "A Jini Tutorial, " <A
href="../../pandonia.canberra.edu.au/java/jini/tutorial/Jini.xml">h
ttp://pandonia.ca nberra.edu.au/jav a/jini/tutorial/J ini.xml</A>, 23
June 1999.
<DD>[5] "CS 696 Emerging Technologies: Java Distributed
Computing," <A
href="../../www.eli.sdsu.edu/courses/spring99/cs696/notes/index.html">http://www.eli
.sdsu.edu/courses /spring99/cs696/n otes/index.html</a>, 1998.
</DD></DL><B>程式一、 TestSvrInterface. java</B>
<P align=center>
<TABLE width="70%">
<TBODY>
<TR>
<TD class=detail><PRE>
import java.rmi.*;
public interface TestSvrInterface extends Remote{
public String sayHello() throws RemoteException;
}
</PRE></TD></TR></TBODY></TABLE></P><PRE></PRE><B>程式二、 TestSvr.java</B>
<P align=center>
<TABLE width="70%">
<TBODY>
<TR>
<TD class=detail><PRE>
import net.jini.core.discovery.LookupLocator;
import net.jini.core.entry.*;
import net.jini.core.lease.Lease;
import net.jini.core.lookup.*;
import net.jini.lookup.entry.Name;
import com.sun.jini.lease.LeaseRenewalManager;
import com.sun.jini.lookup.JoinManager;
import java.rmi.*;
import java.rmi.server.*;
public class TestSvr extends UnicastRemoteObject implements
TestSvrInterface{
public TestSvr() throws RemoteException{
super();
}
public String sayHello() throws RemoteException{
System.out.println("I'm called");
return ("TestSvr said... Greeting!");
}
public static void main(String args[]) throws Throwable{
// 设定自己的 attributes.
Entry[] eAttrib = new Entry[1];
eAttrib[0] = new Name("TestSvr");
TestSvr ts = new TestSvr();
// 建立一个LookupLocator物件,以寻找特定的 lookup service.
LookupLocator ll = new LookupLocator("jini://specific-host:4160");
// 找到 lookup service之後,建立一个与其沟通的介面。
ServiceRegistrar sreg = ll.getRegistrar();
// 透过此介面,向 lookup service 注册其服务资讯。
sreg.register (new ServiceItem(null,ts,eAttrib), Lease.FOREVER);
System.out.println("Waiting request......");
}
}
</PRE></TD></TR></TBODY></TABLE></P><PRE></PRE><B>程式三、 TestClnt.java</B>
<P align=center>
<TABLE width="70%">
<TBODY>
<TR>
<TD class=detail><PRE>import net.jini.core.discovery.LookupLocator;
import net.jini.core.lookup.*;
import net.jini.core.entry.*;
import net.jini.lookup.entry.Name;
class TestClnt{
public static void main(String args[]) throws Throwable{
// 建立一个LookupLocator物件,以寻找特定的 lookup service.
LookupLocator ll = new LookupLocator("jini://specific-host:4160");
// 找到 lookup service之後,建立一个与其沟通的介面。
ServiceRegistrar sreg = ll.getRegistrar();
// 设定要寻找的服务之 attributes,并做成样版。
Entry[] eAttrib = new Entry[1];
eAttrib[0] = new Name("TestSvr");
ServiceTemplate tmplt = new ServiceTemplate (null, null, eAttrib);
// 将样版送至 lookup service,并要求其找出符合样版的服务。
TestSvrInterface tsi = (TestSvrInterface)( sreg.lookup(tmplt) );
// 找到服务之後,呼叫此服务之 method.
System.out.println("--- "+tsi.sayHello()+" ---");
}
}
</PRE></TD></TR></TBODY></TABLE></P>
</table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -