Permalink
Browse files

[MSC-127] StabilityMonitors need to track also child services + fixin…

…g StabilityStatistics in tests
  • Loading branch information...
1 parent 33b41b3 commit c0c2727459b185a0a7ccb555b5d347c91be02f4d @ropalka ropalka committed Feb 8, 2013
@@ -193,6 +193,12 @@
this.aliasRegistrations = aliasRegistrations;
this.listeners = new IdentityHashMap<ServiceListener<? super S>, ServiceListener.Inheritance>(listeners);
this.monitors = new IdentityHashSet<StabilityMonitor>(monitors);
+ // We also need to register this controller with monitors explicitly.
+ // This allows inherited monitors to have registered all child controllers
+ // and later to remove them when inherited stability monitor is cleared.
+ for (final StabilityMonitor monitor : monitors) {
+ monitor.addControllerNoCallback(this);
+ }
this.parent = parent;
int depCount = dependencies.length;
unstartedDependencies = 0;
@@ -105,10 +105,21 @@ public void addController(final ServiceController<?> controller) {
if (controller == null) return;
final ServiceControllerImpl<?> serviceController = (ServiceControllerImpl<?>) controller;
synchronized (controllersLock) {
+ controllers.add(serviceController);
// It is safe to call controller.addMonitor() under controllersLock because
// controller.addMonitor() may callback only stabilityLock protected methods.
serviceController.addMonitor(this);
- controllers.add(serviceController);
+ }
+ }
+
+ /**
+ * Register controller with this monitor but don't call serviceController.addMonitor() at all.
+ *
+ * @param controller to be registered for stability detection.
+ */
+ void addControllerNoCallback(final ServiceControllerImpl<?> controller) {
+ synchronized (controllersLock) {
+ controllers.add(controller);
}
}
@@ -145,9 +145,9 @@ public Object getValue() throws IllegalStateException, IllegalArgumentException
assertController(controller2.getName(), controller2);
assertTrue(problem.isEmpty());
assertTrue(failed.isEmpty());
- assertTrue(statistics.getActiveCount() == 1);
+ assertTrue(statistics.getActiveCount() == 2);
assertTrue(statistics.getOnDemandCount() == 1);
- assertTrue(statistics.getStartedCount() == 2);
+ assertTrue(statistics.getStartedCount() == 3);
assertTrue(statistics.getFailedCount() == 0);
assertTrue(statistics.getLazyCount() == 0);
assertTrue(statistics.getNeverCount() == 0);
@@ -215,7 +215,7 @@ public Object getValue() throws IllegalStateException, IllegalArgumentException
assertController(controller2.getName(), controller2);
assertTrue(problem.isEmpty());
assertTrue(failed.size() == 1);
- assertTrue(statistics.getActiveCount() == 1);
+ assertTrue(statistics.getActiveCount() == 2);
assertTrue(statistics.getOnDemandCount() == 1);
assertTrue(statistics.getStartedCount() == 2);
assertTrue(statistics.getFailedCount() == 1);

0 comments on commit c0c2727

Please sign in to comment.