首页>代码>java项目中用到的rmi实例>/RMI/src/com/csii/rmi/RMILocator.java
package com.csii.rmi;

import java.rmi.server.RMIClientSocketFactory;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.csii.service.comm.rmi.RMINaming;

public class RMILocator {
	  
	  private RMIClientSocketFactory rmiClientSocketFactory;
	  private static Log log = LogFactory.getLog(RMILocator.class);
	  private transient boolean inited;
	  private transient SecurityManager securityManager;
	  private String registryHost = "";

	  private int registryPort = 7700;
	  private int recoverDelay;
	  private int recoverRetry;

	  public void setRecoverDelay(int recoverDelay)
	  {
	    this.recoverDelay = recoverDelay;
	  }

	  public void setRecoverRetry(int recoverRetry) {
	    this.recoverRetry = recoverRetry;
	  }

	  public void setRmiClientSocketFactory(RMIClientSocketFactory rmiClientSocketFactory)
	  {
	    this.rmiClientSocketFactory = rmiClientSocketFactory;
	  }

	  public void setRegistryHost(String registryHost) {
	    this.registryHost = registryHost;
	  }

	  public void setRegistryPort(int registryPort) {
	    this.registryPort = registryPort;
	  }

	  private synchronized void init() {
	    if (!this.inited) {
	      if (this.securityManager != null)
	        System.setSecurityManager(this.securityManager);
	      this.inited = true;
	    }
	  }

	  public Object lookup(String name) {
	    init();

	    if (name == null)
	      throw new IllegalArgumentException("lookup name is null.");
	    if (!name.startsWith("//"))
	      name = "//" + this.registryHost + ":" + this.registryPort + "/" + name;
	    try
	    {
	      Object o = RMINaming.lookup(name, this.rmiClientSocketFactory);

	      log.info("lookup and found " + name);
	      return o;
	    } catch (Exception e) {
	      throw new RuntimeException("Lookup Object from registry error.", e);
	    }
	  }

	  public String[] list() {
	    init();
	    try
	    {
	      return RMINaming.list("//" + this.registryHost + ":" + this.registryPort + "/", this.rmiClientSocketFactory);
	    } catch (Exception e) {
	      throw new RuntimeException("List registry Objects error.", e);
	    }
	  }
}
最近下载更多
1971717082  LV2 2021年5月20日
bjwsnl  LV22 2021年5月6日
longyin2018  LV14 2019年3月23日
mashangfacai  LV2 2017年11月16日
annazhang  LV29 2017年10月7日
hh516554097  LV10 2016年8月1日
zhangshangya  LV2 2016年7月14日
penghuangit  LV2 2016年6月17日
xiaoxuan  LV4 2015年1月20日
yekun  LV3 2014年11月10日
最近浏览更多
zhos0212  LV19 2022年7月11日
wyx065747  LV67 2022年3月9日
wxd1997  LV13 2022年3月9日
dongzhan  LV12 2021年12月16日
1971717082  LV2 2021年5月20日
bjwsnl  LV22 2021年5月6日
2929737994  LV1 2020年10月13日
bbdwpyyd  LV2 2019年11月13日
longyin2018  LV14 2019年2月28日
大风知微  LV3 2019年1月22日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友