jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1138349 - in /jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel: SessionState.java SubscriptionImpl.java
Date Wed, 22 Jun 2011 09:10:01 GMT
Author: mduerig
Date: Wed Jun 22 09:10:01 2011
New Revision: 1138349

URL: http://svn.apache.org/viewvc?rev=1138349&view=rev
Log:
spi2microkernel prototype (WIP)
observation (WIP)

Modified:
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SessionState.java
    jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SessionState.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SessionState.java?rev=1138349&r1=1138348&r2=1138349&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SessionState.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SessionState.java
Wed Jun 22 09:10:01 2011
@@ -27,24 +27,12 @@ import java.util.List;
 import java.util.concurrent.Callable;
 
 public class SessionState {
-    private final String initialRevision;
     private final SessionInfo sessionInfo;
-    private final List<RevisionInfo> commitLog = new ArrayList<RevisionInfo>();
+    private final List<String> commitLog = new ArrayList<String>();
 
     public SessionState(SessionInfo sessionInfo, String initialRevision) {
         this.sessionInfo = sessionInfo;
-        this.initialRevision = initialRevision;
-    }
-
-    public String getHeadRevision() {
-        if (commitLog.isEmpty()) {
-            return initialRevision;
-        }
-        else {
-            synchronized (commitLog) {
-                return commitLog.get(commitLog.size() - 1).getRevisionId();
-            }
-        }
+        commitLog.add(initialRevision);
     }
 
     public SessionInfo getSessionInfo() {
@@ -54,7 +42,7 @@ public class SessionState {
     public void commitWithLock(Callable<String> commit) throws RepositoryException
{
         try {
             synchronized (this) {
-                commitLog.add(new RevisionInfo(commit.call(), sessionInfo.getUserID(), null/*
fixme: need accessors sessionInfo.getUserInfo()) */));
+                commitLog.add(commit.call());
             }
         }
         catch (Exception e) {
@@ -66,36 +54,12 @@ public class SessionState {
      * Snapshot of this session state's commit log at the time of the call
      * @return
      */
-    public List<RevisionInfo> getRevisionInfos() {
-        List<RevisionInfo> commitLog = new ArrayList<RevisionInfo>(this.commitLog.size());
+    public List<String> getCommitLog() {
+        List<String> commitLog = new ArrayList<String>(this.commitLog.size());
         synchronized (this.commitLog) {
             commitLog.addAll(this.commitLog);
         }
         return commitLog;
     }
 
-    public static class RevisionInfo {
-        private final String revisionId;
-        private final String userId;
-        private final String userData;
-
-        public RevisionInfo(String revisionId, String userId, String userData) {
-            this.revisionId = revisionId;
-            this.userId = userId;
-            this.userData = userData;
-        }
-
-        public String getRevisionId() {
-            return revisionId;
-        }
-
-        public String getUserId() {
-            return userId;
-        }
-
-        public String getUserData() {
-            return userData;
-        }
-    }
-
 }

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java?rev=1138349&r1=1138348&r2=1138349&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SubscriptionImpl.java
Wed Jun 22 09:10:01 2011
@@ -32,7 +32,6 @@ import org.apache.jackrabbit.spi.QValue;
 import org.apache.jackrabbit.spi.Subscription;
 import org.apache.jackrabbit.spi.commons.EventBundleImpl;
 import org.apache.jackrabbit.spi.commons.EventImpl;
-import org.apache.jackrabbit.spi2microkernel.SessionState.RevisionInfo;
 import org.json.simple.JSONArray;
 import org.json.simple.JSONObject;
 import org.json.simple.parser.JSONParser;
@@ -60,8 +59,7 @@ public class SubscriptionImpl implements
 
     public void setEventFilters(EventFilter[] eventFilters) throws RepositoryException {
         synchronized (eventSources) {
-            List<RevisionInfo> revisionInfos = sessionState.getRevisionInfos();
-            eventSources.add(new EventSource(eventFilters, sessionState.getHeadRevision(),
revisionInfos));
+            eventSources.add(new EventSource(eventFilters, sessionState));
         }
     }
 
@@ -111,21 +109,23 @@ public class SubscriptionImpl implements
 
     private class EventSource {
         private final EventFilter[] eventFilters;
-        private final String startRevision;
-        private final List<RevisionInfo> revisionInfos;
+        private final List<String> commitLog;
 
-        public EventSource(EventFilter[] eventFilters, String startRevision, List<RevisionInfo>
revisionInfos) {
+        public EventSource(EventFilter[] eventFilters, SessionState sessionState) {
+            this(eventFilters, sessionState.getCommitLog());
+        }
+
+        public EventSource(EventFilter[] eventFilters, List<String> commitLog) {
             this.eventFilters = eventFilters;
-            this.startRevision = startRevision;
-            this.revisionInfos = revisionInfos;
+            this.commitLog = commitLog;
         }
 
         public String getStartRevision() {
-            return startRevision;
+            return commitLog.get(commitLog.size() - 1);
         }
 
         public Collection<? extends EventBundle> getEventsBundles(String endRevision)
throws RepositoryException {
-            String journal = microKernel.getJournal(startRevision, endRevision);
+            String journal = microKernel.getJournal(getStartRevision(), endRevision);
             List<EventBundle> eventBundles = new ArrayList<EventBundle>();
 
             try {
@@ -146,33 +146,25 @@ public class SubscriptionImpl implements
         }
 
         public EventSource update(String startRevision) {
-            return new EventSource(eventFilters, startRevision, revisionInfos);
+            return new EventSource(eventFilters, commitLog);
         }
 
         //------------------------------------------< private >---
         
         private EventBundle createEventBundle(JSONObject jsonObject) {
             String revisionId = getString(jsonObject, "id");
-
-            // revisionInfo = revisionInfos.find(_.getRevisionId == revisionId)
-            RevisionInfo revisionInfo = null;
-            for (RevisionInfo info : revisionInfos) {
-                if (info.getRevisionId().equals(revisionId)) { // todo performance: use map!?
-                    revisionInfo = info;
-                    break;
-                }
-            }
+            String userData = ""; // getString(jsonObject, "msg");  // todo see http://markmail.org/message/fzf7clnyvs6uzaus
 
             EventTemplate eventTemplate = new EventTemplate()
                     .setTimestamp(getLong(jsonObject, "ts"))
-                    .setUserId(revisionInfo.getUserId())
-                    .setUserData(revisionInfo.getUserData());
+                    .setUserId(sessionState.getSessionInfo().getUserID())
+                    .setUserData(userData);
 
             String changes = getString(jsonObject, "changes");
             Collection<Event> events = getEvents(changes, eventTemplate);
 
             // fixme: revisionInfos.map(_.getRevisionId)
-            boolean isLocal = revisionInfos.contains(revisionId);  // todo performance: this
does a linear search on the list
+            boolean isLocal = commitLog.contains(revisionId);  // todo performance: this
does a linear search on the list
 
             // events.filter(event => eventFilters.all(_.accept(event, isLocal))
             for (Iterator<Event> it = events.iterator(); it.hasNext(); ) {



Mime
View raw message