Serialization of objects and their PropertyChangeListeners - Weblogic

This is a discussion on Serialization of objects and their PropertyChangeListeners - Weblogic ; I have a question pertaining to serialization. I have a thick client that consumes EJBs deployed on WLS 8.1 sp2. Some of the information passed between EJBs and the client app is in the form of lists of objects. These ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Serialization of objects and their PropertyChangeListeners

  1. Serialization of objects and their PropertyChangeListeners

    I have a question pertaining to serialization. I have a thick client
    that consumes EJBs deployed on WLS 8.1 sp2. Some of the information
    passed between EJBs and the client app is in the form of lists of
    objects. These can be modified on the client and returned to the
    server. I have what I term a BusinessList (a 'smart' collection) that
    registers as a PropertyChangeListener on each of its elements - as
    they are added to the BusinessList on the server. The BusinessList
    tracks changes to its elements, and this enables certain other
    processing during the commit process. Also, a BusinessList is itself a
    property change announcer - occasionally I have a BusinessList
    listening for changes to another BusinessList. The BusinessList and
    its elements all use the java.beans.PropertyChangeSupport class to
    manage each object's listener-list. In all cases, the
    PropertyChangeSupport data member is transient, and is reinstantiated
    in each object's readObject() method. The BusinessList class
    additionally overrides the readResolve() method, where it
    reestablishes itself as a property change listener on each of its
    element objects.


    For example, in the BusinessList class:


    private void readObject( ObjectInputStream ois ) throws
    ClassNotFoundException, IOException
    {
    ois.defaultReadObject();
    propertyChangeListeners = new PropertyChangeSupport( this );
    }

    private Object readResolve() throws ObjectStreamException
    {
    // Reestablish listening to this BusinessList's elements (and
    maybe other BusinessLists)
    registerAsElementListenerWithAll();
    return this;
    }


    Everything is working at present. I am somewhat uncomfortable with the
    BusinessList's readResolve() method, as the
    registerAsElementListenerWithAll() method will be calling methods on
    other objects - specifically addPropertyChangeListener(). Apparently
    the list elements have been deserialized prior to the BusinessList's
    readResolve() method's invocation.

    So... Is this a behavior that can be counted on? Is this the best
    approach?

    Thanks for listening,
    Jim

  2. Re: Serialization of objects and their PropertyChangeListeners

    jjanzen@guardian.com (Jim Janzen) wrote in message news:<84512d8e.0406240607.4c2d7f94@posting.google.com>...
    > I have a question pertaining to serialization. I have a thick client
    > that consumes EJBs deployed on WLS 8.1 sp2. Some of the information
    > passed between EJBs and the client app is in the form of lists of
    > objects. These can be modified on the client and returned to the
    > server. I have what I term a BusinessList (a 'smart' collection) that
    > registers as a PropertyChangeListener on each of its elements - as
    > they are added to the BusinessList on the server. The BusinessList
    > tracks changes to its elements, and this enables certain other
    > processing during the commit process. Also, a BusinessList is itself a
    > property change announcer - occasionally I have a BusinessList
    > listening for changes to another BusinessList. The BusinessList and
    > its elements all use the java.beans.PropertyChangeSupport class to
    > manage each object's listener-list. In all cases, the
    > PropertyChangeSupport data member is transient, and is reinstantiated
    > in each object's readObject() method. The BusinessList class
    > additionally overrides the readResolve() method, where it
    > reestablishes itself as a property change listener on each of its
    > element objects.
    >
    >
    > For example, in the BusinessList class:
    >
    >
    > private void readObject( ObjectInputStream ois ) throws
    > ClassNotFoundException, IOException
    > {
    > ois.defaultReadObject();
    > propertyChangeListeners = new PropertyChangeSupport( this );
    > }
    >
    > private Object readResolve() throws ObjectStreamException
    > {
    > // Reestablish listening to this BusinessList's elements (and
    > maybe other BusinessLists)
    > registerAsElementListenerWithAll();
    > return this;
    > }
    >
    >
    > Everything is working at present. I am somewhat uncomfortable with the
    > BusinessList's readResolve() method, as the
    > registerAsElementListenerWithAll() method will be calling methods on
    > other objects - specifically addPropertyChangeListener(). Apparently
    > the list elements have been deserialized prior to the BusinessList's
    > readResolve() method's invocation.
    >
    > So... Is this a behavior that can be counted on? Is this the best
    > approach?
    >
    > Thanks for listening,
    > Jim



    [follow up]

    It turns out that we have decided to use the validation feature on the
    ObjectInputStream class instead of the readResolve() approach.
    According to the spec, Java guarantees that validation will not take
    place until the complete object graph has been deserialized.


    private void readObject( ObjectInputStream ois ) throws
    ClassNotFoundException, IOException
    {
    ois.registerValidation(new ElementRegisterer(),0);
    ois.defaultReadObject();
    propertyChangeListeners = new PropertyChangeSupport( this );
    }

    private void writeObject( ObjectOutputStream oos ) throws
    IOException
    {
    oos.defaultWriteObject();
    }

    private class ElementRegisterer implements ObjectInputValidation
    {
    public void validateObject() throws InvalidObjectException
    {
    try {
    registerAsElementListenerWithAll();
    }
    catch ( Exception ex ) {
    throw new InvalidObjectException( ex.getMessage() );
    }
    }
    }

+ Reply to Thread