RMI注册表和非法参数例外

时间:2016-05-29 17:11:37

标签: java proxy rmi middleware

我使用RMI的项目是如此分散:

两个接口,ISportello和IGestoreSportelli。

public interface IGestoreSportelli extends Remote {


public boolean sottoponiRichiesta (int id) throws RemoteException;
public void sottoscrivi (ISportello sportello) throws RemoteException;

}


public interface ISportello {
public boolean serviRichiesta(int id) throws RemoteException;
 }

实现应用程序逻辑的两个类,并实现接口:GestoreSportelliImplementazione和SportelloImplementazione

   public class GestoreSportelliImplementazione implements IGestoreSportelli{

public Vector<ISportello> sportelli = new Vector<ISportello>();
@Override
public boolean sottoponiRichiesta(int id) throws RemoteException {
    System.out.println("Processo la richiesta: id:" + id);
    int size = sportelli.size();
    int i=0;
    boolean esito = false;

    do {
        esito = sportelli.get(i++).serviRichiesta(id);
    }while(i<size && !esito);

    return esito;
}

@Override
public void sottoscrivi(ISportello sportello) throws RemoteException {
    System.out.println("[GESTORE] Aggiungo un nuovo sportello");
    System.out.println("SPORTELLO: " + sportello);
    sportelli.add(sportello);

}

  }


 @SuppressWarnings("serial")
 public class SportelloImplementazione extends UnicastRemoteObject implements ISportello{

protected SportelloImplementazione() throws RemoteException {
    super();
}

@Override
public boolean serviRichiesta(int id) throws RemoteException {
    // TODO Auto-generated method stub
    return true;
}

 }

第二课是一个存根(当我知道为什么程序不能正常工作时,我会进一步发展。)

两个主要功能的类,#34; wrap&#34;前两个班级

public class GestoreSportelliServer {

public static void main(String[] args) {
    try {
    IGestoreSportelli gestore = new GestoreSportelliImplementazione();
    Registry rmi = LocateRegistry.getRegistry();
    IGestoreSportelli gestoreRef = (IGestoreSportelli) UnicastRemoteObject.exportObject(gestore,0);
    System.out.println("[GESTORE] AVVIATO");
    System.out.println("[GESTORE] " + gestore);
    rmi.rebind("gestore", gestoreRef);
    System.out.println("[GESTORE] Registrato");
    }
    catch (RemoteException r)
    {
        r.printStackTrace();
    }
}
}



public class SportelloServer {

public static void main(String[] args) {
    try {
    Registry rmi = LocateRegistry.getRegistry();
    ISportello sportello = new SportelloImplementazione();
    System.out.println("[SPORTELLO] : " + sportello);
    IGestoreSportelli gestore  =(IGestoreSportelli) rmi.lookup("gestore");
    gestore.sottoscrivi(sportello);
    System.out.println("[SPORTELLO] Sottoscrizione avvenuta");
    }
    catch (RemoteException r)
    {
        r.printStackTrace();

    }

    catch (NotBoundException n)
    {
        n.printStackTrace();
    }

    catch (IllegalArgumentException i)
    {
        i.printStackTrace();

的System.out.println(i.getmessage());         }

}

}

我在两个差异提示窗口中运行带有main的类,第三个提示窗口运行RMIRegistry。 SportelloServer课程不起作用。它遇到了一个例外:

 java.lang.IllegalArgumentException: java.lang.ClassCastException@547d534d
at sun.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.rmi.server.UnicastServerRef.dispatch(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at sun.rmi.transport.Transport$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.Transport.serviceCall(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport.handleMessages(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(Unknown Source)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(Unknown Source)
at sun.rmi.transport.StreamRemoteCall.executeCall(Unknown Source)
at sun.rmi.server.UnicastRef.invoke(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(Unknown Source)
at java.rmi.server.RemoteObjectInvocationHandler.invoke(Unknown Source)
at com.sun.proxy.$Proxy1.sottoscrivi(Unknown Source)
at server.SportelloServer.main(SportelloServer.java:19)
java.lang.ClassCastException@547d534d

#19行是:

gestore.sottoscrivi(sportello);

1 个答案:

答案 0 :(得分:0)

两个接口都必须扩展Remote:

def get_input():
    while True:
        choice = input("[R]ock, [P]aper, or [S]cissors? ").lower()
        if choice == 'r':
            return 'rock'
        elif choice == 'p':
            return 'paper'
        elif choice == 's':
            return 'scissors'
        # go through the loop again.

choice = get_input()
print(choice)

是否是正确的ISportello代码