Permalink
Browse files

introducing two additional awaitStability methods + reordering Stabil…

…ityMonitor methods to be paired properly
  • Loading branch information...
ropalka committed Jan 10, 2013
1 parent f2f06cd commit 385cadbf73e90c218dbb67cd713a2821071a083c
@@ -205,6 +205,18 @@ public void awaitTermination(long timeout, TimeUnit unit) throws InterruptedExce
throw new UnsupportedOperationException();
}
+ /** {@inheritDoc} */
+ @Override
+ public void awaitStability() throws InterruptedException {
+ throw new UnsupportedOperationException();
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public boolean awaitStability(final long timeout, final TimeUnit unit) throws InterruptedException {
+ throw new UnsupportedOperationException();
+ }
+
/** {@inheritDoc} */
@Override
public void awaitStability(final Set<? super ServiceController<?>> failed, final Set<? super ServiceController<?>> problem) throws InterruptedException {
@@ -74,8 +74,28 @@
/**
* Causes the current thread to wait until the container is stable.
*
- * @param failed a set into which failed services should be copied, or {@code null} to ignore
- * @param problem a set into which problem services should be copied, or {@code null} to ignore
+ * @throws InterruptedException if the current thread is interrupted
+ * while waiting
+ */
+ void awaitStability() throws InterruptedException;
+
+ /**
+ * Causes the current thread to wait until the container is stable.
+ *
+ * @param timeout the maximum time to wait
+ * @param unit the time unit of the {@code timeout} argument
+ * @return <tt>true</tt> if this container achieved stability,
+ * <tt>false</tt> if the timeout elapsed before stability
+ * @throws InterruptedException if the current thread is interrupted
+ * while waiting
+ */
+ boolean awaitStability(long timeout, TimeUnit unit) throws InterruptedException;
+
+ /**
+ * Causes the current thread to wait until the container is stable.
+ *
+ * @param failed a set into which failed services should be copied
+ * @param problem a set into which problem services should be copied
* @throws InterruptedException if the current thread is interrupted
* while waiting
*/
@@ -86,8 +106,10 @@
*
* @param timeout the maximum time to wait
* @param unit the time unit of the {@code timeout} argument
- * @param failed a set into which failed services should be copied, or {@code null} to ignore
- * @param problem a set into which problem services should be copied, or {@code null} to ignore
+ * @param failed a set into which failed services should be copied
+ * @param problem a set into which problem services should be copied
+ * @return <tt>true</tt> if this container achieved stability,
+ * <tt>false</tt> if the timeout elapsed before stability
* @throws InterruptedException if the current thread is interrupted
* while waiting
*/
@@ -376,6 +376,16 @@ public void awaitTermination(long timeout, TimeUnit unit) throws InterruptedExce
listener.await(timeout, unit);
}
+ @Override
+ public void awaitStability() throws InterruptedException {
+ awaitStability(null, null);
+ }
+
+ @Override
+ public boolean awaitStability(final long timeout, final TimeUnit unit) throws InterruptedException {
+ return awaitStability(timeout, unit, null, null);
+ }
+
@Override
public void awaitStability(Set<? super ServiceController<?>> failed, Set<? super ServiceController<?>> problem) throws InterruptedException {
synchronized (lock) {
@@ -51,8 +51,16 @@ public void removeController(final ServiceController<?> controller) {
final ServiceControllerImpl<?> serviceController = (ServiceControllerImpl<?>) controller;
serviceController.removeMonitor(this);
}
+
+ public void awaitStability() throws InterruptedException {
+ awaitStability(null, null);
+ }
+
+ public boolean awaitStability(final long timeout, final TimeUnit unit) throws InterruptedException {
+ return awaitStability(timeout, unit, null, null);
+ }
- public void awaitStability(Set<? super ServiceController<?>> failed, Set<? super ServiceController<?>> problem) throws InterruptedException {
+ public void awaitStability(final Set<? super ServiceController<?>> failed, final Set<? super ServiceController<?>> problem) throws InterruptedException {
synchronized (lock) {
while (unstableServices != 0) {
lock.wait();
@@ -66,7 +74,7 @@ public void awaitStability(Set<? super ServiceController<?>> failed, Set<? super
}
}
- public boolean awaitStability(final long timeout, final TimeUnit unit, Set<? super ServiceController<?>> failed, Set<? super ServiceController<?>> problem) throws InterruptedException {
+ public boolean awaitStability(final long timeout, final TimeUnit unit, final Set<? super ServiceController<?>> failed, final Set<? super ServiceController<?>> problem) throws InterruptedException {
long now = System.nanoTime();
long remaining = unit.toNanos(timeout);
synchronized (lock) {
@@ -87,37 +95,37 @@ public boolean awaitStability(final long timeout, final TimeUnit unit, Set<? sup
}
}
- void removeProblem(ServiceController<?> controller) {
+ void addProblem(final ServiceController<?> controller) {
assert holdsLock(controller);
synchronized (lock) {
- problems.remove(controller);
+ problems.add(controller);
}
}
- void removeFailed(ServiceController<?> controller) {
+ void removeProblem(final ServiceController<?> controller) {
assert holdsLock(controller);
synchronized (lock) {
- failed.remove(controller);
+ problems.remove(controller);
}
}
- void incrementUnstableServices() {
+ void addFailed(final ServiceController<?> controller) {
+ assert holdsLock(controller);
synchronized (lock) {
- unstableServices++;
+ failed.add(controller);
}
}
- void addProblem(ServiceController<?> controller) {
+ void removeFailed(final ServiceController<?> controller) {
assert holdsLock(controller);
synchronized (lock) {
- problems.add(controller);
+ failed.remove(controller);
}
}
- void addFailed(ServiceController<?> controller) {
- assert holdsLock(controller);
+ void incrementUnstableServices() {
synchronized (lock) {
- failed.add(controller);
+ unstableServices++;
}
}

0 comments on commit 385cadb

Please sign in to comment.