Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > ObjectInputStream and unknown object

Reply
Thread Tools

ObjectInputStream and unknown object

 
 
David Levitan
Guest
Posts: n/a
 
      03-16-2006
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
 
Reply With Quote
 
 
 
 
Ike
Guest
Posts: n/a
 
      03-16-2006
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


 
Reply With Quote
 
 
 
 
David Levitan
Guest
Posts: n/a
 
      03-16-2006
Ike wrote:
> 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
>
>



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
 
Reply With Quote
 
Chris Uppal
Guest
Posts: n/a
 
      03-17-2006
David Levitan wrote:

> 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


 
Reply With Quote
 
EJP
Guest
Posts: n/a
 
      03-20-2006
Ike wrote:

> 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?


No. Java still has to deserialize the members of the list, so the
problem will still arise in readObject().
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Assign an unknown value to an unknown variable Vincent Arnoux Ruby 1 08-11-2006 06:12 PM
ObjectInputStream and GZIPInputStream working together - newbie R Java 0 03-28-2005 01:22 PM
Re: creating ObjectInputStream takes forever Roedy Green Java 2 08-05-2003 10:30 PM
Re: creating ObjectInputStream takes forever Lothar Kimmeringer Java 3 08-01-2003 04:46 AM
objectInputStream.readObject() does not work properly after certain period of inactivity. Serial # 19781010 Java 1 07-15-2003 10:20 PM



Advertisments