jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r482631 - in /jackrabbit/trunk/contrib/spi: jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/ jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/ spi/src/main/java/o...
Date Tue, 05 Dec 2006 12:59:40 GMT
Author: mreutegg
Date: Tue Dec  5 04:59:39 2006
New Revision: 482631

URL: http://svn.apache.org/viewvc?view=rev&rev=482631
Log:
Work in progress
- Add SessionInfo parameter to RepositoryService.createEventFilter()
- Move creation of event filter in ObservationManagerImpl.addEventListener() out of synchronized
block
- Make sure subscription is in place before batch
- NodeTypeDefinitions are not cached in RepositoryServiceImpl
- Return empty EventBundle array if there were no events
- Decide whether an event bundle is local based on lastBatchId in SessionInfo and transactionId
in EventBundle.

Modified:
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java
    jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateManager.java
    jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
    jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java?view=diff&rev=482631&r1=482630&r2=482631
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/WorkspaceManager.java
Tue Dec  5 04:59:39 2006
@@ -294,8 +294,8 @@
     public EventFilter createEventFilter(int eventTypes, Path path, boolean isDeep,
                                          String[] uuids, QName[] nodeTypes,
                                          boolean noLocal)
-        throws UnsupportedRepositoryOperationException {
-        return service.createEventFilter(eventTypes, path, isDeep, uuids, nodeTypes, noLocal);
+        throws UnsupportedRepositoryOperationException, RepositoryException {
+        return service.createEventFilter(sessionInfo, eventTypes, path, isDeep, uuids, nodeTypes,
noLocal);
     }
     //--------------------------------------------------------------------------
     /**

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java?view=diff&rev=482631&r1=482630&r2=482631
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/observation/ObservationManagerImpl.java
Tue Dec  5 04:59:39 2006
@@ -127,8 +127,8 @@
             }
         }
 
+        EventFilter filter = wspManager.createEventFilter(eventTypes, path, isDeep, uuids,
nodeTypeQNames, noLocal);
         synchronized (subscriptions) {
-            EventFilter filter = wspManager.createEventFilter(eventTypes, path, isDeep, uuids,
nodeTypeQNames, noLocal);
             subscriptions.put(listener, filter);
             readOnlySubscriptions = null;
         }

Modified: jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateManager.java?view=diff&rev=482631&r1=482630&r2=482631
==============================================================================
--- jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateManager.java
(original)
+++ jackrabbit/trunk/contrib/spi/jcr2spi/src/main/java/org/apache/jackrabbit/jcr2spi/state/WorkspaceItemStateManager.java
Tue Dec  5 04:59:39 2006
@@ -29,6 +29,7 @@
 import org.slf4j.LoggerFactory;
 
 import javax.jcr.UnsupportedRepositoryOperationException;
+import javax.jcr.RepositoryException;
 import java.util.Set;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -56,8 +57,8 @@
             try {
                 // todo for now listen to everything
                 filter = wspManager.createEventFilter(Event.ALL_TYPES, Path.ROOT, true, null,
null, false);
-            } catch (UnsupportedRepositoryOperationException e) {
-                // spi does not support observation
+            } catch (RepositoryException e) {
+                // spi does not support observation, or another error occurred.
             }
             this.eventFilter = (filter == null) ? Collections.EMPTY_LIST : Collections.singletonList(filter);
         } else {

Modified: jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java?view=diff&rev=482631&r1=482630&r2=482631
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi/src/main/java/org/apache/jackrabbit/spi/RepositoryService.java
Tue Dec  5 04:59:39 2006
@@ -530,6 +530,7 @@
      * the corresponding {@link javax.jcr.Repository#OPTION_OBSERVATION_SUPPORTED repository
descriptor}
      * does not return 'true'.
      *
+     * @param sessionInfo the session info which requests an event filter.
      * @param eventTypes A combination of one or more event type constants
      * encoded as a bitmask.
      * @param absPath An absolute path.
@@ -540,12 +541,15 @@
      * @return the event filter instance with the given parameters.
      * @throws UnsupportedRepositoryOperationException if this SPI implementation
      * does not allow to create event filters.
+     * @throws RepositoryException if an error occurs while creating the
+     * EventFilter.
      * @see javax.jcr.observation.ObservationManager#addEventListener(javax.jcr.observation.EventListener,
int, String, boolean, String[], String[], boolean)
      */
-    public EventFilter createEventFilter(int eventTypes, Path absPath,
-                                         boolean isDeep, String[] uuid,
-                                         QName[] nodeTypeName, boolean noLocal)
-            throws UnsupportedRepositoryOperationException;
+    public EventFilter createEventFilter(SessionInfo sessionInfo, int eventTypes,
+                                         Path absPath, boolean isDeep,
+                                         String[] uuid, QName[] nodeTypeName,
+                                         boolean noLocal)
+            throws UnsupportedRepositoryOperationException, RepositoryException;
 
     /**
      * Retrieves the external events that occurred since the last call to this

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java?view=diff&rev=482631&r1=482630&r2=482631
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/RepositoryServiceImpl.java
Tue Dec  5 04:59:39 2006
@@ -1155,20 +1155,25 @@
     }
 
     /**
-     * @see RepositoryService#createEventFilter(int, org.apache.jackrabbit.name.Path, boolean,
String[], org.apache.jackrabbit.name.QName[], boolean)
+     * @see RepositoryService#createEventFilter(SessionInfo, int, org.apache.jackrabbit.name.Path,
boolean, String[], org.apache.jackrabbit.name.QName[], boolean)
      */
-    public EventFilter createEventFilter(int eventTypes,
+    public EventFilter createEventFilter(SessionInfo sessionInfo,
+                                         int eventTypes,
                                          Path absPath,
                                          boolean isDeep,
                                          String[] uuids,
                                          QName[] nodeTypeNames,
                                          boolean noLocal)
-            throws UnsupportedRepositoryOperationException {
+            throws UnsupportedRepositoryOperationException, RepositoryException {
         // resolve node type names
         // todo what if new node types become available while event filter is still in use?
         Set resolvedTypeNames = null;
         if (nodeTypeNames != null) {
             resolvedTypeNames = new HashSet();
+            // make sure node type definitions are available
+            if (nodeTypeDefinitions.size() == 0) {
+                getNodeTypeDefinitions(sessionInfo);
+            }
             synchronized (nodeTypeDefinitions) {
                 for (int i = 0; i < nodeTypeNames.length; i++) {
                     resolveNodeType(resolvedTypeNames, nodeTypeNames[i]);
@@ -1195,7 +1200,7 @@
             sessionInfoImpl.setSubscriptionId(subscriptionId);
         }
 
-        return poll(rootUri, subscriptionId, sessionInfo);
+        return poll(rootUri, subscriptionId, (SessionInfoImpl) sessionInfo);
         // todo timeout is not respected
     }
 
@@ -1260,7 +1265,7 @@
         }
     }
 
-    private EventBundle[] poll(String uri, String subscriptionId,  SessionInfo sessionInfo)
throws RepositoryException {
+    private EventBundle[] poll(String uri, String subscriptionId,  SessionInfoImpl sessionInfo)
throws RepositoryException {
         PollMethod method = null;
         try {
             method = new PollMethod(uri, subscriptionId);
@@ -1270,7 +1275,7 @@
             EventDiscovery disc = method.getResponseAsEventDiscovery();
             EventBundle[] events;
             if (disc.isEmpty()) {
-                events = new EventBundle[]{EventBundleImpl.EMPTY};
+                events = new EventBundle[0];
             } else {
                 Element discEl = disc.toXml(domFactory);
                 ElementIterator it = DomUtil.getChildren(discEl,
@@ -1279,9 +1284,14 @@
                 List bundles = new ArrayList();
                 while (it.hasNext()) {
                     Element bundleElement = it.nextElement();
-                    String value = DomUtil.getAttribute(bundleElement, ObservationConstants.XML_EVENT_IS_LOCAL,
NAMESPACE);
-                    boolean isLocal = (value != null) ? Boolean.valueOf(value).booleanValue()
: false;
-
+                    String value = DomUtil.getAttribute(bundleElement,
+                            ObservationConstants.XML_EVENT_TRANSACTION_ID,
+                            ObservationConstants.NAMESPACE);
+                    // check if it matches a batch id recently submitted
+                    boolean isLocal = false;
+                    if (value != null && sessionInfo instanceof SessionInfoImpl)
{
+                        isLocal = value.equals(sessionInfo.getLastBatchId());
+                    }
                     bundles.add(new EventBundleImpl(buildEventList(bundleElement, sessionInfo),
isLocal));
                 }
                 events = (EventBundle[]) bundles.toArray(new EventBundle[bundles.size()]);
@@ -1483,7 +1493,7 @@
             // refresh node type definitions map
             synchronized (nodeTypeDefinitions) {
                 nodeTypeDefinitions.clear();
-                for (Iterator defIt = ntDefs.iterator(); it.hasNext(); ) {
+                for (Iterator defIt = ntDefs.iterator(); defIt.hasNext(); ) {
                     QNodeTypeDefinition def = (QNodeTypeDefinition) defIt.next();
                     nodeTypeDefinitions.put(def.getQName(), def);
                 }
@@ -1589,6 +1599,9 @@
                 method.setRequestBody(new TransactionInfo(commit));
                 client.executeMethod(method);
                 method.checkSuccess();
+                if (sessionInfo instanceof SessionInfoImpl) {
+                    ((SessionInfoImpl) sessionInfo).setLastBatchId(batchId);
+                }
             } catch (IOException e) {
                 throw new RepositoryException(e);
             } catch (DavException e) {

Modified: jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java?view=diff&rev=482631&r1=482630&r2=482631
==============================================================================
--- jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
(original)
+++ jackrabbit/trunk/contrib/spi/spi2dav/src/main/java/org/apache/jackrabbit/spi2dav/SessionInfoImpl.java
Tue Dec  5 04:59:39 2006
@@ -38,6 +38,8 @@
 
     private String lastEventBundleId;
 
+    private String lastBatchId;
+
     /**
      * The subscriptionId if this session info is subscribed to observation
      * events.
@@ -125,5 +127,24 @@
         String old = this.subscriptionId;
         this.subscriptionId = subscriptionId;
         return old;
+    }
+
+    /**
+     * Returns the id of the most recently submitted batch or <code>null</code>
+     * it no batch has been submitted yet.
+     *
+     * @return the batch id of the most recently submitted batch.
+     */
+    String getLastBatchId() {
+        return lastBatchId;
+    }
+
+    /**
+     * Sets the id of the most recently submitted batch.
+     *
+     * @param batchId the batch id.
+     */
+    void setLastBatchId(String batchId) {
+        this.lastBatchId = batchId;
     }
 }



Mime
View raw message