glimmerveen commented on code in PR #486:
URL: https://github.com/apache/felix-dev/pull/486#discussion_r2984398593


##########
scr/src/main/java/org/apache/felix/scr/impl/ComponentRegistry.java:
##########
@@ -718,42 +720,84 @@ public Dictionary<String, Object> 
getServiceRegistrationProperties()
 
     public void setRegistration(final 
ServiceRegistration<ServiceComponentRuntime> reg)
     {
-        this.registration = reg;
+        m_updateChangeCountPropertyTask.setRegistration(reg);
+        m_updateChangeCountPropertyTask.schedule();
     }
 
-    public void updateChangeCount()
-    {
-        if ( registration != null )
+    class UpdateChangeCountProperty implements Runnable {
+        private volatile ServiceRegistration<ServiceComponentRuntime> 
registration;
+        private final long maxNumberOfNoChanges;
+        private final long delay;
+
+        // guarded by this
+        private int noChangesCount = 0;
+        // guarded by this
+        private ScheduledFuture<?> scheduledFuture = null;
+
+        public UpdateChangeCountProperty(long delay)
         {
-            final long count = this.changeCount.incrementAndGet();
+            this.delay = delay;
+            // calculate the max number of no changes; must be at least 1 to 
avoid missing events
+            maxNumberOfNoChanges = Long.max(10000 / delay, 1);
+        }
 
-            try
-            {
-                m_componentActor.schedule(new Runnable()
-                    {
+        public void 
setRegistration(ServiceRegistration<ServiceComponentRuntime> reg)
+        {
+            this.registration = reg;
+        }
 
-                        @Override
-                        public void run()
-                        {
-                            if ( changeCount.get() == count )
-                            {
-                                try
-                                {
-                                    
registration.setProperties(getServiceRegistrationProperties());
-                                }
-                                catch ( final IllegalStateException ise)
-                                {
-                                    // we ignore this as this might happen on 
shutdown
-                                }
+        public synchronized void schedule()
+        {
+            // reset noChangesCount to ensure task runs at least once more if 
it exists
+            noChangesCount = 0;
+            if (scheduledFuture != null) {
+                return;
+            }
+            scheduledFuture = m_componentActor.scheduleWithFixedDelay(this , 
delay, delay, TimeUnit.MILLISECONDS);
+        }
+
+        @Override
+        public void run()
+        {
+            ServiceRegistration<ServiceComponentRuntime> currentReg = 
registration;
+            if (currentReg == null) {
+                return;
+            }
+            try {
+                Long registeredChangeCount = (Long) 
currentReg.getReference().getProperty(PROP_CHANGECOUNT);

Review Comment:
   I think getReference, just like setProperties, can throw an 
IllegalStateException. Should that also not be ignored, currently it will end 
up in the catch block where it is logged as a warning.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to