Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / March 2006

Tip: Looking for answers? Try searching our database.

ObjectInputStream and unknown object

Thread view: 
David Levitan - 16 Mar 2006 03:54 GMT
I'm having an issue with ObjectInputStreams. I have two JVM instances
running, communicating via ObjectInputStream/ObjectOutputStreams. Call
them instance A and instance B.
The basic way the program works is that A sends B some data, B does
something to it, and sends back a result that is an object containing
several other objects. Until today, this has worked fine, but all
objects being sent back and forth were either part of the code base for
A and B or a standard java package.
Today a situation came up where B is sending back an object that is a
subclass of one of the classes in A/B's codebase, but is not in the
codebase itself. Based on my debugging, B sends the result (which
contains this object) successfully, but A just hangs trying to read the
object. The new object is in B's classpath but is not in A's classpath
This new object seems to be the reason for the hang, since I haven't
seen this behavior before. I'm wondering if anyone can comment on this
and whether dynamically changing the classpath would solve the issue, or
whether there is a more elegant way of solving the issue.
I'll be happy to provide more details if needed.

Thanks,
David
Ike - 16 Mar 2006 12:51 GMT
Hi David,

Have you tried wrapping the Object(s) passed in a collections class like an
ArrayList, then merely pass the ArrayList, looking therefore for an
ArrayList on the other side?

Only when you iterate through the ArrayList after receiving it, the
unknown-classed object should then throw an exception of some sort,and you
might be able to try-catch it there, after the OutPutStreams have completed
their work?

HTH -Ike
David Levitan - 16 Mar 2006 13:51 GMT
> Hi David,
>
[quoted text clipped - 8 lines]
>
> HTH -Ike

The actual object being transmitted is a wrapper class - the instance
receiving the object never gets out of the readObject method. I do know
adding the previously unknown object to the classpath does make it work
(I confirmed this yesterday), but I need to change the path dynamically
and have no idea how to remove directories dynamically (I know how to
add them).
Thanks,
David
EJP - 20 Mar 2006 07:03 GMT
> Have you tried wrapping the Object(s) passed in a collections class like an
> ArrayList, then merely pass the ArrayList, looking therefore for an
[quoted text clipped - 4 lines]
> might be able to try-catch it there, after the OutPutStreams have completed
> their work?

No. Java still has to deserialize the members of the list, so the
problem will still arise in readObject().
Chris Uppal - 17 Mar 2006 14:33 GMT
> Today a situation came up where B is sending back an object that is a
> subclass of one of the classes in A/B's codebase, but is not in the
> codebase itself.

It's a bit tricky to manage this.  If the two applications don't have a common
set of .class files, then you'll have to find some way to do one of two things:

a)  Only transmit objects which /are/ shared.  This may force you to convert
objects from one side or the other into some sort of neutral common form before
sending them.  Not too nice...

b) Use classloaders to share the code dynamically.  Also painful, but perhaps
not as bad.

Before getting into that, it's worth pointing out that RMI already has features
for doing this kind of thing for you, so if you haven't looked at RMI then it
might be worth doing so.

Anyway, concentrating on (b).  There are two issues here.

The first is classloaders, what they do, and how they work.  If you don't know
how to use classloaders, then now is the time to find out ;-)  Once you have
done, then you will understand how to use custom classloaders to control almost
every aspect of where an application looks for class definitions.

The second issue is how to tell the ObjectInputStream to use your custom
classloader.  That's a lot simpler -- it's just a matter of creating a custom
subclass of ObjectInputStream which overrides the definition of resolveClass().
In fact you might not even have to do that, if the class which uses the
ObjectInputStream was itself loaded by your custom classloader.

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.