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

📄 第七章 join manager.htm

📁 分多章节详细介绍了Jini技术及相关开发环境
💻 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>第七章 Join Manager</strong></big></p>
                
<p>寻找一个lookup service包括一系列普通的步骤。他们随后的交互也包括了一些一般的步骤。所以<BR>
我们用一个join manager把这些步骤封装成一个有用的类。
<P>1、 Join Manager
<P>一个服务要使自己可用通常有以下策略:
<pre><code>
(1) 发现可用的服务定位器(service locators)。
(2) 注册到找到的locator上(Register with all of them)
(3) 一直重新注册(Keep re-registering till the end of time)
(4) 如果状态改变了,通知给所有注册服务的locators。
</code></pre>
这些代码一旦写完,就可以从一个服务拷贝到另一个。更好的做法是把他们封装到一个对象中。甚至<BR>
Sun用一个类JoinManager来做它。它能很好的减少服务端的代码量。例如option2的服务可以变成:
<pre><code>
package joinmgr;
// import net.jini.discovery.LookupDiscovery;
// import net.jini.discovery.DiscoveryListener;
// import net.jini.discovery.DiscoveryEvent;
// import net.jini.core.lookup.ServiceRegistrar;
// import net.jini.core.lookup.ServiceItem;
// import net.jini.core.lookup.ServiceRegistration;
// import net.jini.core.lease.Lease;
import com.sun.jini.lookup.JoinManager;
import net.jini.core.lookup.ServiceID;
import com.sun.jini.lookup.ServiceIDListener;
import com.sun.jini.lease.LeaseRenewalManager;
/**
 * FileClassifierServer.java *
    * Created: Wed Mar 17 14:23:44 1999 
    * @author Jan Newmarch 
    * @version
    */

public class FileClassifierServer implements ServiceIDListener {    
    public static void main(String argv[]) {
     	new FileClassifierServer();
    }

    public FileClassifierServer() {
     	/** WE JUNK ALL OF THIS CODE
	        LookupDiscovery discover = null;
        try {
            discover = new LookupDiscovery(LookupDiscovery.ALL_GROUPS);
        } catch(Exception e) {
            System.err.println(e.toString());
            System.exit(1);
        }
        discover.addDiscoveryListener(this);
        // stay around long enough to receive replies
        try {
            Thread.currentThread().sleep(10000L);
        } catch(java.lang.InterruptedException e) {
            // do nothing
        }	*/
	
/** AND REPLACE IT WITH THIS */	

    JoinManager joinMgr = null;
  	try {
	    joinMgr = new JoinManager(new FileClassifierImpl(), null, 
	              this,new LeaseRenewalManager());
 	} catch(Exception e) {
	      e.printStackTrace();
   	  System.exit(1);
 	}
        // stay around long enough to receive replies
   try {
       Thread.currentThread().sleep(1000000L);
   } catch(java.lang.InterruptedException e) {
            // do nothing
   }
}

public void serviceIDNotify(ServiceID serviceID) {
	    System.out.println("got service ID " + serviceID.toString());
}
    /*    
    public void discovered(DiscoveryEvent evt) {
        ServiceRegistrar[] registrars = evt.getRegistrars();
        for (int n = 0; n < registrars.length; n++) {
            ServiceRegistrar registrar = registrars[n];
	    ServiceItem item = new ServiceItem(null, new FileClassifierImpl(), null);

	    ServiceRegistration reg = null;	    try {
		reg = registrar.register(item, Lease.FOREVER);
	    } catch(java.rmi.RemoteException e) {
		System.err.println("Register exception: " + e.toString());
		}
	    System.out.println("service registered");	}    }
    public void discarded(DiscoveryEvent evt) {    } 
   */       

} // FileClassifierServer
</code></pre>

  </table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>

⌨️ 快捷键说明

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