我编辑的测试类如下:
服务器类:News_register_factory import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;import News_apart_DAOImp.NAprt_affair_noticeDAOImp;
import News_apart_DAOImp.News_apart_DAOImp;
import News_aprt_DAO.News_register_factoryDAO;public class News_register_factory extends UnicastRemoteObject implements
News_register_factoryDAO,Runnable {
private String item;
protected News_register_factory() throws RemoteException {
super();
// TODO Auto-generated constructor stub
} public boolean register() throws RemoteException {
if(this.item == "newsDAOImp"){
LocateRegistry.createRegistry(8808);
News_apart_DAOImp news = new News_apart_DAOImp();
try {
Naming.rebind("//localhost:8808/news" , news);
System.out.println("\n news registered");
//registry.unbind("news");
/* UnicastRemoteObject.unexportObject(registry, true);
System.out.println(">>>>>INFO:服务停止!");
System.exit(0); //终止RMI服务程序的运行
*/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
if(this.item == "NApart_affairImp"){
LocateRegistry.createRegistry(8809);
NAprt_affair_noticeDAOImp affair = new NAprt_affair_noticeDAOImp();
try {
Naming.rebind("//localhost:8809/Naffair" , affair);
System.out.println("\n affair registered");
/* //registry.unbind("Naffair");
UnicastRemoteObject.unexportObject(registry, true);
System.out.println(">>>>>INFO:服务停止!");
//System.exit(0); //终止RMI服务程序的运行
*
*/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
if(this.item == "BApart_affairImp"){
LocateRegistry.createRegistry(8810);
NAprt_affair_noticeDAOImp affair = new NAprt_affair_noticeDAOImp();
try {
Naming.rebind("//localhost:8810/Baffair" , affair);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
return false;
} public synchronized void setItem(String it) throws RemoteException {
// TODO Auto-generated method stub
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.item = it;
} public void run() {
// TODO Auto-generated method stub
try {
System.out.println(Thread.currentThread().getName() + " is saling ticket " + register()); } catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}其中Imp类及其stub全部部署在服务端本地。
客户端类:package LookUpImp;import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;import NewsDAO.News_register_factoryDAO;public class NLookUp {
public boolean lookup(String item) {
String url = "//localhost:8807/factory";
try {
News_register_factoryDAO factory = (News_register_factoryDAO) Naming
.lookup("demo");
if (item == "news") {
factory.setItem("news");
new Thread((Runnable) factory).start();
return true;
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotBoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}}codebase设置的就是classPath
客户端提示
News_register_factoryDAO factory = (News_register_factoryDAO) Naming.lookup("demo");找不到 News_register_factory_stub
求解
服务器类:News_register_factory import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;import News_apart_DAOImp.NAprt_affair_noticeDAOImp;
import News_apart_DAOImp.News_apart_DAOImp;
import News_aprt_DAO.News_register_factoryDAO;public class News_register_factory extends UnicastRemoteObject implements
News_register_factoryDAO,Runnable {
private String item;
protected News_register_factory() throws RemoteException {
super();
// TODO Auto-generated constructor stub
} public boolean register() throws RemoteException {
if(this.item == "newsDAOImp"){
LocateRegistry.createRegistry(8808);
News_apart_DAOImp news = new News_apart_DAOImp();
try {
Naming.rebind("//localhost:8808/news" , news);
System.out.println("\n news registered");
//registry.unbind("news");
/* UnicastRemoteObject.unexportObject(registry, true);
System.out.println(">>>>>INFO:服务停止!");
System.exit(0); //终止RMI服务程序的运行
*/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
if(this.item == "NApart_affairImp"){
LocateRegistry.createRegistry(8809);
NAprt_affair_noticeDAOImp affair = new NAprt_affair_noticeDAOImp();
try {
Naming.rebind("//localhost:8809/Naffair" , affair);
System.out.println("\n affair registered");
/* //registry.unbind("Naffair");
UnicastRemoteObject.unexportObject(registry, true);
System.out.println(">>>>>INFO:服务停止!");
//System.exit(0); //终止RMI服务程序的运行
*
*/
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
if(this.item == "BApart_affairImp"){
LocateRegistry.createRegistry(8810);
NAprt_affair_noticeDAOImp affair = new NAprt_affair_noticeDAOImp();
try {
Naming.rebind("//localhost:8810/Baffair" , affair);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return true;
}
return false;
} public synchronized void setItem(String it) throws RemoteException {
// TODO Auto-generated method stub
try {
Thread.sleep(10);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this.item = it;
} public void run() {
// TODO Auto-generated method stub
try {
System.out.println(Thread.currentThread().getName() + " is saling ticket " + register()); } catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}其中Imp类及其stub全部部署在服务端本地。
客户端类:package LookUpImp;import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;import NewsDAO.News_register_factoryDAO;public class NLookUp {
public boolean lookup(String item) {
String url = "//localhost:8807/factory";
try {
News_register_factoryDAO factory = (News_register_factoryDAO) Naming
.lookup("demo");
if (item == "news") {
factory.setItem("news");
new Thread((Runnable) factory).start();
return true;
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (RemoteException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotBoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return false;
}}codebase设置的就是classPath
客户端提示
News_register_factoryDAO factory = (News_register_factoryDAO) Naming.lookup("demo");找不到 News_register_factory_stub
求解
解决方案 »
- 使用struts2和tomcat的memory leak问题
- 启动时抛的异常!
- 关于jquery方法trigger( event, [data] )和triggerHandler( event, [data] )
- MEM_DEV_ARGS是什么意思?
- 帮我看看xml的错误
- 安装ipv6协议的机器 在使用request.getRomoteAddr()为什么获得的是ipv6地址,不能获得以前ipv地址了
- 急!!!servlet如何实现读取一个绝对路径文件展现到页面
- Hibernate表与表之间关系的设计的问题
- 新手:问开发&配置j2ee的环境初级问题,求EJB实例
- hibernate 初学问题:我这个列子怎么连编译都通不过啊? 多谢大家进来看看。
- org.hibernate.HibernateException:Could not parse configuration/hibernate.cfg.xml
- 求问BI方面的问题。
codebase设置的就是classPath