FileDocCategorySizeDatePackage
DistributedVersionManager.javaAPI DocJBoss 4.2.110963Fri Jul 13 21:02:32 BST 2007org.jboss.aspects.versioned

DistributedVersionManager

public class DistributedVersionManager extends VersionManager
author
Bill Burke
version
$Revision: 57186 $

Fields Summary
protected static Logger
log
protected SynchronizationManager
synchManager
protected long
timeout
Constructors Summary
public DistributedVersionManager(long timeout, SynchronizationManager synchManager)


       
   
      this.synchManager = synchManager;
      this.timeout = timeout;
   
Methods Summary
public org.jboss.aop.proxy.ClassProxyaddListVersioning(java.util.List list, DistributedListState manager)
This is used by DistributedState.buildObject when the DistributedState object is serialized across the wire and must recreate the object it represents

      ClassProxy proxy = ClassProxyFactory.newInstance(list.getClass());
      GUID guid = manager.getGUID();
      org.jboss.aop.metadata.SimpleMetaData metaData = proxy._getInstanceAdvisor().getMetaData();
      metaData.addMetaData(VERSION_MANAGER, VERSION_ID, guid);
      StateManager.setStateManager(proxy, manager);
      CollectionStateChangeInterceptor interceptor = new CollectionStateChangeInterceptor(manager);
      proxy._getInstanceAdvisor().appendInterceptor(interceptor);
      return proxy;
   
public org.jboss.aop.proxy.ClassProxyaddMapVersioning(java.util.Map map, DistributedMapState manager)
This is used by DistributedState.buildObject when the DistributedState object is serialized across the wire and must recreate the object it represents

      ClassProxy proxy = ClassProxyFactory.newInstance(map.getClass());
      GUID guid = manager.getGUID();
      org.jboss.aop.metadata.SimpleMetaData metaData = proxy._getInstanceAdvisor().getMetaData();
      metaData.addMetaData(VERSION_MANAGER, VERSION_ID, guid);
      StateManager.setStateManager(proxy, manager);
      CollectionStateChangeInterceptor interceptor = new CollectionStateChangeInterceptor(manager);
      proxy._getInstanceAdvisor().appendInterceptor(interceptor);
      return proxy;
   
public org.jboss.aop.proxy.ClassProxyaddSetVersioning(java.util.Set set, DistributedSetState manager)
This is used by DistributedState.buildObject when the DistributedState object is serialized across the wire and must recreate the object it represents

      ClassProxy proxy = ClassProxyFactory.newInstance(set.getClass());
      GUID guid = manager.getGUID();
      org.jboss.aop.metadata.SimpleMetaData metaData = proxy._getInstanceAdvisor().getMetaData();
      metaData.addMetaData(VERSION_MANAGER, VERSION_ID, guid);
      StateManager.setStateManager(proxy, manager);
      CollectionStateChangeInterceptor interceptor = new CollectionStateChangeInterceptor(manager);
      proxy._getInstanceAdvisor().appendInterceptor(interceptor);
      return proxy;
   
public voidaddVersioning(DistributedPOJOState manager, org.jboss.aop.Advised advised)
This is used by DistributedState.buildObject when the DistributedState object is serialized across the wire and must recreate the object it represents

      StateManager.setStateManager(advised, manager);
      StateChangeInterceptor interceptor = new StateChangeInterceptor(manager);
      org.jboss.aop.metadata.SimpleMetaData metaData = advised._getInstanceAdvisor().getMetaData();
      metaData.addMetaData(VERSION_MANAGER, VERSION_ID, manager.getGUID());
      advised._getInstanceAdvisor().appendInterceptor(interceptor);
   
public booleanisVersioned(java.lang.Object obj)

      if (!(obj instanceof InstanceAdvised)) return false;
      InstanceAdvised advised = (InstanceAdvised)obj;
      return getGUID(advised) != null;
   
public java.lang.ObjectmakeVersioned(java.lang.Object obj)

      ArrayList newObjects = new ArrayList();
      obj = makeVersioned(obj, newObjects);
      synchManager.createObjects(newObjects);
      return obj;
   
java.lang.ObjectmakeVersioned(java.lang.Object obj, java.util.ArrayList newObjects)

      // Proxies cannot be versioned
      if (obj instanceof ClassProxy) return obj;

      if (!(obj instanceof Advised))
      {
         if (obj instanceof List)
         {
            List list = (List)obj;
            return makeVersionedList(list, newObjects);
         }
         else if (obj instanceof Map)
         {
            Map map = (Map)obj;
            return makeVersionedMap(map, newObjects);
         }
         else if (obj instanceof Set)
         {
            Set set = (Set)obj;
            return makeVersionedSet(set, newObjects);
         }
         else
         {
            return obj;
         }
      }
      Advised advised = (Advised)obj;
      org.jboss.aop.metadata.SimpleMetaData metaData = advised._getInstanceAdvisor().getMetaData();
      GUID guid;
      synchronized (metaData)
      {
         if (isVersioned(advised)) return obj;
         guid = tag(advised);
      }
      System.out.println("VersionManager: " + guid);
      DistributedPOJOState manager = new DistributedPOJOState(guid, timeout, advised, this, synchManager);
      StateManager.setStateManager(advised, manager);
      StateChangeInterceptor interceptor = new StateChangeInterceptor(manager);
      manager.acquireWriteLock();
      advised._getInstanceAdvisor().appendInterceptor(interceptor);
      try
      {
         Field[] advisedFields = ((ClassAdvisor)advised._getAdvisor()).getAdvisedFields();
         for (int i = 0; i < advisedFields.length; i++)
         {
            Field field = advisedFields[i];
            if (Modifier.isStatic(field.getModifiers())) continue;
            Object fieldVal = field.get(advised);
            if (fieldVal != null)
            {
               if (fieldVal instanceof Advised)
               {
                  Advised fieldAdvised = (Advised)fieldVal;
                  makeVersioned(fieldAdvised, newObjects);
                  fieldVal = new VersionReference(getGUID(fieldAdvised), fieldAdvised);
               }
               else if (fieldVal instanceof List)
               {
                  List list = (List)fieldVal;
                  InstanceAdvised instanceAdvised = (InstanceAdvised)makeVersionedList(list, newObjects);
                  fieldVal = new VersionReference(getGUID(instanceAdvised), instanceAdvised);
               }
               else if (fieldVal instanceof Map)
               {
                  Map map = (Map)fieldVal;
                  InstanceAdvised instanceAdvised = (InstanceAdvised)makeVersionedMap(map, newObjects);
                  fieldVal = new VersionReference(getGUID(instanceAdvised), instanceAdvised);
               }
               else if (fieldVal instanceof Set)
               {
                  Set set = (Set)fieldVal;
                  InstanceAdvised instanceAdvised = (InstanceAdvised)makeVersionedSet(set, newObjects);
                  fieldVal = new VersionReference(getGUID(instanceAdvised), instanceAdvised);
               }
            }
            manager.fieldMap.put(new Integer(i), new DistributedFieldUpdate(fieldVal, 0, i));
         }
         newObjects.add(manager);
         return advised;
      }
      finally
      {
         manager.releaseWriteLock();
      }
   
public java.util.ListmakeVersionedList(java.util.List list, java.util.ArrayList newObjects)

      ClassProxy proxy = ClassProxyFactory.newInstance(list.getClass());
      GUID guid = tag(proxy);
      DistributedListState manager = new DistributedListState(guid, timeout, proxy, list, this, synchManager);
      StateManager.setStateManager(proxy, manager);
      CollectionStateChangeInterceptor interceptor = new CollectionStateChangeInterceptor(manager);
      proxy._getInstanceAdvisor().appendInterceptor(interceptor);
      newObjects.add(manager);
      return (List)proxy;
   
public java.util.MapmakeVersionedMap(java.util.Map map, java.util.ArrayList newObjects)

      ClassProxy proxy = ClassProxyFactory.newInstance(map.getClass());
      GUID guid = tag(proxy);
      DistributedMapState manager = new DistributedMapState(guid, timeout, proxy, map, this, synchManager);
      StateManager.setStateManager(proxy, manager);
      CollectionStateChangeInterceptor interceptor = new CollectionStateChangeInterceptor(manager);
      proxy._getInstanceAdvisor().appendInterceptor(interceptor);
      newObjects.add(manager);
      return (Map)proxy;
   
public java.util.SetmakeVersionedSet(java.util.Set set, java.util.ArrayList newObjects)

      ClassProxy proxy = ClassProxyFactory.newInstance(set.getClass());
      GUID guid = tag(proxy);
      DistributedSetState manager = new DistributedSetState(guid, timeout, proxy, set, this, synchManager);
      StateManager.setStateManager(proxy, manager);
      CollectionStateChangeInterceptor interceptor = new CollectionStateChangeInterceptor(manager);
      proxy._getInstanceAdvisor().appendInterceptor(interceptor);
      newObjects.add(manager);
      return (Set)proxy;
   
public org.jboss.util.id.GUIDtag(org.jboss.aop.InstanceAdvised advised)

      GUID guid = new GUID();
      org.jboss.aop.metadata.SimpleMetaData metaData = advised._getInstanceAdvisor().getMetaData();
      metaData.addMetaData(VERSION_MANAGER, VERSION_ID, guid);
      return guid;
   
public voiduntag(org.jboss.aop.InstanceAdvised advised)

      org.jboss.aop.metadata.SimpleMetaData metaData = advised._getInstanceAdvisor().getMetaData();
      metaData.removeMetaData(VERSION_MANAGER, VERSION_ID);