openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1825376 - in /openwebbeans/trunk/webbeans-impl/src: main/java/org/apache/webbeans/config/ main/java/org/apache/webbeans/intercept/ main/java/org/apache/webbeans/util/ test/java/org/apache/webbeans/test/config/ test/resources/org/apache/web...
Date Mon, 26 Feb 2018 14:24:16 GMT
Author: rmannibucau
Date: Mon Feb 26 14:24:15 2018
New Revision: 1825376

URL: http://svn.apache.org/viewvc?rev=1825376&view=rev
Log:
OWB-1232 reducing the log level of 'interceptor already defined' to FINE and log when possible
the priority

Added:
    openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/config/BeansDeployerTest.java
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/config/BeansDeployerTest/
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/config/BeansDeployerTest/interceptorLogging/
    openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/config/BeansDeployerTest/interceptorLogging/beans.xml
Modified:
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
    openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClasses.java

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java?rev=1825376&r1=1825375&r2=1825376&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/BeansDeployer.java
Mon Feb 26 14:24:15 2018
@@ -1754,7 +1754,13 @@ public class BeansDeployer
                 if ((!isBDAScanningEnabled && interceptorsManager.isInterceptorClassEnabled(clazz))
||
                         (isBDAScanningEnabled && !scannerService.getBDABeansXmlScanner().addInterceptor(clazz,
bdaLocation.toExternalForm())))
                 {
-                    logger.warning( "Interceptor class : " + interceptor + " is already defined");
+                    int priority = -1;
+                    if (!isBDAScanningEnabled)
+                    {
+                        priority = interceptorsManager.getPriority(clazz);
+                    }
+                    logger.fine( "Interceptor class : " + interceptor + " is already defined"
+
+                            (priority >= 0 ? " with priority " + priority : ""));
                 }
                 else
                 {

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java?rev=1825376&r1=1825375&r2=1825376&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/intercept/InterceptorsManager.java
Mon Feb 26 14:24:15 2018
@@ -354,6 +354,11 @@ public class InterceptorsManager
         }
     }
 
+    public int getPriority(final Class<?> type)
+    {
+        return priorityInterceptors.getPriority(type).orElseGet(() -> getPrioritizedInterceptors().indexOf(type));
+    }
+
     public List<Class<?>> getPrioritizedInterceptors()
     {
         return priorityInterceptors.getSorted();

Modified: openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClasses.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClasses.java?rev=1825376&r1=1825375&r2=1825376&view=diff
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClasses.java
(original)
+++ openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/PriorityClasses.java
Mon Feb 26 14:24:15 2018
@@ -22,6 +22,7 @@ import javax.annotation.Priority;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
+import java.util.OptionalInt;
 
 public class PriorityClasses
 {
@@ -34,6 +35,11 @@ public class PriorityClasses
     private final List<PriorityClass> raw = new ArrayList<>();
     private List<Class<?>> sorted;
 
+    public OptionalInt getPriority(final Class<?> type)
+    {
+        return raw.stream().filter(it -> it.getClazz() == type).mapToInt(PriorityClass::getPriority).findFirst();
+    }
+
     /**
      * Used for Classes which are annotated with &#064;Priority
      */

Added: openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/config/BeansDeployerTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/config/BeansDeployerTest.java?rev=1825376&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/config/BeansDeployerTest.java
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/java/org/apache/webbeans/test/config/BeansDeployerTest.java
Mon Feb 26 14:24:15 2018
@@ -0,0 +1,120 @@
+/*
+ * 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.webbeans.test.config;
+
+import static java.util.Collections.singletonList;
+import static java.util.logging.Level.FINE;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
+
+import javax.annotation.Priority;
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.Interceptor;
+import javax.interceptor.InvocationContext;
+
+import org.apache.webbeans.config.BeansDeployer;
+import org.apache.webbeans.test.AbstractUnitTest;
+import org.apache.webbeans.test.component.intercept.webbeans.bindings.Transactional;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TestName;
+
+public class BeansDeployerTest extends AbstractUnitTest
+{
+    @Rule
+    public final TestName testName = new TestName();
+
+    @Test
+    public void interceptorLogging()
+    {
+        final Logger logger = Logger.getLogger(BeansDeployer.class.getName());
+        final Level originalLevel = logger.getLevel();
+        logger.setLevel(FINE);
+        final Collection<LogRecord> records = new ArrayList<>();
+        final Handler testHandler = new Handler()
+        {
+            {
+                setLevel(FINE);
+            }
+
+            @Override
+            public void publish(final LogRecord record)
+            {
+                if (!record.getMessage().contains("Interceptor"))
+                {
+                    return;
+                }
+                synchronized (records)
+                {
+                    records.add(record);
+                }
+            }
+
+            @Override
+            public void flush()
+            {
+                // no-op
+            }
+
+            @Override
+            public void close() throws SecurityException
+            {
+                // no-op
+            }
+        };
+        logger.addHandler(testHandler);
+        try
+        {
+            startContainer(singletonList(TransactionalInterceptor.class),
+                    singletonList(Thread.currentThread().getContextClassLoader()
+                            .getResource(getClass().getName().replace('.', '/') + '/' + testName.getMethodName()
+ "/beans.xml")
+                            .toExternalForm()));
+        }
+        finally
+        {
+            logger.removeHandler(testHandler);
+            logger.setLevel(originalLevel);
+        }
+        assertTrue( records.size() >= 1);
+        final LogRecord record = records.iterator().next();
+        assertEquals(Level.FINE, record.getLevel());
+        assertEquals("Interceptor class : " + TransactionalInterceptor.class.getName() +
+                " is already defined with priority 1000", record.getMessage());
+    }
+
+    @Interceptor
+    @Transactional
+    @Priority(Interceptor.Priority.LIBRARY_BEFORE)
+    public static class TransactionalInterceptor implements Serializable
+    {
+        @AroundInvoke
+        public Object caller(final InvocationContext context) throws Exception
+        {
+            return null;
+        }
+    }
+}

Added: openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/config/BeansDeployerTest/interceptorLogging/beans.xml
URL: http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/config/BeansDeployerTest/interceptorLogging/beans.xml?rev=1825376&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/config/BeansDeployerTest/interceptorLogging/beans.xml
(added)
+++ openwebbeans/trunk/webbeans-impl/src/test/resources/org/apache/webbeans/test/config/BeansDeployerTest/interceptorLogging/beans.xml
Mon Feb 26 14:24:15 2018
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<beans version="2.0" bean-discovery-mode="all">
+  <interceptors>
+    <class>org.apache.webbeans.test.config.BeansDeployerTest$TransactionalInterceptor</class>
+  </interceptors>
+</beans>



Mime
View raw message