Javaの違法なリモートメソッド
-
09-10-2019 - |
質問
Java RMI*を使用するのは初めてです。拡張するカスタムクラスがあります UnicastRemoteObject
リモートを拡張するインターフェイスを実装します。クラスでインターフェイスのメソッドを正しく実装したと思いますが、それでも IllegalArgumentException
コードを実行しようとするとき(そして、それは引数がない方法についてです)。
JVMは、違法なリモート方法に遭遇したと主張していますが、その方法とその実装は私には問題ないようです。
メソッドを誤って実装または呼び出すことを除いて、この例外が発生する可能性のある結果として他の理由はありますか?
これがスタックトレースです:
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
これがインターフェイスです:
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();
}
そして、これがクラスのコンストラクターです:
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();
}
解決
RMI上のすべての方法 Remote
インターフェイスは宣言する必要があります RemoteException
彼らに throws
条項、例:
public String getId() throws RemoteException;
例外名が明確ではありません getId()
具体的には、おそらくそれがチェックした最初の方法にすぎません。
また、 getLeafNodes()
と getNeighborhoodList()
メソッドには、指定する返品タイプが必要です Node
, 、 いいえ NodeImpl
, 、そうでなければ、おそらく失敗するでしょう。
所属していません StackOverflow