毕业论文开发语言企业开发JAVA技术.NET技术WEB开发Linux/Unix数据库技术Windows平台移动平台嵌入式论文范文英语论文
您现在的位置: 毕业论文 >> java技术 >> 正文

News_register_factoryDAO factory = (News_register_factoryDAO) Naming.lookup("demo");找不到 News_register_factory_stub

更新时间:2012-5-15:  来源:毕业论文

服务器类:News_register_factory

Java code
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();
        }
       
    }
}
我编辑的测试类如下:
服务器类:News_register_factory

Java code
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全部部署在服务端本地。


客户端类:

Java code
package LookUpImp;

[1] [2] [3] 下一页

设为首页 | 联系站长 | 友情链接 | 网站地图 |

copyright©youerw.com 优尔论文网 严禁转载
如果本毕业论文网损害了您的利益或者侵犯了您的权利,请及时联系,我们一定会及时改正。