org.openejb.core.ivm
Class IntraVmArtifact

java.lang.Object
  extended by org.openejb.core.ivm.IntraVmArtifact
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable

public class IntraVmArtifact
extends java.lang.Object
implements java.io.Externalizable

This class represents all artifacts of the IntraVM in a stream.

Classes create this object in the writeReplace method.

When the object is serialized, the writeReplace method is invoked and this artifact is written to the stream instead. The original object instance is placed in a HashMap and not serialized.

During deserialization, it is this object that is deserialized. This class implements the readResolve method of the serialization API. In the readResolve method, the original object instance is retrieved from the HashMap and returned instead.

Basically, we mark all local serialization operations the same way you would mark a transaction.

LOCAL to LOCAL SERIALIZATION

Definition:

This is a full serialization/deserialization takes place in the local vm inside the marked scope of the IntraVM server.

Circumstances:

When an IntraVM implementation of a javax.ejb.* interface is serialized in the scope of a local IntraVM serialization.

These serializations happen when objects are passed as parameters or return values from one client/ejb to another client/ejb running inside the same VM.

Action:

Temporarily cache the instance in memory during serialization, retrieve again during deserialization.

Example Scenario:

BEFORE SERIALIZATION

1. Call IntraVmCopyMonitor.preCopyOperation().
2. Method parameters are sent to ObjectOutputStream.

SERIALIZATION

3. ObjectOutputStream encounters an IntraVmMetaData instance in the object graph and calls its writeReplace method.
4. The IntraVmMetaData instance determines it is being serialized in the scope of an IntraVM serialization by calling IntraVmCopyMonitor.isIntraVmCopyOperation().
5. The IntraVmMetaData instance creates an IntraVmArtifact that caches it in a static hashtable keyed on a combination of the thread id and instance hashCode.
6. The IntraVmMetaData instance returns the IntraVmArtifact instance from the writeReplace method.
7. The ObjectOutputStream serializes the IntraVmArtifact instance in place of the IntraVmMetaData instance.

DESERIALIZATION

8. ObjectInputStream encounters and deserializes an IntraVmArtifact instance and calls its readResolve method.
9. The IntraVmArtifact instance uses the key it created in step 5 to retrieve the IntraVmMetaData instance from the static hashtable.
10. The IntraVmArtifact instance returns the IntraVmMetaData instance from the readResolve method.
11. ObjectInputStream places the IntraVmMetaData instance in the object graph in place of the IntraVmArtifact instance.

AFTER

12. Method parameters are now de-referenced as mandated by the spec and can be passed into the bean's method.
13. IntraVmCopyMonitor.postCopyOperation() is called, ending the local IntraVm serialization scope.

Author:
David Blevins, Richard Monson-Haefel
See Also:
Serialized Form

Constructor Summary
IntraVmArtifact()
          This class is Externalizable and this public, no-arg, constructor is required.
IntraVmArtifact(java.lang.Object obj)
          Used to creat an IntraVmArtifact object that can represent the true intra-vm artifact in a stream.
 
Method Summary
 void readExternal(java.io.ObjectInput in)
          Reads the instanceHandle from the stream
 void writeExternal(java.io.ObjectOutput out)
          Writes the instanceHandle to the stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

IntraVmArtifact

public IntraVmArtifact(java.lang.Object obj)
Used to creat an IntraVmArtifact object that can represent the true intra-vm artifact in a stream.

Parameters:
obj - The object instance this class should represent in the stream.

IntraVmArtifact

public IntraVmArtifact()
This class is Externalizable and this public, no-arg, constructor is required. This constructor should only be used by the deserializing stream.

Method Detail

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Writes the instanceHandle to the stream.

Specified by:
writeExternal in interface java.io.Externalizable
Parameters:
out -
Throws:
java.io.IOException

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException
Reads the instanceHandle from the stream

Specified by:
readExternal in interface java.io.Externalizable
Parameters:
in -
Throws:
java.io.IOException


Copyright © 1999-2011 OpenEJB. All Rights Reserved.