org.openejb.core.ivm
Class IntraVmCopyMonitor

java.lang.Object
  extended by org.openejb.core.ivm.IntraVmCopyMonitor

public class IntraVmCopyMonitor
extends java.lang.Object

This class is used to demarcate intra-VM copy operations so that intra-VM artifacts such as IntraVmHandle, IntraVmMetaData, and BaseEjbProxyHandlers (EjbHomeProxyHandler and EjbObjectProxyHandler) can know when they should replace themselves during serialization with an IntraVmArtifact or a application server specific artifact.

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.

Version:
$Revision: 1921 $ $Date: 2005-06-19 15:40:34 -0700 (Sun, 19 Jun 2005) $
Author:
David Blevins, Richard Monson-Haefel

Method Summary
static boolean exists()
           
static boolean isIntraVmCopyOperation()
          Returns true if the current operation is an IntraVM copy.
static boolean isStatefulPassivationOperation()
          Returns true if the current operation is the passivation of a stateful session bean.
static void postCopyOperation()
          Notifies the monitor for this thread just after a copy operation has taken place.
static void postPassivationOperation()
          Notifies the monitor for this thread just after a stateful session bean is passified.
static void preCopyOperation()
          Notifies the monitor for this thread just before a copy operation is to take place.
static void prePassivationOperation()
          Notifies the monitor for this thread just before a stateful session bean is passified.
static void release()
          Not to be used lightly.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

exists

public static boolean exists()

release

public static void release()
Not to be used lightly. This class is more performant if every thread has a ThreadContext set only use this method if the thread is never going to re-access the container.


preCopyOperation

public static void preCopyOperation()
Notifies the monitor for this thread just before a copy operation is to take place. This happens when one bean access another bean and arguments or return values are copied.


postCopyOperation

public static void postCopyOperation()
Notifies the monitor for this thread just after a copy operation has taken place. This happens when one bean access another bean and arguments or return values are copied.


prePassivationOperation

public static void prePassivationOperation()
Notifies the monitor for this thread just before a stateful session bean is passified. This happens when a stateful session bean is passified and all its member variables are serialized.


postPassivationOperation

public static void postPassivationOperation()
Notifies the monitor for this thread just after a stateful session bean is passified. This happens when a stateful session bean is passified and all its member variables are serialized.


isIntraVmCopyOperation

public static boolean isIntraVmCopyOperation()
Returns true if the current operation is an IntraVM copy.

Returns:
boolean

isStatefulPassivationOperation

public static boolean isStatefulPassivationOperation()
Returns true if the current operation is the passivation of a stateful session bean.

Returns:
boolean


Copyright © 1999-2011 OpenEJB. All Rights Reserved.