Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NX: Problem on using RMIFactory

 
hover cheng
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, all
I am trying to use the DAO Factory together with RMI: the server generates the "Data" object, and return it to the client through RMI on request. But here I encountered a problem:
In order to return a "Data" object through RMI, I make the "Data" class "implements Serializable"; in order to make "Data" class serializable, all the attribbutes of it must be serializable too, am I still on the way? So, how to make the attribute "RandomAccessFile db" serializable? I tried to wrap it with:
class SerializableRandomAccessFile extends RandomAccessFile implements Serializable{}
Then, I replace the "RandomAccessFile" attribute with "SerializableRandomAccessFile".
But, on running, an exception is thrown out, "java.io.InvalidClassException: java.io.RandomAccessFile Missing no-arg constructor for class", which mains the parentclass of "SerializableRandomAccessFile","RandomAccessFile", must has a no-arg constructor, which it hasn't eventually.
What should I do now? Does it means the RMIFactory for returning "Data" object is not feasible?
Hover Cheng
 
Ta Ri Ki Sun
Ranch Hand
Posts: 442
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , dont take my word for it and I'm sure someone will come along and explain this better, but I wouldn't pass Data object, i would instead pass the return values that i get from Data , either serialized or not depending on local or remote, but I definately wont be passing a RandomAccessFile or any other file object for that matter
 
hover cheng
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, Ta
Thanks for your response. Eventually, I have been considering the Adaptor pattern as well as DAO pattern. In your prefer, I think it should be the Adaptor category, am I right? I am trying to adopt the DAO pattern because I found it could make world easier, IF IT FEASIBLE, right? If it does work, on the client ctroller, we deal directly with the "Data" object, whatever it from local or remote.
The RandomAccessFile atrribute in the "Data" class is turning me down becuase of not serializable. If anybody could give me some suggestion to solve this problem? If no, I think I'd better turn to the Adaptor pattern....
Hover
 
hover cheng
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, buddies
I am wondering that if anyone has successfully used the DAO pattern to achieve the remote accessing. The server generate the "Data" object and then transfer it to client through RMI, as a return value of a method. Then the client can use this "Data" object to access data file directly. I think this is the most convenient and transparent for the client... The problem I encountered here is how to serrialize the "Data" object(considering the "RandomAccessFile" attribute, which is NOT serializable), in order to be marshalled by RMI? Comments are really appreciated.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic