You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@felix.apache.org by cz...@apache.org on 2022/07/25 05:48:42 UTC

[felix-dev] branch master updated: FELIX-6551 : Simplify logging, use atomic boolean for denied flag

This is an automated email from the ASF dual-hosted git repository.

cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git


The following commit(s) were added to refs/heads/master by this push:
     new cb553d57b9 FELIX-6551 : Simplify logging, use atomic boolean for denied flag
cb553d57b9 is described below

commit cb553d57b95f1e6d4492e31291f919be52f825c8
Author: Carsten Ziegeler <cz...@apache.org>
AuthorDate: Mon Jul 25 07:48:37 2022 +0200

    FELIX-6551 : Simplify logging, use atomic boolean for denied flag
---
 .../eventadmin/impl/handler/EventHandlerProxy.java | 38 ++++++++++------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java
index a62411f58b..9ffe78640a 100644
--- a/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java
+++ b/eventadmin/impl/src/main/java/org/apache/felix/eventadmin/impl/handler/EventHandlerProxy.java
@@ -20,6 +20,7 @@ package org.apache.felix.eventadmin.impl.handler;
 
 import java.util.Collection;
 import java.util.Iterator;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import org.apache.felix.eventadmin.impl.security.PermissionsUtil;
 import org.apache.felix.eventadmin.impl.util.LogWrapper;
@@ -58,7 +59,7 @@ public class EventHandlerProxy {
     private volatile EventHandler handler;
 
     /** Is this handler denied? */
-    private volatile boolean denied;
+    private final AtomicBoolean denied = new AtomicBoolean();
 
     /** Use timeout. */
     private boolean useTimeout;
@@ -85,7 +86,7 @@ public class EventHandlerProxy {
      */
     public boolean update()
     {
-        this.denied = false;
+        this.denied.set(false);
         boolean valid = true;
         // First check, topic
         final Object topicObj = reference.getProperty(EventConstants.EVENT_TOPIC);
@@ -345,7 +346,7 @@ public class EventHandlerProxy {
      */
     public boolean canDeliver(final Event event)
     {
-        if ( this.denied )
+        if ( this.denied.get() )
         {
             return false;
         }
@@ -435,10 +436,9 @@ public class EventHandlerProxy {
             // The spec says that we must catch exceptions and log them:
             LogWrapper.getLogger().log(
                             this.reference,
-                            LogWrapper.LOG_WARNING,
-                            "Exception during event dispatch [" + event + " | "
-                                            + this.reference + " | Bundle("
-                                            + this.reference.getBundle() + ")]", e);
+                            LogWrapper.LOG_ERROR,
+                            String.format("Exception during event dispatch [%s | %s | Bundle(%s) | Handler(%s)]", 
+                                event, this.reference, this.reference.getBundle(), handlerService), e);
         }
     }
 
@@ -447,23 +447,21 @@ public class EventHandlerProxy {
      */
     public void denyEventHandler()
     {
-    	if(!this.denied)
-    	{
-            String output = this.reference + " | Bundle(" + this.reference.getBundle() + ")";
-            if(this.handler != null){
-                output += " | Handler(" + this.handler.getClass().getCanonicalName() + ")";
-            }
-
+        if ( this.denied.compareAndSet(false, true) ) {
+            final EventHandler handlerService = this.handler;
             LogWrapper.getLogger().log(
                     LogWrapper.LOG_ERROR,
-                    String.format("Denying event handler from ServiceReference [%s] due to timeout!", output));
-	        this.denied = true;
-	        // we can free the handler now.
-	        this.release();
+                    String.format("Denying event handler from ServiceReference [%s | Bundle(%s)%s] due to timeout!",
+                        this.reference,
+                        this.reference.getBundle(),
+                        handlerService == null ? "" : " | Handler(".concat(handlerService.getClass().getName()).concat(")")));
+
+            this.release();
     	}
     }
 
-    public boolean isDenied() {
-        return this.denied;
+    public boolean isDenied()
+    {
+        return this.denied.get();
     }
 }