myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gpetra...@apache.org
Subject svn commit: r1004052 - in /myfaces/extensions/cdi/trunk: core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/config/ core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/config/ core/impl/src/main/java/org/apache/myfaces/ex...
Date Sun, 03 Oct 2010 21:35:04 GMT
Author: gpetracek
Date: Sun Oct  3 21:35:02 2010
New Revision: 1004052

URL: http://svn.apache.org/viewvc?rev=1004052&view=rev
Log:
EXTCDI-6, EXTCDI-69 and small refactorings

Added:
    myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/config/ConfigStorage.java
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/ValidatorFactoryStorage.java
Removed:
    myfaces/extensions/cdi/trunk/core/api/src/main/java/org/apache/myfaces/extensions/cdi/core/api/config/DeactivatedCodiConfig.java
Modified:
    myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/config/ConfigProducer.java
    myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/utils/ApplicationCache.java
    myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/CdiAwareBeanValidationProducer.java

Modified: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/config/ConfigProducer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/config/ConfigProducer.java?rev=1004052&r1=1004051&r2=1004052&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/config/ConfigProducer.java
(original)
+++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/config/ConfigProducer.java
Sun Oct  3 21:35:02 2010
@@ -19,9 +19,11 @@
 package org.apache.myfaces.extensions.cdi.core.impl.config;
 
 import org.apache.myfaces.extensions.cdi.core.api.config.CodiConfig;
-import org.apache.myfaces.extensions.cdi.core.api.config.DeactivatedCodiConfig;
 import org.apache.myfaces.extensions.cdi.core.api.resolver.ConfigResolver;
+import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils;
 import org.apache.myfaces.extensions.cdi.core.impl.utils.ApplicationCache;
+import org.apache.myfaces.extensions.cdi.core.impl.utils.ClassDeactivation;
+import static org.apache.myfaces.extensions.cdi.core.impl.config.ConfigStorage.*;
 
 import javax.enterprise.inject.Produces;
 import javax.enterprise.inject.spi.BeanManager;
@@ -30,9 +32,7 @@ import javax.enterprise.context.spi.Crea
 import javax.enterprise.context.ApplicationScoped;
 import javax.inject.Inject;
 import java.util.Set;
-import java.util.HashSet;
 import java.util.Collections;
-import java.util.Arrays;
 
 /**
  * @author Gerhard Petracek
@@ -40,12 +40,6 @@ import java.util.Arrays;
 @SuppressWarnings({"UnusedDeclaration"})
 public class ConfigProducer
 {
-    private static Boolean configInitialized;
-
-    private static Set<CodiConfig> configSet;
-
-    private static Set<Class<? extends CodiConfig>> configFilter;
-
     @Inject
     private BeanManager beanManager;
 
@@ -53,25 +47,25 @@ public class ConfigProducer
     @ApplicationScoped
     public Set<CodiConfig> createCodiConfig()
     {
-        if(configInitialized == null)
+        ClassLoader classLoader = getClassLoader();
+
+        if(!isConfigInitialized(classLoader))
         {
-            initConfig();
+            initConfig(classLoader);
         }
-        return Collections.unmodifiableSet(configSet);
+        return Collections.unmodifiableSet(getCodiConfig(classLoader));
     }
 
-    private synchronized void initConfig()
+    private synchronized void initConfig(ClassLoader classLoader)
     {
-        if(configInitialized != null)
+        if(isConfigInitialized(classLoader))
         {
             return; //paranoid mode
         }
 
-        createConfigFilter();
-
-        createConfig();
+        createConfig(classLoader);
 
-        configInitialized = true;
+        setConfigInitialized(classLoader);
     }
 
     @Produces
@@ -117,29 +111,11 @@ public class ConfigProducer
         };
     }
 
-    private void createConfigFilter()
-    {
-        Set<? extends Bean> deactivatedConfigBeans = this.beanManager.getBeans(DeactivatedCodiConfig.class);
-
-        configFilter = new HashSet<Class<? extends CodiConfig>>(deactivatedConfigBeans.size());
-
-        CreationalContext<DeactivatedCodiConfig> creationalContext;
-        Class<? extends CodiConfig>[] filteredCodiConfigClasses;
-        for(Bean<DeactivatedCodiConfig> deactivatedConfigBean : deactivatedConfigBeans)
-        {
-            creationalContext = this.beanManager.createCreationalContext(deactivatedConfigBean);
-
-            filteredCodiConfigClasses = deactivatedConfigBean.create(creationalContext).getDeactivatedConfigs();
-
-            configFilter.addAll(Arrays.asList(filteredCodiConfigClasses));
-        }
-    }
-
-    private void createConfig()
+    private void createConfig(ClassLoader classLoader)
     {
         Set<? extends Bean> configBeans = this.beanManager.getBeans(CodiConfig.class);
 
-        configSet = new HashSet<CodiConfig>(configBeans.size());
+        initConfigCache(configBeans.size(), classLoader);
 
         CreationalContext<CodiConfig> creationalContext;
         CodiConfig currentCodiConfig;
@@ -149,10 +125,15 @@ public class ConfigProducer
 
             currentCodiConfig = codiConfigBean.create(creationalContext);
 
-            if(!configFilter.contains(currentCodiConfig.getClass()))
+            if(ClassDeactivation.isClassActivated(currentCodiConfig.getClass()))
             {
-                configSet.add(currentCodiConfig);
+                addCodiConfig(currentCodiConfig, classLoader);
             }
         }
     }
+
+    private static ClassLoader getClassLoader()
+    {
+        return ClassUtils.getClassLoader(null);
+    }
 }

Added: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/config/ConfigStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/config/ConfigStorage.java?rev=1004052&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/config/ConfigStorage.java
(added)
+++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/config/ConfigStorage.java
Sun Oct  3 21:35:02 2010
@@ -0,0 +1,67 @@
+/*
+ * 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.myfaces.extensions.cdi.core.impl.config;
+
+import org.apache.myfaces.extensions.cdi.core.api.config.CodiConfig;
+
+import java.util.Set;
+import java.util.Map;
+import java.util.HashSet;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * TODO add test-cases and refactor afterwards
+ *
+ * @author Gerhard Petracek
+ */
+class ConfigStorage
+{
+    private static Map<ClassLoader, Boolean> configInitialized =
+            new ConcurrentHashMap<ClassLoader, Boolean>();
+
+    private static Map<ClassLoader, Set<CodiConfig>> configSetCache =
+            new ConcurrentHashMap<ClassLoader, Set<CodiConfig>>();
+
+    static Set<CodiConfig> getCodiConfig(ClassLoader classLoader)
+    {
+        return configSetCache.get(classLoader);
+    }
+
+    static synchronized boolean isConfigInitialized(ClassLoader classLoader)
+    {
+        Boolean initializedMarker = configInitialized.get(classLoader);
+        return initializedMarker != null;
+    }
+
+    static void setConfigInitialized(ClassLoader classLoader)
+    {
+        configInitialized.put(classLoader, Boolean.TRUE);
+    }
+
+    static void initConfigCache(int size, ClassLoader classLoader)
+    {
+        configSetCache.put(classLoader, new HashSet<CodiConfig>(size));
+    }
+
+    static void addCodiConfig(CodiConfig currentCodiConfig, ClassLoader classLoader)
+    {
+        Set<CodiConfig> codiConfig = configSetCache.get(classLoader);
+        codiConfig.add(currentCodiConfig);
+    }
+}

Modified: myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/utils/ApplicationCache.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/utils/ApplicationCache.java?rev=1004052&r1=1004051&r2=1004052&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/utils/ApplicationCache.java
(original)
+++ myfaces/extensions/cdi/trunk/core/impl/src/main/java/org/apache/myfaces/extensions/cdi/core/impl/utils/ApplicationCache.java
Sun Oct  3 21:35:02 2010
@@ -19,6 +19,8 @@
 package org.apache.myfaces.extensions.cdi.core.impl.utils;
 
 import org.apache.myfaces.extensions.cdi.core.api.config.CodiConfig;
+import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils;
+
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
@@ -27,22 +29,45 @@ import java.util.concurrent.ConcurrentHa
  */
 public class ApplicationCache
 {
-    private static Map<Class<? extends CodiConfig>, CodiConfig> configCache
-            = new ConcurrentHashMap<Class<? extends CodiConfig>, CodiConfig>();
+    private static Map<ClassLoader, Map<Class<? extends CodiConfig>, CodiConfig>>
configCache
+            = new ConcurrentHashMap<ClassLoader, Map<Class<? extends CodiConfig>,
CodiConfig>>();
 
-    public static CodiConfig getConfig(Class<? extends CodiConfig> config)
+    public static CodiConfig getConfig(Class<? extends CodiConfig> configKey)
     {
-        return configCache.get(config);
+        Map<Class<? extends CodiConfig>, CodiConfig> config = configCache.get(getClassLoader());
+
+        if(config == null)
+        {
+            return null;
+        }
+        return config.get(configKey);
     }
 
     public static void setConfig(Class<? extends CodiConfig> configKey, CodiConfig
config)
     {
-        configCache.put(configKey, config);
+        Map<Class<? extends CodiConfig>, CodiConfig> configMap = configCache.get(getClassLoader());
+
+        if(configMap == null)
+        {
+            configMap = new ConcurrentHashMap<Class<? extends CodiConfig>, CodiConfig>();
+            configCache.put(getClassLoader(), configMap);
+        }
+        configMap.put(configKey, config);
     }
 
     @SuppressWarnings({"UnusedDeclaration"})
     public static void resetConfigs()
     {
-        configCache.clear();
+        Map<Class<? extends CodiConfig>, CodiConfig> configMap = configCache.get(getClassLoader());
+
+        if(configMap != null)
+        {
+            configMap.clear();
+        }
+    }
+
+    private static ClassLoader getClassLoader()
+    {
+        return ClassUtils.getClassLoader(null);
     }
 }

Modified: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/CdiAwareBeanValidationProducer.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/CdiAwareBeanValidationProducer.java?rev=1004052&r1=1004051&r2=1004052&view=diff
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/CdiAwareBeanValidationProducer.java
(original)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/CdiAwareBeanValidationProducer.java
Sun Oct  3 21:35:02 2010
@@ -26,7 +26,6 @@ import static org.apache.myfaces.extensi
 import javax.enterprise.context.Dependent;
 import javax.enterprise.inject.Produces;
 import javax.validation.ConstraintValidatorFactory;
-import javax.validation.Validation;
 import javax.validation.Validator;
 import javax.validation.ValidatorFactory;
 import javax.validation.MessageInterpolator;
@@ -37,8 +36,6 @@ import javax.inject.Named;
  */
 public class CdiAwareBeanValidationProducer
 {
-    private static ValidatorFactory defaultValidatorFactory;
-
     protected CdiAwareBeanValidationProducer()
     {
     }
@@ -53,11 +50,7 @@ public class CdiAwareBeanValidationProdu
         ValidatorFactory validatorFactory = validatorFactoryResolver.resolve();
         if (validatorFactory == null)
         {
-            if (defaultValidatorFactory == null)
-            {
-                defaultValidatorFactory = Validation.buildDefaultValidatorFactory();
-            }
-            validatorFactory = defaultValidatorFactory;
+            validatorFactory = ValidatorFactoryStorage.getOrCreateValidatorFactory();
         }
 
         return new CdiAwareValidatorFactory(validatorFactory);

Added: myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/ValidatorFactoryStorage.java
URL: http://svn.apache.org/viewvc/myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/ValidatorFactoryStorage.java?rev=1004052&view=auto
==============================================================================
--- myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/ValidatorFactoryStorage.java
(added)
+++ myfaces/extensions/cdi/trunk/jee-modules/bv-module/impl/src/main/java/org/apache/myfaces/extensions/cdi/bv/impl/ValidatorFactoryStorage.java
Sun Oct  3 21:35:02 2010
@@ -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.myfaces.extensions.cdi.bv.impl;
+
+import org.apache.myfaces.extensions.cdi.core.api.util.ClassUtils;
+
+import javax.validation.ValidatorFactory;
+import javax.validation.Validation;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * @author Gerhard Petracek
+ */
+class ValidatorFactoryStorage
+{
+    private static Map<ClassLoader, ValidatorFactory> defaultValidatorFactoryCache
+            = new ConcurrentHashMap<ClassLoader, ValidatorFactory>();
+
+    static ValidatorFactory getOrCreateValidatorFactory()
+    {
+        ClassLoader classLoader = getClassLoader();
+        ValidatorFactory defaultValidatorFactory = defaultValidatorFactoryCache.get(classLoader);
+
+        if (defaultValidatorFactory == null)
+        {
+            defaultValidatorFactory = Validation.buildDefaultValidatorFactory();
+            defaultValidatorFactoryCache.put(classLoader, defaultValidatorFactory);
+        }
+
+        return defaultValidatorFactory;
+    }
+
+    private static ClassLoader getClassLoader()
+    {
+        return ClassUtils.getClassLoader(null);
+    }
+}



Mime
View raw message