• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Data Serialization

 
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I included a reference to Data in my DataServer (which subclassed UnicastRemoteObject).
If I tried using the reference to Data as an instance variable, I get a Serialization error.
How do you overcome this?
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim,
I replied to this last night but mistakenly addressed it to Samual. I believe that you are going to have to rethink your design on serializing Data. Anyway, here's the post:
Problems with serializing the Data object
Scroll down to the bottom and read the last two posts.
Michael Morris
[ August 13, 2002: Message edited by: Michael Morris ]
 
Jim Bedenbaugh
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Morris:
Hi Jim,
I replied to this last night but mistakenly addressed it to Samual. I believe that you are going to have to rethink your design on serializing Data. Anyway, here's the post:


Michael,
Thanks for the response. I read your posts and I understand that Data will not serialize. I found out on my own some time ago. What I'm trying to figure out is how to make calls to Data from my DataServer. If I include a reference to Data as an instance variable, I get a serialization error.
 
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a RemoteData object that has a private ref to Data. RemoteData implements Remote and my data interface, so it has methods to access all public methods in Data through that private reference. I am not getting any errors... do you have a similar settup?
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jim,
For my server, I just got a connection through the connection factory just like a client would and just like the client, calls were made on my DataAccess interface and not a Data object. Only objects in my db package actually had a reference to Data.
You may want to make calls on the interface through an object that implements your public Data interface for your server as well. That may solve the problem.
Hope this helps,
Michael Morris
 
Jim Bedenbaugh
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nate Johnson:
I have a RemoteData object that has a private ref to Data. RemoteData implements Remote and my data interface, so it has methods to access all public methods in Data through that private reference. I am not getting any errors... do you have a similar settup?


I had the same exact setup, except I'm not sure the reference to Data was private - I might have made it public. If so, than that would have been the issue, I'm pretty sure. I'll try and see if it works.
 
Jim Bedenbaugh
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Morris:
Hi Jim,
For my server, I just got a connection through the connection factory just like a client would and just like the client, calls were made on my DataAccess interface and not a Data object. Only objects in my db package actually had a reference to Data.


Thanks. I'll play around with this some more and see what I can do.
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I dont know if that would have made a difference... I had the same setup as Michael mentioned (and as I talked about above).
Factory returns my DataAccess (interface to RemoteData object) and I made the calls to Data reference through that interface (called the methods in Data).
I hope that was a better explanation.
 
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim,
Try removing any member variables of type Data and have a private method to find/create a Data instance for you in your DataRemote class. This private method in turn will use a factory to get the Data instance.
 
Jim Bedenbaugh
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nate (Sai or Michael, feel free to jump in too!),
So would this work (see skeleton code below)?

Then anytime I wanted to get a Data reference, I call getDataReference(filename) in DataFactory.
Question:
Okay, so will RMI serialize the dataReference that has been cast as a DataAccess interface and I can now make dataReference an instance(member) variable?
Or, if RMI will not serialize dataReference, does this imply that every method I have in DataServer that wants access to a Data methods (such as lock, unlock, etc.) will first have to call the geDataReference(filename) method and then make the call to Data?
Either way, the only thing I have to insure is that DataServer knows what the filename is anytime I return a reference.
I think I understand what you, Sai and Michael have been trying patiently to explain, but I'm still not sure I have the right understanding. Sorry if I seem a little obtuse. Thanks for your help and let me know if this will work.
 
Sai Prasad
Ranch Hand
Posts: 560
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim
No need to have a member variable that holds a DataAccess reference as long as you have a method to return that reference like in your example code. Also this way, DataAccess reference will neither be Serialized nor marshalled to the client tier.
 
Nate Johnson
Ranch Hand
Posts: 301
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is hard for me to see past my implementation without seeing the rest of your code, but I will see what I can do...
Your DataServer class... is that your server? The way I wrote my server was very different, it didnt act as a Data but as setup for my rmi factory...
main
1) create a "local" database on the server (Data)
2) pass that ref to my RemoteDataFactory (constructor) so it can keep a copy when getConn is called on it (which it turn creates a new RemoteData based on that database)
3) bind that RemoteDataFactory to the registry
end main

So, now in the client, get a ref to RemoteDataFactory (from Naming) when a remote connection is requested and call getConn. This will return a RemoteData object that has all of the methods that can access that "local" Data that was created back on the server. Each client can do this when it starts in remote mode and then be talking to the same Data, but with a unique RemoteData (which in turn can be used as the id for locking).
I am not sure if that will help with your server or not...

It looks like Sai may have answered you serialization questions... I know I didnt have to worry about serialization with the approach that I mentioned above.
[ August 14, 2002: Message edited by: Nate Johnson ]
 
Jim Bedenbaugh
Ranch Hand
Posts: 171
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Nate Johnson:

main
1) create a "local" database on the server (Data)
2) pass that ref to my RemoteDataFactory (constructor) so it can keep a copy when getConn is called on it (which it turn creates a new RemoteData based on that database)
3) bind that RemoteDataFactory to the registry
end main

So, now in the client, get a ref to RemoteDataFactory (from Naming) when a remote connection is requested and call getConn. This will return a RemoteData object that has all of the methods that can access that "local" Data that was created back on the server. Each client can do this when it starts in remote mode and then be talking to the same Data, but with a unique RemoteData (which in turn can be used as the id for locking).


So you end up only having one Data for all the connections? Then synchronizing the calls to Data prevents collisions. . .Okay, I see where you're going.
Thanks. I think I've got it now.
 
reply
    Bookmark Topic Watch Topic
  • New Topic