我有一个项目,正在使用Java RMI使对象可以被其他对象远程访问。我需要将以下课程设为远程:
public interface MarketBB extends Remote
{
public ArrayList<CloudEntry> getMarketBB() throws RemoteException;
public void moveAMP(int fromCloud, int toCloud) throws RemoteException;
}
我遇到的问题是,因为ArrayList持有CloudEntry对象,所以从另一个对象调用getMarketBB方法时,什么也不会返回。
有没有一种方法可以远程访问CloudEntry类的ArrayList?
这是CloudEntry类的代码:
public class CloudEntryImpl implements CloudEntry {
int cloudId;
String cloudName;
double speedGHz;
double costPerGhzH;
double commsCost;
double commsTime;
int noAMPs;
//constructor, get and set methods for fields
}
和CloudEntry接口:
public interface CloudEntry extends Remote {
public void setNoAmps(int noAmps) throws RemoteException;
public String getCloudName() throws RemoteException;
public String getCloudDetails() throws RemoteException;
}
最佳答案
您的CloudEntryImpl
不可序列化。尝试将其更改为:
public class CloudEntryImpl extends UnicastRemoteObject implements CloudEntry {
//...
}