@@ -138,7 +138,7 @@ public class ComponentRegistry
138138 public ComponentRegistry (final ScrConfiguration scrConfiguration , final ScrLogger logger , final ScheduledExecutorService componentActor )
139139 {
140140 m_configuration = scrConfiguration ;
141- m_updateChangeCountPropertyTask = new UpdateChangeCountProperty (m_configuration .serviceChangecountTimeout ());
141+ m_updateChangeCountPropertyTask = new UpdateChangeCountProperty (m_configuration .serviceChangecountTimeout (), logger , componentActor );
142142 m_logger = logger ;
143143 m_componentActor = componentActor ;
144144 m_componentHoldersByName = new HashMap <>();
@@ -708,38 +708,43 @@ public void unregisterRegionConfigurationSupport(
708708
709709 }
710710
711- private final AtomicLong changeCount = new AtomicLong ();
712-
713- public Dictionary <String , Object > getServiceRegistrationProperties ()
711+ Dictionary <String , Object > getServiceRegistrationProperties ()
714712 {
715- final Dictionary <String , Object > props = new Hashtable <>();
716- props .put (PROP_CHANGECOUNT , this .changeCount .get ());
717-
718- return props ;
713+ return m_updateChangeCountPropertyTask .getServiceRegistrationProperties ();
719714 }
720715
721- public void setRegistration (final ServiceRegistration <ServiceComponentRuntime > reg )
716+ public void setRegistration (final ServiceRegistration <ServiceComponentRuntime > reg )
722717 {
723718 m_updateChangeCountPropertyTask .setRegistration (reg );
724719 m_updateChangeCountPropertyTask .schedule ();
725720 }
726721
727- class UpdateChangeCountProperty implements Runnable {
728- // TODO Is 100 ms an appropriate minimum?
729- private static final long MIN_ALLOWED_DELAY = 100 ;
722+ public void updateChangeCount ()
723+ {
724+ m_updateChangeCountPropertyTask .updateChangeCount ();
725+ }
726+
727+ static class UpdateChangeCountProperty implements Runnable {
728+ // TODO 1 seems really low?
729+ private static final long MIN_ALLOWED_DELAY = 1 ;
730+ private final AtomicLong changeCount = new AtomicLong ();
730731 private volatile ServiceRegistration <ServiceComponentRuntime > registration ;
731732 private final long maxNumberOfNoChanges ;
732733 private final long delay ;
734+ private final ScrLogger logger ;
735+ private final ScheduledExecutorService executor ;
733736
734737 // guarded by this
735738 private int noChangesCount = 0 ;
736739 // guarded by this
737740 private ScheduledFuture <?> scheduledFuture = null ;
738741
739- public UpdateChangeCountProperty (long delay )
742+ UpdateChangeCountProperty (long delay , ScrLogger logger , ScheduledExecutorService executor )
740743 {
744+ this .logger = logger ;
745+ this .executor = executor ;
741746 if (delay < MIN_ALLOWED_DELAY ) {
742- m_logger .log (Level .INFO ,
747+ logger .log (Level .INFO ,
743748 "The service change count timeout {0} is less than the allowable minimum {1}. Using the allowable minimum instead." , null ,
744749 delay , MIN_ALLOWED_DELAY );
745750 delay = MIN_ALLOWED_DELAY ;
@@ -750,19 +755,31 @@ public UpdateChangeCountProperty(long delay)
750755 maxNumberOfNoChanges = Long .max (10000 / delay , 1 );
751756 }
752757
753- public void setRegistration (ServiceRegistration <ServiceComponentRuntime > reg )
758+ void setRegistration (ServiceRegistration <ServiceComponentRuntime > reg )
754759 {
755760 this .registration = reg ;
756761 }
757762
758- public synchronized void schedule ()
763+ Dictionary <String , Object > getServiceRegistrationProperties ()
764+ {
765+ final Dictionary <String , Object > props = new Hashtable <>();
766+ props .put (PROP_CHANGECOUNT , this .changeCount .get ());
767+
768+ return props ;
769+ }
770+
771+ public void updateChangeCount () {
772+ this .changeCount .incrementAndGet ();
773+ schedule ();
774+ }
775+ synchronized void schedule ()
759776 {
760777 // reset noChangesCount to ensure task runs at least once more if it exists
761778 noChangesCount = 0 ;
762779 if (scheduledFuture != null ) {
763780 return ;
764781 }
765- scheduledFuture = m_componentActor .scheduleWithFixedDelay (this , delay , delay , TimeUnit .MILLISECONDS );
782+ scheduledFuture = executor .scheduleWithFixedDelay (this , delay , delay , TimeUnit .MILLISECONDS );
766783 }
767784
768785 @ Override
@@ -802,16 +819,10 @@ public void run()
802819 }
803820 }
804821 } catch (Exception e ) {
805- m_logger .log (Level .WARN ,
822+ logger .log (Level .WARN ,
806823 "Service changecount update for {0} had a problem" , e ,
807824 registration .getReference ());
808825 }
809826 }
810827 }
811-
812- public void updateChangeCount ()
813- {
814- this .changeCount .incrementAndGet ();
815- m_updateChangeCountPropertyTask .schedule ();
816- }
817828}
0 commit comments