goodsjpi
Class BasicMetaobject

java.lang.Object
  extended bygoodsjpi.Metaobject
      extended bygoodsjpi.BasicMetaobject
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
OptimisticMetaobject, PessimisticMetaobject

public abstract class BasicMetaobject
extends Metaobject

BasicMetaobject implements all the transaction logic.
Specifically pre/postDaemon are implemented to call begin/end read/write Access and call commit + abort Transaction.
Locking is not implemented here, but in the subclasses. The functions begin/end read/write Access serve as hooks to do so.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class goodsjpi.Metaobject
CONSTRUCTOR, EXCEPTION, MUTATOR, VARIABLE
 
Constructor Summary
BasicMetaobject()
           
 
Method Summary
static void abortNestedTransaction()
          abortNestedTransaction decreases the cache managers nestedTransaction counter, and if that hits 0 calls abortTransaction
protected static void abortTransaction()
          abortTransaction aborts for the static CacheManager.getCacheManger (per thread) and the database that the objects in that are in. calls
protected static void abortTransaction(CacheManager mng, Database db)
          abortTransaction obviously aborts the Transaction in progress.
static void beginNestedTransaction()
          By incrementing nested transaction count we delay implicit transaction commit until the moment when counter is explicitly decremented by endNestedTransactionMethod()
protected  void commitObjectChanges(Persistent obj)
          commitObjectChanges is called during commitTransaction.
protected static void commitTransaction()
          At this moment there are no more active methods for classes controlled by this metaobject (or metaobjects derived from it).
protected  void destroyObject(Persistent obj)
          Destoroy all object references to make it possible to provide more unaccessible objects to GC
The objects state is set to DESTRUCTED | RAW
static void endNestedTransaction()
          endNestedTransaction decreases the cache managers nestedTransaction counter, and if that hits 0 calls commitTransaction
protected  void forgetObject(Persistent obj)
          forgetObject is called when the objects finalize() is called, if it's opid is still valid.
protected  void invalidateObject(Persistent obj)
          This method is asynchronously called by server storag agent when deterioration notification from server is received.
protected  void loadObject(Persistent obj)
          loadObject is not so much the loading of the Object, ,but a notification thereof.
protected  void makePersistent(Persistent obj, Persistent parent)
          Assign persistent identifier to the transient object of persistent capable class.
protected  void notifyOnModification(Persistent obj, boolean enabled)
          Enable or disable notification on receving invalidation messages from the server for this object.
 void postDaemon(java.lang.Object o, int attr, boolean modified)
          Invocation of postDaemon is inserted by MOP geneator after each method invocation or object component access.
 void preDaemon(java.lang.Object o, int attr)
          Invocation of preDaemon is inserted by MOP geneator before each method invocation or object component access.
protected  void preloadObject(Persistent obj, int size)
          preloadObject is called by Storage.read() when it's bytes have been received and just before they are copied into it's data member
The function adjusts the cache Managers cacheSize appropriately
protected  void releaseObject(Persistent obj)
          releaseObject is called during a commitTransaction, for objects that have not been modified.
protected static void sendForgottenObjectsToServers(CacheManager mng)
          Object thrown by GC from weak cache are linked into forgottenObjectList list and notifications are send to servers at the transaction commit time.
protected  void undoObjectChanges(Persistent obj)
          undoObjectChanges is called during an abortTransaction.
 
Methods inherited from class goodsjpi.Metaobject
beginReadAccess, beginWriteAccess, endAccess, modify, mutator
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BasicMetaobject

public BasicMetaobject()
Method Detail

preDaemon

public void preDaemon(java.lang.Object o,
                      int attr)
Invocation of preDaemon is inserted by MOP geneator before each method invocation or object component access. See MetaObject
This "basic" implementation increases the accesscount of the object and if the flag indicates change, calls begin read/write Access.
Also it load, or prepares the object by calling these functions on the objects store

Specified by:
preDaemon in class Metaobject
Parameters:
o - an Object value that is modified
attr - an int flag, saying what kind of modufucation

postDaemon

public void postDaemon(java.lang.Object o,
                       int attr,
                       boolean modified)
Invocation of postDaemon is inserted by MOP geneator after each method invocation or object component access. See also MetaObject
This "basic" implementation decreases the accesscount of the object and if that hits 0 calls endAccess(obj). In that case, the object is removed from the cache manager and detroyObject is called. If that was the end of nested Trasaction, either commitTransaction, or abortTransaction, depending on if the flag indicates Exception is called.

Specified by:
postDaemon in class Metaobject
Parameters:
o - an Object, or really a Persistent, that has been changed
attr - an int, indicating where/how the change happened. An OR combination of the static flags below
modified - a boolean value, indicating whether there has actually been a change. Because of exceptions it isn't always true.

makePersistent

protected void makePersistent(Persistent obj,
                              Persistent parent)
Assign persistent identifier to the transient object of persistent capable class. The object is placed in the same storage as persistent object containing reference to this object unless explicit storage attachment was specified for this object.

Specified by:
makePersistent in class Metaobject
Parameters:
obj - a Persistent value that is made persistent
parent - a Persistent into whose storage obj is placed, if obj is new

sendForgottenObjectsToServers

protected static void sendForgottenObjectsToServers(CacheManager mng)
Object thrown by GC from weak cache are linked into forgottenObjectList list and notifications are send to servers at the transaction commit time. This is done because clearing weak reference by GC is not synchronized with invocation of finalize() method. So there is no warrenty that in the moment between object is removed from weak cache and ionvocation of finilize method, the object with the same identifier will not be retirieved from the server. Delayed strategy of sending forget message together with checking object for presence in the cache before sending foget message to the server makes sending of wrong forgot message not possible.
OId's of Object that were "forgotten" are collected and handed to Storage.forgetObjects

Parameters:
mng - a CacheManager value

commitTransaction

protected static void commitTransaction()
At this moment there are no more active methods for classes controlled by this metaobject (or metaobjects derived from it). This method will try to commit all transactions in all opened databases. Until this method is completed no other invocation or access to objects controled by this MOP is possible (it is forced by declaring this static method "synchronized" as well as static method fixObject(), which is called before any access to the object).
First sendForgottenObject is called. Then, for all modifed objects (all others are release by metaobject.releaseObject()) we find it's database and collect all object involved in the trasaction. If any is invalidated, the transaction is aborted.
Each objects storage store(obj) function is called, which packs the byte into the tranaction buffer. Then the storage's commitTransaction is called, and if the trasaction spans several storages, those storages commitSubtransaction are called. This send the bytes to the server, and if anything goes wrong, abortTransaction is called.
If all went well, obj.metaObject.commitchanegs is called for every object


abortTransaction

protected static void abortTransaction(CacheManager mng,
                                       Database db)
abortTransaction obviously aborts the Transaction in progress. This is done by calling undoObjectChanges on each Objects metaobject, and calling abortTransaction on the DB.

Parameters:
mng - a CacheManager that provides the list of objects that participate in the Transaction. (mng.transObjects)
db - a Database, in which all participating Objects must be

abortTransaction

protected static void abortTransaction()
abortTransaction aborts for the static CacheManager.getCacheManger (per thread) and the database that the objects in that are in. calls


commitObjectChanges

protected void commitObjectChanges(Persistent obj)
commitObjectChanges is called during commitTransaction. The object is removed from the transaction list of the cache manager. If the obj is invalidated, it's destroyed (this.destroyObject()).

Specified by:
commitObjectChanges in class Metaobject
Parameters:
obj - a Persistent object to commit

undoObjectChanges

protected void undoObjectChanges(Persistent obj)
undoObjectChanges is called during an abortTransaction.
The object is removed from the cache managers Trasaction list and if locked, unlocked. If the object has been modified (dirty), new objects are destroyed and old removed from their storage (storage.forgetObject())

Specified by:
undoObjectChanges in class Metaobject
Parameters:
obj - a Persistent value

preloadObject

protected void preloadObject(Persistent obj,
                             int size)
preloadObject is called by Storage.read() when it's bytes have been received and just before they are copied into it's data member
The function adjusts the cache Managers cacheSize appropriately

Specified by:
preloadObject in class Metaobject
Parameters:
obj - a Persistent that has been read (from the net)
size - an int, how many bytes the data member will hold

loadObject

protected void loadObject(Persistent obj)
loadObject is not so much the loading of the Object, ,but a notification thereof. The object is really loaded by the Storage class (in prepare(obj) method) and after the deed is done, this method is called.
This only increases the cache size appropriately

Specified by:
loadObject in class Metaobject
Parameters:
obj - a Persistent object that has been loaded

forgetObject

protected void forgetObject(Persistent obj)
forgetObject is called when the objects finalize() is called, if it's opid is still valid. If all data were local, this would mean the object could be desroyed because it's not reachable anymore. But because more references may exist at the servers end, this basically reduces the reference count at the servers side.
Server side garbage collection will eventually reclaim the object space, if it really has become unreachable.
The function adjusts the cache manager's cache size and links the object into the forgottenObjectList of the cache manager

Specified by:
forgetObject in class Metaobject
Parameters:
obj - a Persistent that has become localy unreachable

releaseObject

protected void releaseObject(Persistent obj)
releaseObject is called during a commitTransaction, for objects that have not been modified. The Object is removed from the Transaction list and unlocked (if it was). If NOTIFY is set on the object we keep it in cache.
DIRTY,NEW,TANS*,*LOCK flags are cleared.

Specified by:
releaseObject in class Metaobject
Parameters:
obj - a Persistent to be released.

destroyObject

protected void destroyObject(Persistent obj)
Destoroy all object references to make it possible to provide more unaccessible objects to GC
The objects state is set to DESTRUCTED | RAW

Specified by:
destroyObject in class Metaobject
Parameters:
obj - a Persistent value

invalidateObject

protected void invalidateObject(Persistent obj)
This method is asynchronously called by server storag agent when deterioration notification from server is received.
If the object does not participate in a current Transaction, it is removed from the cache and detroyed. Otherwise the invalidated flag is set and detruction happends after commit.
If NOTIFY is set on the object, the associated CondEvent's signal is called

Specified by:
invalidateObject in class Metaobject
Parameters:
obj - a Persistent object to be invalidated.

notifyOnModification

protected void notifyOnModification(Persistent obj,
                                    boolean enabled)
Enable or disable notification on receving invalidation messages from the server for this object. If enable, set NOTIFY flag on the object and remove from cache (?). Else unset the flag and insert into cache, if not accessed.

Specified by:
notifyOnModification in class Metaobject
Parameters:
obj - a Persistent to make the notification changes for
enabled - a boolean, whether notifications are used for this object

beginNestedTransaction

public static void beginNestedTransaction()
By incrementing nested transaction count we delay implicit transaction commit until the moment when counter is explicitly decremented by endNestedTransactionMethod()


endNestedTransaction

public static void endNestedTransaction()
endNestedTransaction decreases the cache managers nestedTransaction counter, and if that hits 0 calls commitTransaction


abortNestedTransaction

public static void abortNestedTransaction()
abortNestedTransaction decreases the cache managers nestedTransaction counter, and if that hits 0 calls abortTransaction