如何使数组列表可远程访问
我有一个项目,其中使用 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;
}
I have a project where I am using Java RMI to make objects remotely accessible to other objects. I need to make the following class remote:
public interface MarketBB extends Remote
{
public ArrayList<CloudEntry> getMarketBB() throws RemoteException;
public void moveAMP(int fromCloud, int toCloud) throws RemoteException;
}
The problem that I have is that because the ArrayList is holding CloudEntry objects, when the getMarketBB method is called from another object, nothing is returned.
Is there a way of making the ArrayList of CloudEntry classes remotely accessible?
Here is the code for the CloudEntry class:
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
}
And the CloudEntry interface:
public interface CloudEntry extends Remote {
public void setNoAmps(int noAmps) throws RemoteException;
public String getCloudName() throws RemoteException;
public String getCloudDetails() throws RemoteException;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
CloudEntryImpl
不可序列化。尝试将其更改为:Your
CloudEntryImpl
is not serializable. Try changing it to:getMarketBB() 返回 ArrayList 的副本。您不能让它返回列表的“实时”视图。
相反,我建议您提供与您尝试对列表执行的操作相匹配的方法。恕我直言,无论有没有 RMI,这都是最佳实践。
getMarketBB() returns a copy of the ArrayList. You cannot have it return a "live" view of the list.
Instead I would suggest you provide methods which match what you are trying to do with the list. IMHO This is best practice with or without RMI.