FeaturesPluginsDocs & SupportCommunityPartners

Transient Metadata

Author:Tomas Zezula
Version:1.0
Note: The API described in this document is not an official contract and may change without preserving a backward compatibility. Such changes will be announced in advance on MDR mailing lists.

Intention

To provide model elements whose end of lifecycle is controlled by the JVM garbage collector in addition to the refDelete operation.

Motivation

The model of Java language needs to hold same temporary data which should not persist (e.g. JavaDoc, position in the source file,...). The Java module supplies references to this model elements to its clients, so it is hard for it to control their livecycle. The transient metadata provides elegant solution of this problem. The developer only marks the Class as transient during creation of model, modifies model to fullfill the requirements for transient metadata (described below) and imports the model into the MDR. The deletion of unreferenced elements is done automatically by the MDR engine.

Limitations

The tansient model elements have several limitations in comparison to the standard model elements.

  • The first limitation concerns the inherited associations. The following association usages are forbidden.
    1. Inheritance of nontransient class from transient class
    2. Inheritance of transient class from nontransient class
    In the situation 1. the transient class (ClassA) defines association to ClassC. The non transient class (ClassB) inherits from ClassB. But adding the instances of ClassB into the association is forbidden. Similarly in the situation 2. where the nontransient class (ClassA) defines the association to ClassC and the transient class (ClassB) is subclass of ClassA the instances of ClassB can not be added into the association. Instead of using the single association the association has to be split into two associations (one for non transient class and second for transient class) as shown on the following picture.
    Split of association into two independent associations for transient and nontransient class.
  • Change in Collection.size() and Iterator.next () behavior.
    Due to the essence of the transient metadata the transient element can be freed by the garbage collector when it is not hard referenced. So, the two consequent calls of the Collection's size method can return different number of elements in the collection if the garbage collector is activated between this two calls. The same holds for Iterator's hasNext and next methods. If the hasNext method returns true the consequent call of the next method can return null if the garbage collector is activated between this two calls and all elements in the iterator behind the current one were unreferenced.
  • Lifecycle of transient element can not be controlled by the association from the nontransient element.
    The transient element is deleted when it is not hard referenced from client application or is not amember of association with both transient ends. The existence of association where one end is transient and other non transient does not protect the transient element from being deleted by the garbage collector.

Usage

The MDR engine treats the object as transient if its class has the org.netbeans.mdr.transient tag set to the value true. Such a class is represented by the TransientStorableClass rather than StorableClass. The TransientStorableClass creates TransientStorableObject for instance representation. The association is treated as transient automatically if at least one end of the association is transient (represented by transient class).
Companion
Projects:
MySQL Database Server   Open JDK: an Open SourceJDK   GlassFish Community: an Open Source Application Server    Mobile & Embedded Community    Open Solaris   java.net - The Source for Java Technology Collaboration   Open ESB - The Open Enterprise Service Bus Powered by