chemistry-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1415841 - in /chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src: main/java/org/apache/chemistry/opencmis/inmemory/server/ test/java/org/apache/chemistry/opencmis/inmemory/
Date Fri, 30 Nov 2012 20:34:23 GMT
Author: jens
Date: Fri Nov 30 20:34:21 2012
New Revision: 1415841

URL: http://svn.apache.org/viewvc?rev=1415841&view=rev
Log:
InMemoryService: prepare for more CMIS 1.1 features, make call context globally available

Added:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceContext.java
Modified:
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryService.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java
    chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.java

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryService.java?rev=1415841&r1=1415840&r2=1415841&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryService.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryService.java
Fri Nov 30 20:34:21 2012
@@ -56,7 +56,6 @@ public class InMemoryService extends Abs
     private static final Logger LOG = LoggerFactory.getLogger(InMemoryService.class.getName());
 
     private final StoreManager storeManager; // singleton root of everything
-    private CallContext context;
 
     private final InMemoryRepositoryServiceImpl fRepSvc;
     private final InMemoryObjectServiceImpl fObjSvc;
@@ -82,16 +81,22 @@ public class InMemoryService extends Abs
     }
 
     public CallContext getCallContext() {
-        return context;
+        return InMemoryServiceContext.getCallContext();
     }
 
     public void setCallContext(CallContext context) {
-        this.context = context;
+        InMemoryServiceContext.setCallContext(context);
     }
 
     // --- repository service ---
 
     @Override
+    public void close() {
+        super.close();
+        setCallContext(null);
+    }
+
+    @Override
     public List<RepositoryInfo> getRepositoryInfos(ExtensionsData extension) {
         return fRepSvc.getRepositoryInfos(getCallContext(), extension);
     }

Added: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceContext.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceContext.java?rev=1415841&view=auto
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceContext.java
(added)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceContext.java
Fri Nov 30 20:34:21 2012
@@ -0,0 +1,85 @@
+/*
+ * 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.chemistry.opencmis.inmemory.server;
+
+import org.apache.chemistry.opencmis.commons.server.CallContext;
+import org.apache.chemistry.opencmis.server.support.CmisServiceWrapper;
+
+/**
+ * Helper class to associate context information with each incoming call
+ *
+ */
+public class InMemoryServiceContext {
+    
+    private static class ContextHolder {
+        private CmisServiceWrapper<InMemoryService> wrapper;
+        private CallContext callContext;
+
+        ContextHolder(CmisServiceWrapper<InMemoryService> wrapper) {
+            this.wrapper = wrapper;
+        }
+
+        public CmisServiceWrapper<InMemoryService> getServiceWrapper() {
+            return wrapper;
+        }
+        
+        public void setCallContext(CallContext context) {
+            this.callContext = context;
+        }
+        
+        public CallContext getCallContext() {
+            return callContext;
+        }
+    }
+    
+    private static ThreadLocal<ContextHolder> threadLocalService = new ThreadLocal<ContextHolder>();
+    
+    public static synchronized void setWrapperService(CmisServiceWrapper<InMemoryService>
wrapperService) {
+        threadLocalService.remove();
+        if (null != wrapperService) {
+            ContextHolder holder = new ContextHolder(wrapperService);
+            threadLocalService.set(holder);                    
+        }
+    }
+    
+    public static synchronized InMemoryService getCmisService() {
+        ContextHolder holder = threadLocalService.get();
+        if (null == holder)
+            return null;
+        else {
+            CmisServiceWrapper<InMemoryService> wrapperService = holder.getServiceWrapper();
+            return wrapperService == null ? null : wrapperService.getWrappedService();
+        }        
+    }
+    
+    public static synchronized void  setCallContext(CallContext context) {
+        ContextHolder holder = threadLocalService.get();
+        if (null == holder)
+            throw new IllegalStateException("Cannot store call context, no service wrapper
set.");
+        else {
+            holder.setCallContext(context);
+        }        
+    }
+    
+    public static CallContext getCallContext() {
+        ContextHolder holder = threadLocalService.get();
+        return null == holder ? null : holder.getCallContext();        
+    }
+    
+}

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java?rev=1415841&r1=1415840&r2=1415841&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/main/java/org/apache/chemistry/opencmis/inmemory/server/InMemoryServiceFactoryImpl.java
Fri Nov 30 20:34:21 2012
@@ -74,7 +74,6 @@ public class InMemoryServiceFactoryImpl 
     private static CallContext OVERRIDE_CTX;
 
     private Map<String, String> inMemoryServiceParameters;
-    private ThreadLocal<CmisServiceWrapper<InMemoryService>> threadLocalService
= new ThreadLocal<CmisServiceWrapper<InMemoryService>>();
     private boolean fUseOverrideCtx = false;
     private StoreManager storeManager; // singleton root of everything
     private CleanManager cleanManager = null;
@@ -154,18 +153,19 @@ public class InMemoryServiceFactoryImpl 
             context = OVERRIDE_CTX;
         }
 
-        CmisServiceWrapper<InMemoryService> wrapperService = threadLocalService.get();
-        if (wrapperService == null) {
-            wrapperService = new CmisServiceWrapper<InMemoryService>(new InMemoryService(inMemoryServiceParameters,
-                    storeManager), DEFAULT_MAX_ITEMS_TYPES, DEFAULT_DEPTH_TYPES, DEFAULT_MAX_ITEMS_OBJECTS,
-                    DEFAULT_DEPTH_OBJECTS);
-            threadLocalService.set(wrapperService);
+        InMemoryService inMemoryService = InMemoryServiceContext.getCmisService();
+        if (inMemoryService == null) {
+            CmisServiceWrapper<InMemoryService> wrapperService;
+            inMemoryService = new InMemoryService(inMemoryServiceParameters, storeManager);
+            wrapperService = new CmisServiceWrapper<InMemoryService>(inMemoryService,
DEFAULT_MAX_ITEMS_TYPES,
+                    DEFAULT_DEPTH_TYPES, DEFAULT_MAX_ITEMS_OBJECTS, DEFAULT_DEPTH_OBJECTS);
+            InMemoryServiceContext.setWrapperService(wrapperService);
         }
 
-        wrapperService.getWrappedService().setCallContext(context);
+        inMemoryService.setCallContext(context);
 
         LOG.debug("stop getService()");
-        return wrapperService.getWrappedService(); // wrapperService;
+        return inMemoryService; // wrapperService;
     }
 
     @Override
@@ -193,7 +193,7 @@ public class InMemoryServiceFactoryImpl 
         if (null != cleanManager) {
             cleanManager.stopCleanRepositoryJob();
         }
-        threadLocalService = null;
+        InMemoryServiceContext.setWrapperService(null);
     }
 
     public StoreManager getStoreManger() {
@@ -358,10 +358,7 @@ public class InMemoryServiceFactoryImpl 
         String contentKindStr = parameters.get(ConfigConstants.CONTENT_KIND);
         boolean doFillRepository = doFillRepositoryStr == null ? false : Boolean.parseBoolean(doFillRepositoryStr);
 
-        if (doFillRepository /*
-                              * &&
-                              * !allAvailableRepositories.contains(repositoryId)
-                              */) {
+        if (doFillRepository) {
 
             // create an initial temporary service instance to fill the
             // repository
@@ -452,10 +449,10 @@ public class InMemoryServiceFactoryImpl 
 
             // Simulate a runtime context with configuration parameters
             // Attach the CallContext to a thread local context that can be
-            // accessed
-            // from everywhere
+            // accessed from everywhere
             DummyCallContext ctx = new DummyCallContext();
-            svc.setCallContext(ctx);
+            // create thread local storage and attach call context
+            getService(ctx);
 
             // Build the tree
             RepositoryInfo rep = svc.getRepositoryInfo(repositoryId, null);
@@ -469,6 +466,7 @@ public class InMemoryServiceFactoryImpl 
                 LOG.error("Could not create folder hierarchy with documents. " + e);
                 e.printStackTrace();
             }
+            destroy();
         } // if
 
     } // fillRepositoryIfConfigured

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java?rev=1415841&r1=1415840&r2=1415841&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/AbstractServiceTest.java
Fri Nov 30 20:34:21 2012
@@ -81,6 +81,8 @@ public class AbstractServiceTest {
     protected CallContext fTestCallContext;
     private String fTypeCreatorClassName;
 
+    private CmisBinding binding;
+
     public AbstractServiceTest() {
         // The in-memory server unit tests can either be run directly against
         // the
@@ -104,7 +106,6 @@ public class AbstractServiceTest {
     }
 
     protected void setUp() {
-        // super.setUp();
         LOG.debug("Initializing InMemory Test with type creator class: " + fTypeCreatorClassName);
         Map<String, String> parameters = new HashMap<String, String>();
 
@@ -112,8 +113,7 @@ public class AbstractServiceTest {
         parameters.put(ConfigConstants.TYPE_CREATOR_CLASS, fTypeCreatorClassName);
         parameters.put(ConfigConstants.REPOSITORY_ID, REPOSITORY_ID);
 
-        // give subclasses a chance to provide additional parameters for special
-        // tests
+        // give subclasses a chance to provide additional parameters for special tests
         addParameters(parameters);
 
         fTestCallContext = new DummyCallContext();
@@ -142,7 +142,7 @@ public class AbstractServiceTest {
     }
 
     protected void tearDown() {
-        // super.tearDown();
+        binding.close();
     }
 
     public void testDummy() {
@@ -404,7 +404,7 @@ public class AbstractServiceTest {
 
         // get factory and create binding
         CmisBindingFactory factory = CmisBindingFactory.newInstance();
-        CmisBinding binding = factory.createCmisLocalBinding(parameters);
+        binding = factory.createCmisLocalBinding(parameters);
         assertNotNull(binding);
         fFactory = binding.getObjectFactory();
         fRepSvc = binding.getRepositoryService();

Modified: chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.java?rev=1415841&r1=1415840&r2=1415841&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.java
(original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-inmemory/src/test/java/org/apache/chemistry/opencmis/inmemory/DiscoveryServiceTest.java
Fri Nov 30 20:34:21 2012
@@ -28,10 +28,11 @@ import org.apache.chemistry.opencmis.com
 import org.apache.chemistry.opencmis.commons.enums.IncludeRelationships;
 import org.apache.chemistry.opencmis.inmemory.ObjectServiceTest.ObjectTestTypeSystemCreator;
 import org.apache.chemistry.opencmis.util.repository.ObjectGenerator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class DiscoveryServiceTest extends AbstractServiceTest {
 
@@ -48,6 +49,11 @@ public class DiscoveryServiceTest extend
         super.setUp();
     }
 
+    @After
+    public void tearDown() {
+        super.tearDown();
+    }
+
     @Test
     public void testQuery() {
         log.info("starting testQuery() ...");



Mime
View raw message