jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1577213 - in /jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation: JackrabbitEventFilter.java JackrabbitObservationManager.java
Date Thu, 13 Mar 2014 15:50:52 GMT
Author: mduerig
Date: Thu Mar 13 15:50:52 2014
New Revision: 1577213

URL: http://svn.apache.org/r1577213
Log:
JCR-3745: Add JackrabbitObservationManager with additional methods for registering event listeners
Initial version of new API

Added:
    jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation/JackrabbitEventFilter.java
    jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation/JackrabbitObservationManager.java

Added: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation/JackrabbitEventFilter.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation/JackrabbitEventFilter.java?rev=1577213&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation/JackrabbitEventFilter.java
(added)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation/JackrabbitEventFilter.java
Thu Mar 13 15:50:52 2014
@@ -0,0 +1,257 @@
+/*
+ * 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.api.observation;
+
+import static java.util.Arrays.copyOf;
+
+/**
+ * A storage object for event filter configuration.
+ * <p>
+ * The parameters of the filter can then be set by chaining the set methods,
+ * since each method returns the same <code>EventFilter</code> with the indicated
parameter set.
+ * <p>
+ * Once the filter is configured, it and an {@link javax.jcr.observation.EventListener} object
are
+ * passed to
+ * {@link org.apache.jackrabbit.api.observation.JackrabbitObservationManager#addEventListener(javax.jcr.observation.EventListener,
JackrabbitEventFilter)}.
+ * <p>
+ * The filter restricts which events are sent to the <code>EventListener</code>
according to the
+ * following parameters. Note that the term <i>associated parent node</i> of
an event means the
+ * parent node of the item at (or formerly at) the path returned by
+ * {@link javax.jcr.observation.Event#getPath}.
+ * <ul>
+ * <li>
+ * <code>eventTypes</code>:
+ * A bitwise <code>OR</code> of the event types to be listened to. See
+ * {@link javax.jcr.observation.Event} for details.
+ * </li>
+ * <li>
+ * <code>absPath</code>, <code>absPaths</code> <code>isDeep</code>:
+ * Only events whose associated parent node is at one of the paths in
+ * <code>absPath</code> or <code>absPaths</code> (or within its subgraph,
+ * if <code>isDeep</code> is <code>true</code>) will be received.
It is
+ * permissible to register a listener for a path where no node currently exists.
+ * </li>
+ * <li>
+ * <code>uuid</code>:
+ * Only events whose associated parent node has one of
+ * the identifiers in this list will be received. If his parameter is
+ * <code>null</code> then no identifier-related restriction is placed on
+ * events received. Note that specifying an empty array instead of
+ * <code>null</code> would result in no nodes being listened to. The term
+ * "UUID" is used for compatibility with JCR 1.0.
+ * </li>
+ * <li>
+ * <code>nodeTypeName</code>:
+ * Only events whose associated parent node has
+ * one of the node types (or a subtype of one of the node types) in this
+ * list will be received. If his parameter is <code>null</code> then no node
+ * type-related restriction is placed on events received. Note that
+ * specifying an empty array instead of <code>null</code> would result in no
+ * nodes types being listened to.
+ * </li>
+ * <li>
+ * <code>noLocal</code>: if <code>true</code>, then events
+ * generated by the session through which the listener was registered are
+ * ignored. Otherwise, they are not ignored.
+ * </li>
+ * <li>
+ * <code>noExternal</code>: if <code>true</code>, then events
+ * from external cluster nodes are ignored. Otherwise, they are not ignored.
+ * </li>
+ * </ul>
+ * The restrictions are "ANDed" together. In other words, for a particular node to be "listened
to" it
+ * must meet all the restrictions.
+ *
+ */
+public class JackrabbitEventFilter {  // TODO extends EventFilter once JCR 2.1 is out
+    private int eventTypes;
+    private String absPath;
+    private boolean isDeep;
+    private String[] identifiers;
+    private String[] nodeTypeNames;
+    private boolean noLocal;
+    private String[] absPaths = new String[]{};
+    private boolean noExternal;
+
+    /**
+     * Sets the <code>eventTypes</code> parameter of the filter.
+     * If left unset, this parameter defaults to <code>0</code>.
+     *
+     * @param eventTypes an <code>int</code>.
+     * @return This EventFilter object with the <code>eventTypes</code> parameter
set.
+     */
+    public JackrabbitEventFilter setEventTypes(int eventTypes) {
+        this.eventTypes = eventTypes;
+        return this;
+    }
+
+    /**
+     * Returns the <code>eventTypes</code> parameter of the filter.
+     *
+     * @return an <code>int</code>.
+     */
+    public int getEventTypes() {
+        return eventTypes;
+    }
+
+    /**
+     * Sets the <code>absPath</code> parameter of the filter.
+     * If left unset, this parameter defaults to <code>null</code>.
+     *
+     * @param absPath an absolute path <code>String</code>.
+     * @return This EventFilter object with the <code>absPath</code> parameter
set.
+     */
+    public JackrabbitEventFilter setAbsPath(String absPath) {
+        this.absPath = absPath;
+        return this;
+    }
+
+    /**
+     * Returns the <code>absPath</code> parameter of the filter.
+     *
+     * @return a <code>String</code>.
+     */
+    public String getAbsPath() {
+        return absPath;
+    }
+
+    /**
+     * Sets the <code>isDeep</code> parameter of the filter.
+     * If left unset, this parameter defaults to <code>false</code>.
+     *
+     * @param isDeep a <code>boolean</code>.
+     * @return This EventFilter object with the <code>isDeep</code> parameter
set.
+     */
+    public JackrabbitEventFilter setIsDeep(boolean isDeep) {
+        this.isDeep = isDeep;
+        return this;
+    }
+
+    /**
+     * Returns the <code>isDeep</code> parameter of the filter.
+     *
+     * @return a <code>boolean</code>.
+     */
+    public boolean getIsDeep() {
+        return isDeep;
+    }
+
+    /**
+     * Sets the <code>identifiers</code> parameter of the filter.
+     * If left unset, this parameter defaults to <code>null</code>.
+     *
+     * @param identifiers a <code>String</code> array.
+     * @return This EventFilter object with the <code>identifiers</code> parameter
set.
+     */
+    public JackrabbitEventFilter setIdentifiers(String[] identifiers) {
+        this.identifiers = copyOf(identifiers, identifiers.length);
+        return null;
+    }
+
+    /**
+     * Returns the <code>uuids</code> parameter of the filter.
+     *
+     * @return a <code>String</code> array.
+     */
+    public String[] getIdentifiers() {
+        return identifiers == null ? null : copyOf(identifiers, identifiers.length);
+    }
+
+    /**
+     * Sets the <code>nodeTypeNames</code> parameter of the filter.
+     * If left unset, this parameter defaults to <code>null</code>.
+     *
+     * @param nodeTypeNames a <code>String</code> array.
+     * @return This EventFilter object with the <code>nodeTypes</code> parameter
set.
+     */
+    public JackrabbitEventFilter setNodeTypes(String[] nodeTypeNames) {
+        this.nodeTypeNames = copyOf(nodeTypeNames, nodeTypeNames.length);
+        return this;
+    }
+
+    /**
+     * Returns the <code>nodeTypeName</code> parameter of the filter.
+     *
+     * @return a <code>String</code> array.
+     */
+    public String[] getNodeTypes() {
+        return nodeTypeNames == null ? null : copyOf(nodeTypeNames, nodeTypeNames.length);
+    }
+
+    /**
+     * Sets the <code>noLocal</code> parameter of the filter.
+     * If left unset, this parameter defaults to <code>false</code>.
+     *
+     * @param noLocal a <code>boolean</code>.
+     * @return This EventFilter object with the <code>noLocal</code> parameter
set.
+     */
+    public JackrabbitEventFilter setNoLocal(boolean noLocal) {
+        this.noLocal = noLocal;
+        return this;
+    }
+
+    /**
+     * Returns the <code>noLocal</code> parameter of the filter.
+     *
+     * @return a <code>boolean</code>.
+     */
+    public boolean getNoLocal() {
+        return noLocal;
+    }
+
+    /**
+     * Sets the <code>absPaths</code> parameter of the filter.
+     * If left unset, this parameter defaults to an empty array.
+     *
+     * @param absPaths an absolute path <code>String</code> array.
+     * @return This EventFilter object with the <code>absPaths</code> parameter
set.
+     */
+    public JackrabbitEventFilter setAdditionalPaths(String... absPaths) {
+        this.absPaths = copyOf(absPaths, absPaths.length);
+        return this;
+    }
+
+    /**
+     * Returns the <code>absPaths</code> parameter of the filter.
+     *
+     * @return a <code>String</code> array.
+     */
+    public String[] getAdditionalPaths() {
+        return copyOf(absPaths, absPaths.length);
+    }
+
+    /**
+     * Sets the <code>noExternal</code> parameter of the filter.
+     * If left unset, this parameter defaults to <code>false</code>.
+     *
+     * @param noExternal a <code>boolean</code>.
+     * @return This EventFilter object with the <code>noExternal</code> parameter
set.
+     */
+    public JackrabbitEventFilter setNoExternal(boolean noExternal) {
+        this.noExternal = noExternal;
+        return this;
+    }
+
+    /**
+     * Returns the <code>noExternal</code> parameter of the filter.
+     *
+     * @return a <code>boolean</code>.
+     */
+    public boolean getNoExternal() {
+        return noExternal;
+    }
+}
\ No newline at end of file

Added: jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation/JackrabbitObservationManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation/JackrabbitObservationManager.java?rev=1577213&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation/JackrabbitObservationManager.java
(added)
+++ jackrabbit/trunk/jackrabbit-api/src/main/java/org/apache/jackrabbit/api/observation/JackrabbitObservationManager.java
Thu Mar 13 15:50:52 2014
@@ -0,0 +1,54 @@
+/*
+ * 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.api.observation;
+
+import javax.jcr.RepositoryException;
+import javax.jcr.observation.EventListener;
+
+/**
+ * Jackrabbit specific extensions to {@link javax.jcr.observation.ObservationManager}.
+ */
+public interface JackrabbitObservationManager {
+
+    /**
+     * Adds an event listener that listens for the events specified
+     * by the passed {@link JackrabbitEventFilter}.
+     * <p>
+     * In addition to the <code>EventFilter</code>, the set of events reported
+     * will be further filtered by the access rights of the
+     * current <code>Session</code>.
+     * <p>
+     * See {@link JackrabbitEventFilter} for a description of the filtering parameters available.
+     * <p>
+     * The filter of an already-registered <code>EventListener</code> can be
+     * changed at runtime by re-registering the same <code>EventListener</code>
+     * object (i.e. the same actual Java object) with a new filter.
+     * The implementation must ensure that no events are lost during the changeover.
+     * <p>
+     * In addition to the filters placed on a listener above, the scope of
+     * observation support, in terms of which parts of a workspace are observable, may also
+     * be subject to implementation-specific restrictions. For example, in some
+     * repositories observation of changes in the <code>jcr:system</code>
+     * subgraph may not be supported.
+     *
+     * @param listener     an {@link EventListener} object.
+     * @param filter       an {@link JackrabbitEventFilter} object.
+     * @throws RepositoryException If an error occurs.
+     */
+    void addEventListener(EventListener listener, JackrabbitEventFilter filter)
+            throws RepositoryException;
+}



Mime
View raw message