[exo-jcr-commits] exo-jcr SVN: r501 - jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache.
do-not-reply at jboss.org
do-not-reply at jboss.org
Mon Nov 9 04:44:25 EST 2009
Author: nzamosenchuk
Date: 2009-11-09 04:44:25 -0500 (Mon, 09 Nov 2009)
New Revision: 501
Modified:
jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java
Log:
EXOJCR-204:Observation manager updated/logic excluded.
Modified: 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 2009-11-09 09:19:00 UTC (rev 500)
+++ jcr/branches/1.12.0-JBC/component/core/src/main/java/org/exoplatform/services/jcr/impl/storage/jbosscache/ObservationCacheLoader.java 2009-11-09 09:44:25 UTC (rev 501)
@@ -18,11 +18,27 @@
*/
package org.exoplatform.services.jcr.impl.storage.jbosscache;
+import org.exoplatform.services.jcr.core.nodetype.NodeTypeData;
+import org.exoplatform.services.jcr.datamodel.InternalQName;
+import org.exoplatform.services.jcr.datamodel.ItemData;
+import org.exoplatform.services.jcr.datamodel.NodeData;
+import org.exoplatform.services.jcr.datamodel.QPath;
+import org.exoplatform.services.jcr.impl.core.observation.EventImpl;
+import org.exoplatform.services.jcr.impl.core.observation.ListenerCriteria;
import org.exoplatform.services.jcr.impl.core.observation.ObservationManagerRegistry;
+import org.exoplatform.services.jcr.impl.util.EntityCollection;
+import org.exoplatform.services.log.ExoLogger;
+import org.exoplatform.services.log.Log;
+import org.jboss.cache.Fqn;
import org.jboss.cache.Modification;
import java.util.List;
+import javax.jcr.RepositoryException;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventListener;
+import javax.jcr.observation.EventListenerIterator;
+
/**
* @author <a href="mailto:nikolazius at gmail.com">Nikolay Zamosenchuk</a>
* @version $Id: ObservationCacheLoader.java 34360 2009-07-22 23:58:59Z aheritier $
@@ -30,14 +46,21 @@
*/
public class ObservationCacheLoader extends AbstractWriteOnlyCacheLoader
{
- private final ObservationManagerRegistry observationManagerRegistry;
+ public final int SKIP_EVENT = Integer.MIN_VALUE;
+ private Log log = ExoLogger.getLogger(this.getClass().getName());
+
+ private final Fqn nodeFqn = Fqn.fromString(JBossCacheStorage.NODES);
+
+ private final Fqn propFqn = Fqn.fromString(JBossCacheStorage.PROPS);
+
+ private ObservationManagerRegistry observationManagerRegistry=null;
+
/**
*
*/
- public ObservationCacheLoader(ObservationManagerRegistry observationManagerRegistry)
+ public ObservationCacheLoader()
{
- this.observationManagerRegistry = observationManagerRegistry;
}
/**
@@ -46,8 +69,145 @@
@Override
public void put(List<Modification> modifications) throws Exception
{
- // TODO Auto-generated method stub
}
+ private int eventType(Modification modification)
+ {
+ // TODO: REMOVE cache structure hardcode!
+ switch (modification.getType())
+ {
+ case PUT_DATA :
+ if (modification.getFqn().isDirectChildOf(nodeFqn))
+ {
+ // node added
+ return Event.NODE_ADDED;
+ }
+ else if (modification.getFqn().isDirectChildOf(propFqn))
+ {
+ // property added or changed
+ if (modification.getOldValue() != null)
+ {
+ // property changed
+ // TODO: possibly bad idea
+ return Event.PROPERTY_CHANGED;
+ }
+ else
+ {
+ // property added
+ return Event.PROPERTY_ADDED;
+ }
+ }
+ break;
+ case REMOVE_NODE :
+ if (modification.getFqn().isDirectChildOf(nodeFqn))
+ {
+ // node removed
+ return Event.NODE_REMOVED;
+ }
+ else if (modification.getFqn().isDirectChildOf(propFqn))
+ {
+ // property removed
+ return Event.PROPERTY_REMOVED;
+ }
+ break;
+ }
+ return SKIP_EVENT;
+ }
+
+ private boolean isTypeMatch(ListenerCriteria criteria, int eventType)
+ {
+ return (criteria.getEventTypes() & eventType) > 0;
+ }
+
+ private boolean isSessionMatch(ListenerCriteria criteria, String sessionId)
+ {
+ if (criteria.getNoLocal() && criteria.getSessionId().equals(sessionId))
+ return false;
+ return true;
+ }
+
+ private boolean isIdentifierMatch(ListenerCriteria criteria, ItemData item)
+ {
+
+ if (criteria.getIdentifier() == null)
+ return true;
+ // for each uuid in list
+ for (int i = 0; i < criteria.getIdentifier().length; i++)
+ {
+ // if it is a direct child of nodeFqn or propertyFqn - get their parent
+ if (criteria.getIdentifier()[i].equals(item.getParentIdentifier()))
+ return true;
+ }
+ return false;
+
+ }
+
+ private boolean isPathMatch(ListenerCriteria criteria, ItemData item)
+ {
+ if (criteria.getAbsPath() == null)
+ return true;
+ // 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(criteria.getAbsPath(), !criteria.isDeep());
+ }
+
+ @Deprecated
+ private boolean isNodeTypeMatch(ListenerCriteria criteria, ItemData item, List<Modification> modifications)
+ throws RepositoryException
+ {
+ if (criteria.getNodeTypeName() == null)
+ return true;
+
+ // TODO: IT IS IMPOSSIBLE TO ACCESS CACHE ON CACHELOADER.PUT()!!!
+ NodeData node =
+ (NodeData)observationManagerRegistry.getWorkspaceDataManager().getItemData(item.getParentIdentifier());
+ if (node == null)
+ {
+ // check if parent exists in changes log
+ for (int i = modifications.size() - 1; i >= 0; i--)
+ {
+ ItemData data = getItemData(modifications.get(i));
+ if (data.getIdentifier().equals(item.getParentIdentifier()))
+ {
+ // parent found
+ node = (NodeData)data;
+ break;
+ }
+ }
+
+ if (node == null)
+ {
+ log.warn("Item's " + item.getQPath().getAsString() + " associated parent (" + item.getParentIdentifier()
+ + ") can't be found nor in workspace nor in current changes. Nodetype filter is rejected.");
+ return false;
+ }
+ }
+
+ for (int i = 0; i < criteria.getNodeTypeName().length; i++)
+ {
+ NodeTypeData criteriaNT =
+ observationManagerRegistry.getNodeTypeDataManager().getNodeType(criteria.getNodeTypeName()[i]);
+ InternalQName[] testQNames;
+ if (criteriaNT.isMixin())
+ {
+ testQNames = node.getMixinTypeNames();
+ }
+ else
+ {
+ testQNames = new InternalQName[1];
+ testQNames[0] = node.getPrimaryTypeName();
+ }
+ if (observationManagerRegistry.getNodeTypeDataManager().isNodeType(criteriaNT.getName(), testQNames))
+ return true;
+ }
+ return false;
+ }
+
+ protected ItemData getItemData(Modification m)
+ {
+ return (ItemData)m.getData().get(JBossCacheStorage.ITEM_DATA);
+ }
+
}
More information about the exo-jcr-commits
mailing list