Domanda

E 'la prima volta che uso io Java RMI *. Ho una classe personalizzata che si estende UnicastRemoteObject e implementa un'interfaccia che si estende a distanza. Penso che ho implementato i metodi dell'interfaccia in modo corretto nella classe, ma ancora ottengo un IllegalArgumentException quando provo a fare funzionare il mio codice (e si tratta di un metodo che non ha argomenti).

Le rivendicazioni JVM di aver incontrato un metodo remoto illegale, ma il metodo e la sua implementazione sembrano bene a me.

C'è qualche altra ragione a seguito della quale si potrebbe verificare questa eccezione fatta eccezione per l'attuazione o chiamando il metodo sbagliato?


Ecco la traccia dello stack:

SEVERE: null
java.rmi.server.ExportException: remote object implements illegal remote interface; nested exception is:
        java.lang.IllegalArgumentException: illegal remote method encountered: public abstract java.lang.String Node.getId()
        at sun.rmi.server.UnicastServerRef.exportObject(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.exportObject(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.<init>(Unknown Source)
        at java.rmi.server.UnicastRemoteObject.<init>(Unknown Source)
        at NodeImpl.<init>(NodeImpl.java:30)
        at NodeLauncher.main(NodeLauncher.java:11)
Caused by: java.lang.IllegalArgumentException: illegal remote method encountered: public abstract java.lang.String Node.getId()
        at sun.rmi.server.Util.checkMethod(Unknown Source)
        at sun.rmi.server.Util.getRemoteInterfaces(Unknown Source)
        at sun.rmi.server.Util.getRemoteInterfaces(Unknown Source)
        at sun.rmi.server.Util.createProxy(Unknown Source)
        ... 7 more

Ecco l'interfaccia:

import java.rmi.*;
import java.util.LinkedList;

interface Node extends Remote
{
    public boolean isAlive();

    public LinkedList<NodeImpl> getLeafNodes();

    public LinkedList<NodeImpl> getNeighborhoodList();

    public String [] getRoutingTable();

    public NodeImpl initiation(String credentials,Object application);

        public String route(String message,String key);

        public void inform(byte [] id);

        public String getId();

        public boolean isConnected();

        public void applicationClose();

        public boolean distanceMeasure();
}

Ed ecco il costruttore della classe:

public NodeImpl() throws RemoteException
    {
        super();
        l=4;
        M=1;
        nodeId=new byte [16];
        Random r=new Random();
        r.nextBytes(nodeId);
        leafNodes=new LinkedList<NodeImpl>();
        connected=false;
        ng=new NodeGUI(this);

        for(int i=0;i<l;i++)
        {
            leafNodes.add(null);
        }

        neighborhoodList=new LinkedList<NodeImpl>();
        anyNodeWhoAnswered=new LinkedList<byte []>();
        it=new InformingTimer(this);
        Thread informingTimerThread=new Thread(it);
        informingTimerThread.start();

        try 
        {
            Naming.rebind("rmi://" + "localhost" + ":1099/"+nodeId, this);
        }
        catch (Exception ex) 
        {
            Logger.getLogger(NodeImpl.class.getName()).log(Level.SEVERE, null, ex);
        }

        bootstrap();
    }
È stato utile?

Soluzione

Tutti i metodi di un'interfaccia Remote RMI devono dichiarare RemoteException nella loro clausola throws, per esempio:.

public String getId() throws RemoteException;

Non è chiaro il motivo per cui i nomi delle eccezioni getId() specifico, probabilmente è solo il primo metodo di farlo controllare.

Inoltre, i metodi e getLeafNodes() getNeighborhoodList() dovrebbe avere tipi restituiti che specificano Node, non NodeImpl, altrimenti saranno probabilmente fallire anche.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top