jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r512985 - in /jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi: common/EventBundleImpl.java common/EventFilterImpl.java common/EventImpl.java server/ServerRepositoryService.java
Date Wed, 28 Feb 2007 21:33:24 GMT
Author: mreutegg
Date: Wed Feb 28 13:33:24 2007
New Revision: 512985

URL: http://svn.apache.org/viewvc?view=rev&rev=512985
Log:
- observation support in spi-rmi

Added:
    jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventBundleImpl.java
  (with props)
    jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventFilterImpl.java
  (with props)
    jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventImpl.java
  (with props)
Modified:
    jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/server/ServerRepositoryService.java

Added: jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventBundleImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventBundleImpl.java?view=auto&rev=512985
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventBundleImpl.java
(added)
+++ jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventBundleImpl.java
Wed Feb 28 13:33:24 2007
@@ -0,0 +1,78 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.rmi.common;
+
+import org.apache.jackrabbit.spi.EventBundle;
+import org.apache.jackrabbit.spi.EventIterator;
+
+import java.io.Serializable;
+import java.util.Collection;
+
+/**
+ * <code>EventBundleImpl</code> implements a serializable {@link EventBundle}.
+ */
+public class EventBundleImpl implements EventBundle, Serializable {
+
+    /**
+     * Indicates if this bundle was created due to a local change.
+     */
+    private final boolean isLocal;
+
+    /**
+     * The bundle id.
+     */
+    private final String bundleId;
+
+    /**
+     * The events in this bundle.
+     */
+    private final Collection events;
+
+    /**
+     * Creates a new event bundle with <code>events</code>.
+     *
+     * @param events   the events for this bundle.
+     * @param isLocal  if this events were created due to a local change.
+     * @param bundleId the bundle id.
+     */
+    public EventBundleImpl(Collection events, boolean isLocal, String bundleId) {
+        this.events = events;
+        this.isLocal = isLocal;
+        this.bundleId = bundleId;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public EventIterator getEvents() {
+        return new IteratorHelper(events);
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getBundleId() {
+        return bundleId;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isLocal() {
+        return isLocal;
+    }
+}

Propchange: jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventBundleImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventFilterImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventFilterImpl.java?view=auto&rev=512985
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventFilterImpl.java
(added)
+++ jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventFilterImpl.java
Wed Feb 28 13:33:24 2007
@@ -0,0 +1,205 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.rmi.common;
+
+import org.apache.jackrabbit.spi.EventFilter;
+import org.apache.jackrabbit.spi.Event;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.MalformedPathException;
+import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+
+import javax.jcr.PathNotFoundException;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
+import java.util.Collections;
+import java.io.Serializable;
+
+/**
+ * <code>EventFilterImpl</code> is the spi2dav implementation of an
+ * {@link EventFilter}.
+ * TODO: copied from spi2dav, move to spi-commons?
+ */
+public class EventFilterImpl implements EventFilter, Serializable {
+
+    /**
+     * The logger instance for this class.
+     */
+    private static final Logger log = LoggerFactory.getLogger(EventFilterImpl.class);
+
+    private final int eventTypes;
+
+    private final boolean isDeep;
+
+    private final Path absPath;
+
+    private final Set uuids;
+
+    private final Set nodeTypeNames;
+
+    private final boolean noLocal;
+
+    /**
+     * Creates a new <code>EventFilterImpl</code>.
+     *
+     * @param eventTypes    the event types this filter is interested in.
+     * @param absPath       filter events that are below this path.
+     * @param isDeep        whether this filter is applied deep.
+     * @param uuids         the jcr:uuid of the nodes this filter allows.
+     * @param nodeTypeNames the QNames of the already resolved node types this
+     *                      filter allows.
+     * @param noLocal       whether this filter accepts local events or not.
+     */
+    public EventFilterImpl(int eventTypes,
+                    Path absPath,
+                    boolean isDeep,
+                    String[] uuids,
+                    Set nodeTypeNames,
+                    boolean noLocal) {
+        this.eventTypes = eventTypes;
+        this.absPath = absPath;
+        this.isDeep = isDeep;
+        this.uuids = uuids != null ? new HashSet(Arrays.asList(uuids)) : null;
+        this.nodeTypeNames = nodeTypeNames != null ? new HashSet(nodeTypeNames) : null;
+        this.noLocal = noLocal;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public boolean accept(Event event, boolean isLocal) {
+        int type = event.getType();
+        // check type
+        if ((type & eventTypes) == 0) {
+            return false;
+        }
+
+        // check local flag
+        if (isLocal && noLocal) {
+            return false;
+        }
+
+        // check UUIDs
+        NodeId parentId = event.getParentId();
+        if (uuids != null) {
+            if (parentId.getPath() == null) {
+                if (!uuids.contains(parentId.getUniqueID())) {
+                    return false;
+                }
+            } else {
+                return false;
+            }
+        }
+
+        // check node types
+        if (nodeTypeNames != null) {
+            Set eventTypes = new HashSet();
+            eventTypes.addAll(Arrays.asList(event.getMixinTypeNames()));
+            eventTypes.add(event.getPrimaryNodeTypeName());
+            // create intersection
+            eventTypes.retainAll(nodeTypeNames);
+            if (eventTypes.isEmpty()) {
+                return false;
+            }
+        }
+
+        // finally check path
+        try {
+            // the relevant path for the path filter depends on the event type
+            // for node events, the relevant path is the one returned by
+            // Event.getPath().
+            // for property events, the relevant path is the path of the
+            // node where the property belongs to.
+            Path eventPath;
+            if (type == Event.NODE_ADDED || type == Event.NODE_REMOVED) {
+                eventPath = event.getQPath();
+            } else {
+                eventPath = event.getQPath().getAncestor(1);
+            }
+
+            boolean match = eventPath.equals(absPath);
+            if (!match && isDeep) {
+                match = eventPath.isDescendantOf(absPath);
+            }
+            return match;
+        } catch (MalformedPathException e) {
+            // should never get here
+            log.warn("malformed path: " + e);
+            log.debug("Exception: ", e);
+        } catch (PathNotFoundException e) {
+            // should never get here
+            log.warn("invalid property path: " + e);
+            log.debug("Exception: ", e);
+        }
+        // if we get here an exception occurred while checking for the path
+        return false;
+    }
+
+    /**
+     * @return the event types this event filter accepts.
+     */
+    public int getEventTypes() {
+        return eventTypes;
+    }
+
+    /**
+     * @return <code>true</code> if this event filter is deep.
+     */
+    public boolean isDeep() {
+        return isDeep;
+    }
+
+    /**
+     * @return the path to the item where events are filtered.
+     */
+    public Path getAbsPath() {
+        return absPath;
+    }
+
+    /**
+     * @return the uuids of the nodes of this filter or <code>null</code> if
+     *         this filter does not care about uuids.
+     */
+    public String[] getUUIDs() {
+        if (uuids == null) {
+            return null;
+        } else {
+            return (String[]) uuids.toArray(new String[uuids.size()]);
+        }
+    }
+
+    /**
+     * @return an unmodifiable set of node type names or <code>null</code> if
+     *         this filter does not care about node types.
+     */
+    public Set getNodeTypeNames() {
+        if (nodeTypeNames == null) {
+            return null;
+        } else {
+            return Collections.unmodifiableSet(nodeTypeNames);
+        }
+    }
+
+    /**
+     * @return if this filter accepts local events.
+     */
+    public boolean getNoLocal() {
+        return noLocal;
+    }
+}

Propchange: jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventFilterImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventImpl.java?view=auto&rev=512985
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventImpl.java
(added)
+++ jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventImpl.java
Wed Feb 28 13:33:24 2007
@@ -0,0 +1,134 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.spi.rmi.common;
+
+import org.apache.jackrabbit.spi.Event;
+import org.apache.jackrabbit.spi.ItemId;
+import org.apache.jackrabbit.spi.NodeId;
+import org.apache.jackrabbit.name.Path;
+import org.apache.jackrabbit.name.QName;
+
+import java.io.Serializable;
+
+/**
+ * <code>EventImpl</code> implements a serializable SPI
+ * {@link org.apache.jackrabbit.spi.Event}.
+ */
+public class EventImpl implements Event, Serializable {
+
+    /**
+     * The SPI event type.
+     * @see Event
+     */
+    private final int type;
+
+    /**
+     * The path of the affected item.
+     */
+    private final Path path;
+
+    /**
+     * The id of the affected item.
+     */
+    private final ItemId itemId;
+
+    /**
+     * The id of the affected item.
+     */
+    private final NodeId parentId;
+
+    /**
+     * The name of the primary node type of the 'associated' node of this event.
+     */
+    private final QName primaryNodeTypeName;
+
+    /**
+     * The names of the mixin types of the 'associated' node of this event.
+     */
+    private final QName[] mixinTypeNames;
+
+    /**
+     * The user ID connected with this event.
+     */
+    private final String userId;
+
+    /**
+     * Creates a new serializable event.
+     */
+    public EventImpl(int type, Path path, ItemId itemId, NodeId parentId,
+                     QName primaryNodeTypeName, QName[] mixinTypeNames,
+                     String userId) {
+        this.type = type;
+        this.path = path;
+        this.itemId = itemId;
+        this.parentId = parentId;
+        this.primaryNodeTypeName = primaryNodeTypeName;
+        this.mixinTypeNames = mixinTypeNames;
+        this.userId = userId;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public int getType() {
+        return type;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public Path getQPath() {
+        return path;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public ItemId getItemId() {
+        return itemId;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public NodeId getParentId() {
+        return parentId;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public QName getPrimaryNodeTypeName() {
+        return primaryNodeTypeName;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public QName[] getMixinTypeNames() {
+        QName[] mixins = new QName[mixinTypeNames.length];
+        System.arraycopy(mixinTypeNames, 0, mixins, 0, mixinTypeNames.length);
+        return mixins;
+    }
+
+    /**
+     * {@inheritDoc}
+     */
+    public String getUserID() {
+        return userId;
+    }
+}

Propchange: jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/common/EventImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/server/ServerRepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/server/ServerRepositoryService.java?view=diff&rev=512985&r1=512984&r2=512985
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/server/ServerRepositoryService.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi-rmi/src/main/java/org/apache/jackrabbit/spi/rmi/server/ServerRepositoryService.java
Wed Feb 28 13:33:24 2007
@@ -30,6 +30,9 @@
 import org.apache.jackrabbit.spi.rmi.common.QNodeTypeDefinitionImpl;
 import org.apache.jackrabbit.spi.rmi.common.ChildInfoImpl;
 import org.apache.jackrabbit.spi.rmi.common.IteratorHelper;
+import org.apache.jackrabbit.spi.rmi.common.EventImpl;
+import org.apache.jackrabbit.spi.rmi.common.EventBundleImpl;
+import org.apache.jackrabbit.spi.rmi.common.EventFilterImpl;
 import org.apache.jackrabbit.spi.ItemId;
 import org.apache.jackrabbit.spi.RepositoryService;
 import org.apache.jackrabbit.spi.SessionInfo;
@@ -47,6 +50,8 @@
 import org.apache.jackrabbit.spi.QueryInfo;
 import org.apache.jackrabbit.spi.QNodeTypeDefinitionIterator;
 import org.apache.jackrabbit.spi.ChildInfo;
+import org.apache.jackrabbit.spi.EventIterator;
+import org.apache.jackrabbit.spi.Event;
 import org.apache.jackrabbit.name.QName;
 import org.apache.jackrabbit.name.Path;
 
@@ -58,6 +63,9 @@
 import java.util.List;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Set;
+import java.util.HashSet;
+import java.util.Arrays;
 import java.rmi.RemoteException;
 import java.rmi.Remote;
 import java.rmi.server.RemoteObject;
@@ -690,8 +698,14 @@
                                          boolean noLocal)
             throws RepositoryException, RemoteException {
         try {
-            return service.createEventFilter(getSessionInfo(sessionInfo),
-                    eventTypes, absPath, isDeep, uuid, nodeTypeName, noLocal);
+            // some implementations may rely on createEventFilter being called
+            service.createEventFilter(getSessionInfo(sessionInfo), eventTypes,
+                    absPath, isDeep, uuid, nodeTypeName, noLocal);
+            Set ntNames = null;
+            if (nodeTypeName != null) {
+                ntNames = new HashSet(Arrays.asList(nodeTypeName));
+            }
+            return new EventFilterImpl(eventTypes, absPath, isDeep, uuid, ntNames, noLocal);
         } catch (RepositoryException e) {
             throw getRepositoryException(e);
         }
@@ -705,10 +719,32 @@
                                    EventFilter[] filters)
             throws RepositoryException, InterruptedException, RemoteException {
         try {
-            EventBundle[] bundles = service.getEvents(
-                    getSessionInfo(sessionInfo), timeout, filters);
-            // TODO
-            return new EventBundle[0];
+            SessionInfo sInfo = getSessionInfo(sessionInfo);
+            // create local event filter instances
+            filters = createLocalEventFilters(sInfo, filters);
+            EventBundle[] bundles = service.getEvents(sInfo, timeout, filters);
+            EventBundle[] serBundles = new EventBundle[bundles.length];
+            for (int i = 0; i < bundles.length; i++) {
+                List events = new ArrayList();
+                for (EventIterator it = bundles[i].getEvents(); it.hasNext(); ) {
+                    Event e = it.nextEvent();
+                    ItemId id;
+                    if (e.getItemId().denotesNode()) {
+                        id = createSerializableNodeId((NodeId) e.getItemId());
+                    } else {
+                        id = createSerializablePropertyId((PropertyId) e.getItemId());
+                    }
+                    Event serEvent = new EventImpl(e.getType(),
+                            e.getQPath(), id,
+                            createSerializableNodeId(e.getParentId()),
+                            e.getPrimaryNodeTypeName(),
+                            e.getMixinTypeNames(), e.getUserID());
+                    events.add(serEvent);
+                }
+                serBundles[i] = new EventBundleImpl(events,
+                        bundles[i].isLocal(), bundles[i].getBundleId());
+            }
+            return serBundles;
         } catch (RepositoryException e) {
             throw getRepositoryException(e);
         }
@@ -869,5 +905,41 @@
                     createSerializableNodeId(propId.getParentId()),
                     propId.getQName());
         }
+    }
+
+    /**
+     * Creates filter instances created by the underlying repository service.
+     *
+     * @param sInfo   the session info.
+     * @param filters the event filters created by this server repository
+     *                service.
+     * @return array of filter instances created by the underlying repository
+     *         service.
+     * @throws RepositoryException if an error occurs.
+     */
+    private EventFilter[] createLocalEventFilters(SessionInfo sInfo,
+                                                  EventFilter[] filters)
+            throws RepositoryException {
+        if (filters == null) {
+            return null;
+        }
+        for (int i = 0; i < filters.length; i++) {
+            if (filters[i] instanceof EventFilterImpl) {
+                EventFilterImpl e = (EventFilterImpl) filters[i];
+                Set nodeTypeNames = e.getNodeTypeNames();
+                QName[] ntNames = null;
+                if (nodeTypeNames != null) {
+                    ntNames = (QName[]) nodeTypeNames.toArray(
+                            new QName[nodeTypeNames.size()]);
+                }
+                filters[i] = service.createEventFilter(sInfo,
+                        e.getEventTypes(), e.getAbsPath(), e.isDeep(),
+                        e.getUUIDs(), ntNames, e.getNoLocal());
+            } else {
+                throw new RepositoryException("Unknown EventFilter implementation: " +
+                        filters[i].getClass().getName());
+            }
+        }
+        return filters;
     }
 }



Mime
View raw message