五、参考资料

---(文/王静翊)
[1] 王静翊, "Jini - Java实现分散式计算的最佳利器," Java Letter Vol. 1 No. 2, 1999.
[2] 卢惠杰, "Java的分散式环境 - RMI," Java Letter Vol. 1 No. 1, 1999.
[3] Jini Starter Kit 1.0 's DOC.
[4] "A Jini Tutorial, " h ttp://pandonia.ca nberra.edu.au/jav a/jini/tutorial/J ini.xml, 23 June 1999.
[5] "CS 696 Emerging Technologies: Java Distributed Computing," http://www.eli .sdsu.edu/courses /spring99/cs696/n otes/index.html, 1998.
程式一、 TestSvrInterface. java

import java.rmi.*;

public interface TestSvrInterface extends Remote{

	public String sayHello() throws RemoteException;

}


程式二、 TestSvr.java 
      

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......");
	}
}

程式三、 TestClnt.java 
      

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()+" ---");
	}

}