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 2017/02/22 06:58:41 UTC

svn commit: r1783971 - in /felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal: service/HttpServiceRuntimeImpl.java whiteboard/WhiteboardManager.java

Author: cziegeler
Date: Wed Feb 22 06:58:41 2017
New Revision: 1783971

URL: http://svn.apache.org/viewvc?rev=1783971&view=rev
Log:
FELIX-5560 : Add change count property to runtime service

Modified:
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceRuntimeImpl.java
    felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceRuntimeImpl.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceRuntimeImpl.java?rev=1783971&r1=1783970&r2=1783971&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceRuntimeImpl.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceRuntimeImpl.java Wed Feb 22 06:58:41 2017
@@ -20,25 +20,39 @@ import static java.util.Collections.list
 
 import java.util.Dictionary;
 import java.util.Hashtable;
+import java.util.Timer;
+import java.util.TimerTask;
 
 import org.apache.felix.http.base.internal.registry.HandlerRegistry;
 import org.apache.felix.http.base.internal.runtime.dto.RequestInfoDTOBuilder;
 import org.apache.felix.http.base.internal.runtime.dto.RuntimeDTOBuilder;
 import org.apache.felix.http.base.internal.whiteboard.WhiteboardManager;
 import org.osgi.framework.ServiceReference;
+import org.osgi.framework.ServiceRegistration;
 import org.osgi.service.http.runtime.HttpServiceRuntime;
 import org.osgi.service.http.runtime.dto.RequestInfoDTO;
 import org.osgi.service.http.runtime.dto.RuntimeDTO;
 
 public final class HttpServiceRuntimeImpl implements HttpServiceRuntime
 {
+    /**
+     * Service property for change count. This constant is defined here to avoid
+     * a dependency on R7 of the framework.
+     * The value of the property is of type {@code Long}.
+     */
+    private static String PROP_CHANGECOUNT = "service.changecount";
+
     private volatile Hashtable<String, Object> attributes = new Hashtable<String, Object>();
 
     private final HandlerRegistry registry;
     private final WhiteboardManager contextManager;
 
+    private volatile long changeCount;
+
     private volatile ServiceReference<HttpServiceRuntime> serviceReference;
 
+    private volatile Timer timer;
+
     public HttpServiceRuntimeImpl(HandlerRegistry registry,
             WhiteboardManager contextManager)
     {
@@ -74,6 +88,7 @@ public final class HttpServiceRuntimeImp
         {
             replacement.put(key, newAttributes.get(key));
         }
+        replacement.put(PROP_CHANGECOUNT, this.changeCount);
         attributes = replacement;
     }
 
@@ -87,4 +102,37 @@ public final class HttpServiceRuntimeImp
     {
         this.serviceReference = reference;
     }
+
+    public void updateChangeCount(final ServiceRegistration<HttpServiceRuntime> reg)
+    {
+        if ( reg != null )
+        {
+            final long count;
+            synchronized ( this )
+            {
+                count = this.changeCount++;
+                this.setAttribute(PROP_CHANGECOUNT, this.changeCount);
+                if ( this.timer == null )
+                {
+                    this.timer = new Timer();
+                }
+            }
+            timer.schedule(new TimerTask()
+            {
+
+                @Override
+                public void run() {
+                    synchronized ( HttpServiceRuntimeImpl.this )
+                    {
+                        if ( changeCount == count )
+                        {
+                            reg.setProperties(getAttributes());
+                            timer.cancel();
+                            timer = null;
+                        }
+                    }
+                }
+            }, 2000L);
+        }
+    }
 }

Modified: felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java
URL: http://svn.apache.org/viewvc/felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java?rev=1783971&r1=1783970&r2=1783971&view=diff
==============================================================================
--- felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java (original)
+++ felix/trunk/http/base/src/main/java/org/apache/felix/http/base/internal/whiteboard/WhiteboardManager.java Wed Feb 22 06:58:41 2017
@@ -451,6 +451,7 @@ public final class WhiteboardManager
             {
                 this.failureStateHandler.addFailure(info, FAILURE_REASON_VALIDATION_FAILED);
             }
+            updateRuntimeChangeCount();
             return true;
         }
         return false;
@@ -518,6 +519,7 @@ public final class WhiteboardManager
             }
         }
         this.failureStateHandler.removeAll(info);
+        updateRuntimeChangeCount();
     }
 
     /**
@@ -643,6 +645,7 @@ public final class WhiteboardManager
             {
                 this.failureStateHandler.addFailure(info, FAILURE_REASON_VALIDATION_FAILED);
             }
+            updateRuntimeChangeCount();
             return true;
         }
         return false;
@@ -728,6 +731,7 @@ public final class WhiteboardManager
             }
             this.failureStateHandler.removeAll(info);
         }
+        updateRuntimeChangeCount();
     }
 
     /**
@@ -963,12 +967,12 @@ public final class WhiteboardManager
             return true;
         }
         final AtomicBoolean result = new AtomicBoolean(true);
-        final FilterChain chain = new FilterChain() 
+        final FilterChain chain = new FilterChain()
         {
 
             @Override
             public void doFilter(final ServletRequest request, final ServletResponse response)
-            throws IOException, ServletException 
+            throws IOException, ServletException
             {
                 result.set(true);
             }
@@ -984,4 +988,9 @@ public final class WhiteboardManager
         }
         return result.get();
     }
+
+    private void updateRuntimeChangeCount()
+    {
+        this.serviceRuntime.updateChangeCount(this.runtimeServiceReg);
+    }
 }