jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mdue...@apache.org
Subject svn commit: r1136915 - in /jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel: RepositoryServiceImpl.java SessionState.java
Date Fri, 17 Jun 2011 15:44:43 GMT
Author: mduerig
Date: Fri Jun 17 15:44:43 2011
New Revision: 1136915

URL: http://svn.apache.org/viewvc?rev=1136915&view=rev
Log:
spi2microkernel prototype (WIP)
refectored session state into SessionState class

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

Modified: jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java?rev=1136915&r1=1136914&r2=1136915&view=diff
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
(original)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/RepositoryServiceImpl.java
Fri Jun 17 15:44:43 2011
@@ -59,6 +59,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.Callable;
 
 import static javax.jcr.Repository.*;
 import static org.apache.jackrabbit.spi.commons.name.NameConstants.*;
@@ -76,7 +77,7 @@ public class RepositoryServiceImpl exten
     }};
 
     private final MicroKernel microKernel;
-    private final Map<SessionInfo, String> sessions = new HashMap<SessionInfo, String>();
+    private final Map<SessionInfo, SessionState> sessions = new HashMap<SessionInfo,
SessionState>();
 
     public RepositoryServiceImpl(MicroKernel microKernel) throws RepositoryException {
         super(DESCRIPTORS, Collections.<String, String>emptyMap(), NodeTypes.getDefaultNodeTypes());
@@ -109,14 +110,14 @@ public class RepositoryServiceImpl exten
     @Override
     protected SessionInfo createSessionInfo(SessionInfo sessionInfo, String workspaceName)
throws RepositoryException {
         SessionInfo s = super.createSessionInfo(sessionInfo, workspaceName);
-        initSessionInfo(s);
+        createSessionState(s);
         return s;
     }
 
     @Override
     protected SessionInfo createSessionInfo(Credentials credentials, String workspaceName)
throws RepositoryException {
         SessionInfo s = super.createSessionInfo(credentials, workspaceName);
-        initSessionInfo(s);
+        createSessionState(s);
         return s;
     }
 
@@ -126,7 +127,7 @@ public class RepositoryServiceImpl exten
     }
 
     public String[] getWorkspaceNames(SessionInfo sessionInfo) throws RepositoryException
{
-        String rev = getRevision(sessionInfo);
+        String rev = sessionState(sessionInfo).getHeadRevision();
 
         // Names of first level nodes correspond to workspace names
         final List<String> workspaces = new ArrayList<String>();
@@ -191,7 +192,7 @@ public class RepositoryServiceImpl exten
             String wspName = sessionInfo.getWorkspaceName();
             Path path = nodeId.getPath();
             String mkPath = Paths.pathToString(wspName, path);
-            String rev = getRevision(sessionInfo);
+            String rev = sessionState(sessionInfo).getHeadRevision();
 
             if (microKernel.nodeExists(mkPath, rev)) {
                 String json = microKernel.getNodes(mkPath, rev);
@@ -211,7 +212,7 @@ public class RepositoryServiceImpl exten
             String wspName = sessionInfo.getWorkspaceName();
             Path path = nodeId.getPath();
             String mkPath = Paths.pathToString(wspName, path);
-            String rev = getRevision(sessionInfo);
+            String rev = sessionState(sessionInfo).getHeadRevision();
 
             NodeInfo info = null;
             if (microKernel.nodeExists(mkPath, rev)) {
@@ -236,7 +237,7 @@ public class RepositoryServiceImpl exten
             String wspName = sessionInfo.getWorkspaceName();
             Path path = propertyId.getPath();
             String mkPath = Paths.pathToString(wspName, path.getAncestor(1));
-            String rev = getRevision(sessionInfo);
+            String rev = sessionState(sessionInfo).getHeadRevision();
 
             PropertyInfo info = null;
             if (microKernel.nodeExists(mkPath, rev)) {
@@ -287,7 +288,7 @@ public class RepositoryServiceImpl exten
 
     @Override
     public void createWorkspace(SessionInfo sessionInfo, String name, String srcWorkspaceName)
throws RepositoryException {
-        String rev = getRevision(sessionInfo);
+        String rev = sessionState(sessionInfo).getHeadRevision();
         if (srcWorkspaceName == null) {
             createWorkspace(rev, name, false);
         }
@@ -298,7 +299,7 @@ public class RepositoryServiceImpl exten
 
     @Override
     public void deleteWorkspace(SessionInfo sessionInfo, String name) throws RepositoryException
{
-        String rev = getRevision(sessionInfo);
+        String rev = sessionState(sessionInfo).getHeadRevision();
         deleteWorkspace(rev, name);
     }
 
@@ -339,24 +340,20 @@ public class RepositoryServiceImpl exten
         }
     }
 
-    private String getRevision(SessionInfo sessionInfo) throws RepositoryException {
-        String rev = sessions.get(sessionInfo);
+    private SessionState sessionState(SessionInfo sessionInfo) throws RepositoryException
{
+        SessionState state = sessions.get(sessionInfo);
 
-        if (rev == null) {
+        if (state == null) {
             throw new RepositoryException("Invalid session");
         }
         else {
-            return rev;
+            return state;
         }
     }
 
-    private void setRevision(SessionInfo sessionInfo, String revisionId) {
-        sessions.put(sessionInfo, revisionId);
-    }
-
-    private void initSessionInfo(SessionInfo sessionInfo) throws RepositoryException {
+    private void createSessionState(SessionInfo sessionInfo) throws RepositoryException {
         try {
-            setRevision(sessionInfo, microKernel.getHeadRevision());
+            sessions.put(sessionInfo, new SessionState(microKernel.getHeadRevision()));
         }
         catch (MicroKernelException e) {
             throw new RepositoryException(e.getMessage(), e);
@@ -483,9 +480,12 @@ public class RepositoryServiceImpl exten
         }
 
         public void commit() throws RepositoryException {
-            String rev = getRevision(sessionInfo);
-            rev = microKernel.commit("/", jsop.toString(), rev);
-            setRevision(sessionInfo, rev);
+            sessionState(sessionInfo).commitWithLock(new Callable<String>() {
+                public String call() throws RepositoryException {
+                    String rev = sessionState(sessionInfo).getHeadRevision();
+                    return microKernel.commit("/", jsop.toString(), rev);
+                }
+            });
         }
 
         private String target(NodeId nodeId) throws RepositoryException {

Added: 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=1136915&view=auto
==============================================================================
--- jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SessionState.java
(added)
+++ jackrabbit/sandbox/spi2microkernel/src/main/java/org/apache/jackrabbit/spi2microkernel/SessionState.java
Fri Jun 17 15:44:43 2011
@@ -0,0 +1,64 @@
+/*
+ * 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.spi2microkernel;
+
+import javax.jcr.RepositoryException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.Callable;
+
+public class SessionState {
+    private final String initialRevision;
+    private final List<String> revisionHistory = new ArrayList<String>();
+
+    public SessionState(String initialRevision) {
+        this.initialRevision = initialRevision;
+    }
+
+    public String getHeadRevision() {
+        return revisionHistory.isEmpty()
+            ? initialRevision
+            : revisionHistory.get(revisionHistory.size() - 1);
+    }
+
+    public void commitWithLock(Callable<String> commit) throws RepositoryException
{
+        try {
+            synchronized (this) {
+                revisionHistory.add(commit.call());
+            }
+        }
+        catch (Exception e) {
+            throw new RepositoryException(e.getMessage(), e); 
+        }
+    }
+
+    /**
+     * Snapshot of this sessions state at the time of the call
+     * @return
+     */
+    public SessionState freeze() {
+        SessionState frozen = new SessionState(initialRevision);
+        synchronized (revisionHistory) {
+            frozen.revisionHistory.addAll(revisionHistory);
+        }
+        return frozen;
+    }
+
+}



Mime
View raw message