[exo-jcr-commits] exo-jcr SVN: r490 - in jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl: storage/jbosscache and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Fri Nov 6 11:02:43 EST 2009


Author: nzamosenchuk
Date: 2009-11-06 11:02:42 -0500 (Fri, 06 Nov 2009)
New Revision: 490

Added:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
Modified:
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ListenerCriteria.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerImpl.java
   jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java
Log:
EXOJCR-204:Observation manager refactored

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java	2009-11-06 15:54:46 UTC (rev 489)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ActionLauncher.java	2009-11-06 16:02:42 UTC (rev 490)
@@ -18,6 +18,7 @@
  */
 package org.exoplatform.services.jcr.impl.core.observation;
 
+import org.exoplatform.services.jcr.core.NamespaceAccessor;
 import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
 import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
 import org.exoplatform.services.jcr.dataflow.ChangesLogIterator;
@@ -64,12 +65,16 @@
 
    private final SessionRegistry sessionRegistry;
 
+   private final NodeTypeDataManager ntManager;
+   
+
    public ActionLauncher(ObservationManagerRegistry registry, WorkspacePersistentDataManager workspaceDataManager,
-      SessionRegistry sessionRegistry)
+      NodeTypeDataManager ntManager, SessionRegistry sessionRegistry)
    {
       this.observationRegistry = registry;
       this.workspaceDataManager = workspaceDataManager;
       this.sessionRegistry = sessionRegistry;
+      this.ntManager = ntManager;
       this.workspaceDataManager.addItemPersistenceListener(this);
    }
 
@@ -104,9 +109,8 @@
                      try
                      {
                         int eventType = eventType(itemState);
-                        if (eventType != SKIP_EVENT && isTypeMatch(criteria, eventType)
-                           && isPathMatch(criteria, item, userSession) && isIdentifierMatch(criteria, item)
-                           && isNodeTypeMatch(criteria, item, userSession, subLog)
+                        if (eventType != SKIP_EVENT && isTypeMatch(criteria, eventType) && isPathMatch(criteria, item)
+                           && isIdentifierMatch(criteria, item) && isNodeTypeMatch(criteria, item, subLog)
                            && isSessionMatch(criteria, sessionId))
                         {
 
@@ -146,25 +150,15 @@
       return true;
    }
 
-   private boolean isPathMatch(ListenerCriteria criteria, ItemData item, SessionImpl userSession)
+   private boolean isPathMatch(ListenerCriteria criteria, ItemData item)
    {
       if (criteria.getAbsPath() == null)
          return true;
-      try
-      {
-         QPath cLoc = userSession.getLocationFactory().parseAbsPath(criteria.getAbsPath()).getInternalPath();
+      // 8.3.3 Only events whose associated parent node is at absPath (or
+      // within its subtree, if isDeep is true) will be received.
+      QPath itemPath = item.getQPath();
 
-         // 8.3.3 Only events whose associated parent node is at absPath (or
-         // within its subtree, if isDeep is true) will be received.
-
-         QPath itemPath = item.getQPath();
-
-         return itemPath.isDescendantOf(cLoc, !criteria.isDeep());
-      }
-      catch (RepositoryException e)
-      {
-         return false;
-      }
+      return itemPath.isDescendantOf(criteria.getAbsPath(), !criteria.isDeep());
    }
 
    private boolean isIdentifierMatch(ListenerCriteria criteria, ItemData item)
@@ -185,8 +179,8 @@
 
    }
 
-   private boolean isNodeTypeMatch(ListenerCriteria criteria, ItemData item, SessionImpl userSession,
-      PlainChangesLog changesLog) throws RepositoryException
+   private boolean isNodeTypeMatch(ListenerCriteria criteria, ItemData item, PlainChangesLog changesLog)
+      throws RepositoryException
    {
       if (criteria.getNodeTypeName() == null)
          return true;
@@ -214,12 +208,9 @@
          }
       }
 
-      NodeTypeDataManager ntManager = userSession.getWorkspace().getNodeTypesHolder();
-      LocationFactory locationFactory = userSession.getLocationFactory();
       for (int i = 0; i < criteria.getNodeTypeName().length; i++)
       {
-         InternalQName name = locationFactory.parseJCRName(criteria.getNodeTypeName()[i]).getInternalName();
-         NodeTypeData criteriaNT = ntManager.getNodeType(name);
+         NodeTypeData criteriaNT = ntManager.getNodeType(criteria.getNodeTypeName()[i]);
          InternalQName[] testQNames;
          if (criteriaNT.isMixin())
          {

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ListenerCriteria.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ListenerCriteria.java	2009-11-06 15:54:46 UTC (rev 489)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ListenerCriteria.java	2009-11-06 16:02:42 UTC (rev 490)
@@ -18,7 +18,8 @@
  */
 package org.exoplatform.services.jcr.impl.core.observation;
 
-import javax.jcr.RepositoryException;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.QPath;
 
 /**
  * Created by The eXo Platform SAS.
@@ -32,20 +33,20 @@
 
    private int eventTypes;
 
-   private String absPath;
+   private QPath absPath;
 
    private boolean deep;
 
    private String[] identifier;
 
-   private String[] nodeTypeName;
+   private InternalQName[] nodeTypeName;
 
    private boolean noLocal;
 
    private String sessionId;
 
-   public ListenerCriteria(int eventTypes, String absPath, boolean isDeep, String[] identifier, String[] nodeTypeName,
-      boolean noLocal, String sessionId) throws RepositoryException
+   public ListenerCriteria(int eventTypes, QPath absPath, boolean isDeep, String[] identifier, InternalQName[] nodeTypeName,
+      boolean noLocal, String sessionId)
    {
       this.eventTypes = eventTypes;
       this.absPath = absPath;
@@ -61,7 +62,7 @@
       return this.eventTypes;
    }
 
-   public String getAbsPath()
+   public QPath getAbsPath()
    {
       return this.absPath;
    }
@@ -76,7 +77,7 @@
       return this.identifier;
    }
 
-   public String[] getNodeTypeName()
+   public InternalQName[] getNodeTypeName()
    {
       return this.nodeTypeName;
    }

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerImpl.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerImpl.java	2009-11-06 15:54:46 UTC (rev 489)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerImpl.java	2009-11-06 16:02:42 UTC (rev 490)
@@ -20,6 +20,10 @@
 
 import org.exoplatform.services.jcr.core.ExtendedSession;
 import org.exoplatform.services.jcr.core.SessionLifecycleListener;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.core.LocationFactory;
+import org.exoplatform.services.jcr.impl.core.SessionRegistry;
 import org.exoplatform.services.jcr.impl.util.EntityCollection;
 
 import java.util.ArrayList;
@@ -46,15 +50,19 @@
 
    private ObservationManagerRegistry registry;
 
+   private SessionRegistry sessionRegistry;
+
    /**
     * Protected constructor for subclasses
     * 
     * @param session
     */
-   ObservationManagerImpl(ObservationManagerRegistry registry, String sessionId)
+   ObservationManagerImpl(ObservationManagerRegistry registry, String sessionId, SessionRegistry sessionRegistry)
    {
       this.sessionId = sessionId;
       this.registry = registry;
+
+      this.sessionRegistry = sessionRegistry;
    }
 
    /**
@@ -64,7 +72,23 @@
       String[] nodeTypeName, boolean noLocal) throws RepositoryException
    {
 
-      registry.addEventListener(listener, new ListenerCriteria(eventTypes, absPath, isDeep, uuid, nodeTypeName,
+      // Convert all strings to internal view
+      QPath absQPath =
+         sessionRegistry.getSession(sessionId).getLocationFactory().parseAbsPath(absPath).getInternalPath();
+
+      InternalQName[] nodeTypeNames = null;
+
+      if (nodeTypeName != null && nodeTypeName.length > 0)
+      {
+         nodeTypeNames = new InternalQName[nodeTypeName.length];
+         LocationFactory locationFactory = sessionRegistry.getSession(sessionId).getLocationFactory();
+         for (int i = 0; i < nodeTypeNames.length; i++)
+         {
+            nodeTypeNames[i] = locationFactory.parseJCRName(nodeTypeName[i]).getInternalName();
+         }
+      }
+
+      registry.addEventListener(listener, new ListenerCriteria(eventTypes, absQPath, isDeep, uuid, nodeTypeNames,
          noLocal, sessionId));
 
       sessionListeners.add(listener);

Modified: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java	2009-11-06 15:54:46 UTC (rev 489)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/core/observation/ObservationManagerRegistry.java	2009-11-06 16:02:42 UTC (rev 490)
@@ -18,6 +18,8 @@
  */
 package org.exoplatform.services.jcr.impl.core.observation;
 
+import org.exoplatform.services.jcr.core.NamespaceAccessor;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeDataManager;
 import org.exoplatform.services.jcr.impl.core.SessionImpl;
 import org.exoplatform.services.jcr.impl.core.SessionRegistry;
 import org.exoplatform.services.jcr.impl.dataflow.persistent.WorkspacePersistentDataManager;
@@ -49,17 +51,26 @@
 
    protected ActionLauncher launcher;
 
+
+   protected SessionRegistry sessionRegistry;
+
+   protected NamespaceAccessor namespaceAccessor;
+
+   protected NodeTypeDataManager nodeTypeDataManager;
+
    public ObservationManagerRegistry(WorkspacePersistentDataManager workspaceDataManager,
-      SessionRegistry sessionRegistry)
+      SessionRegistry sessionRegistry, NamespaceAccessor namespaceAccessor)
    {
-
+      this.sessionRegistry = sessionRegistry;
       this.listenersMap = new HashMap<EventListener, ListenerCriteria>();
-      this.launcher = new ActionLauncher(this, workspaceDataManager, sessionRegistry);
+      this.namespaceAccessor = namespaceAccessor;
+      //this.nodeTypeDataManager = nodeTypeDataManager;
+      this.launcher = new ActionLauncher(this, workspaceDataManager, nodeTypeDataManager, sessionRegistry);
    }
 
    public ObservationManagerImpl createObservationManager(SessionImpl session)
    {
-      return new ObservationManagerImpl(this, session.getId());
+      return new ObservationManagerImpl(this, session.getId(), sessionRegistry);
    }
 
    public void addEventListener(EventListener listener, ListenerCriteria filter)
@@ -100,5 +111,11 @@
          listenersMap.remove(listener);
       }
    }
+   
 
+   public ActionLauncher getLauncher()
+   {
+      return launcher;
+   }
+   
 }

Added: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
===================================================================
--- jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java	                        (rev 0)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java	2009-11-06 16:02:42 UTC (rev 490)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (C) 2009 eXo Platform SAS.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.exoplatform.services.jcr.impl.storage.jbosscache;
+
+import org.exoplatform.services.jcr.impl.core.observation.ObservationManagerRegistry;
+import org.jboss.cache.Modification;
+
+import java.util.List;
+
+/**
+ * @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
+ * @version $Id: ObservationCacheLoader.java 34360 2009-07-22 23:58:59Z aheritier $
+ *
+ */
+public class ObservationCacheLoader extends AbstractWriteOnlyCacheLoader
+{
+   private final ObservationManagerRegistry observationManagerRegistry;
+
+   /**
+    * 
+    */
+   public ObservationCacheLoader(ObservationManagerRegistry observationManagerRegistry)
+   {
+      this.observationManagerRegistry = observationManagerRegistry;
+   }
+
+   /**
+    * @see org.exoplatform.services.jcr.impl.storage.jbosscache.AbstractWriteOnlyCacheLoader#put(java.util.List)
+    */
+   @Override
+   public void put(List<Modification> modifications) throws Exception
+   {
+      // TODO Auto-generated method stub
+
+   }
+
+}


Property changes on: jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
___________________________________________________________________
Name: svn:mime-type
   + text/plain



More information about the exo-jcr-commits mailing list