Question

Il est la première fois que je utilise Java Rmi *. J'ai une classe personnalisée qui étend UnicastRemoteObject et implémente une interface qui s'étend à distance. Je pense que je l'ai mis en œuvre les méthodes de l'interface correctement dans la classe mais je reçois un IllegalArgumentException quand je tente d'exécuter mon code (et il est sur une méthode qui n'a pas d'arguments).

Les revendications jvm avoir rencontré une méthode distante illégale mais la méthode et sa mise en œuvre semble bien pour moi.

Y at-il une autre raison en raison de cette exception qui pourrait se produire à l'exception de la mise en œuvre ou en appelant la méthode à tort?


Voici la trace de la pile:

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

Voici l'interface:

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();
}

et voici le constructeur de la 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();
    }
Était-ce utile?

La solution

Toutes les méthodes sur une interface Remote RMI doit déclarer RemoteException dans leur clause throws, par exemple:.

public String getId() throws RemoteException;

On ne sait pas pourquoi les noms d'exception getId() spécifiquement, il est probablement juste la première méthode, il vérifié.

En outre, les méthodes de getLeafNodes() et getNeighborhoodList() devrait avoir des types de retour qui spécifient Node, non NodeImpl, sinon ils vont probablement échouer aussi.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top