2014-12-08 7 views
0

У меня есть простая архитектура RMI - Client, Server. Как я хочу сделать обратные вызовы с сервера я определил следующие интерфейсы:Регистрация RMI-клиента приводит к ошибке IllegalArgumentException

public interface Meiern_RMI_Server extends Remote{ 
     public boolean registerClient(RMIClient client) throws RemoteException; 
    } 
    public interface Meiern_RMI_Client extends Remote{ 
     public void setTurn(boolean yourTurn) throws RemoteException; 
    } 

А вот Impls (Сервер):

public class RMIServer extends UnicastRemoteObject implements Meiern_RMI_Server{ 

    private Set<RMIClient> clients; 

    public RMIServer() throws RemoteException { 
     super(); 
     this.clients = new HashSet<RMIClient>(); 
    } 

    public static void main(String [] args){ 
     try { 
      Registry reg = LocateRegistry.createRegistry(1234); 
      reg.rebind("server", new RMIServer()); 
      System.out.println("server started"); 
     } catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 

    @Override 
    public synchronized boolean registerClient(RMIClient client) throws RemoteException { 
     boolean registered = false; 
     try { 
      registered = clients.add(client); 
      if(registered) { 
       System.out.println("Client " + client.getName() + " registered."); 
       System.out.println(clients); 
      } else { 
       System.out.println("Could not register client. Duplicate names " + client.getName());    
      } 
     } catch (Exception e) { 
      e.printStackTrace(); 
     } 
     return registered; 
    } 

} 

Клиент:

public class RMIClient extends UnicastRemoteObject implements Meiern_RMI_Client {  public RMIClient() throws RemoteException { 
     super(); 
    } 

    @Override 
    public void setTurn(boolean yourTurn) throws RemoteException { 
     throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. 
    } 
    public static void main(String [] args) { 
     try { 
      RMIClient client = new RMIClient(); 

      Registry reg = LocateRegistry.getRegistry("127.0.0.1", 1234); 
      Meiern_RMI_Server rmi = (Meiern_RMI_Server)reg.lookup("server"); 
      System.out.println("client connected"); 
      boolean registered = rmi.registerClient(client); 
      if(registered){ 
       System.out.println("Client registered"); 
      } else { 
       System.out.println("Could not register client, Change name"); 
      } 

      while (true) { 

      } 
     } catch (Exception e) { 
      System.out.println("Could not connect to server: "); 
      e.printStackTrace(); 
     } 
    } 


} 

при попытке зарегистрировать клиент, следующее исключение происходит на стороне клиента:

java.lang.IllegalArgumentException: argument type mismatch 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:322) 
    at sun.rmi.transport.Transport$1.run(Transport.java:177) 
    at sun.rmi.transport.Transport$1.run(Transport.java:174) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at sun.rmi.transport.Transport.serviceCall(Transport.java:173) 
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:556) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:811) 
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:670) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:745) 
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:275) 
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:252) 
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:161) 
    at java.rmi.server.RemoteObjectInvocationHandler.invokeRemoteMethod(RemoteObjectInvocationHandler.java:194) 
    at java.rmi.server.RemoteObjectInvocationHandler.invoke(RemoteObjectInvocationHandler.java:148) 
    at com.sun.proxy.$Proxy1.registerClient(Unknown Source) 
    at meiern.RMIClient.main(RMIClient.java:97) 

Любые предложения?

ответ

1
public boolean registerClient(RMIClient client) throws RemoteExceptio 

Вы не можете использовать экспортированные типы удаленных объектов в качестве параметра удаленного метода или возвращаемых типов. Измените его на:

public boolean registerClient(Myeiern_RMI_Client client) throws RemoteException