同一台 PC 上的两个 RMI 注册表,NotBoundException [英] Two RMI registries on the same PC, NotBoundException

查看:50
本文介绍了同一台 PC 上的两个 RMI 注册表,NotBoundException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

场景:我正在 2 台 PC 之间实现 RMI 示例,其中控制器 PC 向代理 PC 查询信息.代理 PC 可能运行 Xen 或 KVM ,因此查询的实现不同(使用 RMI 的原因).在代理端,我正在运行 2 个绑定到两个不同端口的 RMI 注册表.当在代理端仅使用 1 个注册表执行相同的示例时,一切正常.

Scenario: I'm implementing an RMI example between 2 PCs where the Controller PC queries the Agent PC for information. The agent PC may run Xen or KVM , hence the implementations of the queries differ(Reason for using RMI). On the Agent's side I'm running 2 RMI registries bound to two different ports. When the same example is carried out with just 1 Registry on the agent's side, everything works fine.

这是我的代码:控制器.java(包含控制器端的 main()):

Here is my code: Controller. java(contains main() on controller's side):

public class Controller {

NetworkDiscovery n;
public static int discoveryInterval=2000;
static public PM pmlist;

public static void main(String[] args) throws UnknownHostException,NotBoundException, `   MalformedURLException, RemoteException {

pmOperations pm=(pmOperations)Naming.lookup("rmi://Agent_IP/RMIService1");
boolean l= pm.CreateVM("apple3","/var/lib/libvirt/images",1,200);
System.out.println(l);

vmOperations vm=(vmOperations)Naming.lookup("rmi://Agent_IP/RMIService2");
boolean ShutdownVM = vm.ShutdownVM("apple1");
System.out.println(ShutdownVM);
//other code
}

pmOperations.java(在控制器端)(在代理端,它与函数内部的实现代码具有相同的定义)

pmOperations.java(on controller's side)(on the agent's side, it has the same defn with implementation code inside function)

public interface pmOperations extends java.rmi.Remote{
    public boolean CreateVM(String vmName,String imgSrc, int allotCPU, int allotMem )
    throws java.rmi.RemoteException;
}

vmOperations.java(在控制器端)(在代理端,它与函数内部的实现代码具有相同的定义)

vmOperations.java(on controller's side)(on the agent's side, it has the same defn with implementation code inside function)

public interface vmOperations extends java.rmi.Remote{
    boolean ChangeVMParam(String vmName,String paramName,String paramValue)
    throws java.rmi.RemoteException;
}

代理.java

public class Agent {

Agent() throws RemoteException, MalformedURLException{
    Registry RMIService1 = LocateRegistry.createRegistry(1099);

    Registry RMIService2 = LocateRegistry.createRegistry(4478);

        vmOperations vmOp = new kvmVM();
        pmOperations pmOp = new kvmPM();

      Naming.rebind("rmi://localhost:1099/RMIService1", pmOp);
      Naming.rebind("rmi://localhost:4478/RMIService2", vmOp);
}

public static void main(String[] args) throws SocketException, UnknownHostException, IOException, LibvirtException {

        System.out.println("Inside main ");
        new Agent();
        //other code
}
}

在控制器端运行以上代码时出现错误 - 在代理端没有错误:

Error I get while running above code on controller's side-no error on agent side:

线程main"中的异常 java.rmi.NotBoundException: RMIService2在 sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:106)在 sun.rmi.registry.RegistryImpl_Skel.dispatch(来源不明)在 sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386)在 sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250)在 sun.rmi.transport.Transport$1.run(Transport.java:159)在 java.security.AccessController.doPrivileged(Native Method)在 sun.rmi.transport.Transport.serviceCall(Transport.java:155)在 sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535)在 sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790)在 sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649)在 java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)在 java.lang.Thread.run(Thread.java:662)在 sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255)在 sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233)在 sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359)在 sun.rmi.registry.RegistryImpl_Stub.lookup(来源不明)在 java.rmi.Naming.lookup(Naming.java:84)在 package1.Controller.main(Controller.java:43)

Exception in thread "main" java.rmi.NotBoundException: RMIService2 at sun.rmi.registry.RegistryImpl.lookup(RegistryImpl.java:106) at sun.rmi.registry.RegistryImpl_Skel.dispatch(Unknown Source) at sun.rmi.server.UnicastServerRef.oldDispatch(UnicastServerRef.java:386) at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:250) at sun.rmi.transport.Transport$1.run(Transport.java:159) at java.security.AccessController.doPrivileged(Native Method) at sun.rmi.transport.Transport.serviceCall(Transport.java:155) at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:535) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:790) at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:649) at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) at java.lang.Thread.run(Thread.java:662) at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:255) at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:233) at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:359) at sun.rmi.registry.RegistryImpl_Stub.lookup(Unknown Source) at java.rmi.Naming.lookup(Naming.java:84) at package1.Controller.main(Controller.java:43)

谢谢!

推荐答案

您不能在同一个 JVM 中创建两个注册表.同一主机中不需要两个注册表.您不需要创建远程对象的两个实例.

You can't create two Registries in the same JVM. You don't need two Registries in the same host. You don't need to create two instances of the remote object.

只需创建一个 Registry,一个 远程对象,并将其绑定到Registry 两次,每个名称绑定一次.你也不需要将它绑定两次.这个设计中有很多毫无意义的重复.

Just create one Registry, one remote object, and bind it to the Registry twice, once with each name. You don't really need to bind it twice either really either. There's a lot of pointless duplication in this design.

这篇关于同一台 PC 上的两个 RMI 注册表,NotBoundException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆