Skip to content

Commit

Permalink
[MSC-122] various fixes
Browse files Browse the repository at this point in the history
 * use asserts instead of exception throwing
 * fix real regression cause and remove useless 'stable' flag
  • Loading branch information
ropalka authored and dmlloyd committed Jan 3, 2013
1 parent dd6c45e commit 90efcf1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 17 deletions.
Expand Up @@ -332,8 +332,7 @@ void decrementUnstableServices() {
if (--unstableServices == 0) {
lock.notifyAll();
}
// ensure invariant
if (unstableServices < 0) throw new IllegalStateException();
assert unstableServices >= 0;
}
}

Expand Down
25 changes: 12 additions & 13 deletions src/main/java/org/jboss/msc/service/ServiceControllerImpl.java
Expand Up @@ -165,10 +165,6 @@ final class ServiceControllerImpl<S> implements ServiceController<S>, Dependent
* start/stops, and internal tasks.
*/
private int asyncTasks;
/**
* Whether this controller is in stable or unstable state.
*/
private boolean stable = true;
/**
* The service target for adding child services (can be {@code null} if none
* were added).
Expand Down Expand Up @@ -297,14 +293,16 @@ void commitInstallation(Mode initialMode) {
* Roll back the service install.
*/
void rollbackInstallation() {
final boolean stabilityNotification;
synchronized(this) {
stabilityNotification = state != Substate.NEW;
final boolean leavingRestState = isStableRestState();
mode = Mode.REMOVE;
asyncTasks ++;
state = Substate.CANCELLED;
updateStabilityState(leavingRestState);
if (stabilityNotification) updateStabilityState(leavingRestState);
}
(new RemoveTask()).run();
(new RemoveTask(stabilityNotification)).run();
}

/**
Expand Down Expand Up @@ -350,16 +348,14 @@ boolean isStableRestState() {
void updateStabilityState(final boolean leavingStableRestState) {
assert holdsLock(this);
if (leavingStableRestState) {
if (stable && (asyncTasks > 0 || !state.isRestState())) {
stable = false;
if (asyncTasks > 0 || !state.isRestState()) {
primaryRegistration.getContainer().incrementUnstableServices();
for (StabilityMonitor monitor : monitors) {
monitor.incrementUnstableServices();
}
}
} else {
if (state.isRestState() && asyncTasks == 0 && !stable) {
stable = true;
if (state.isRestState() && asyncTasks == 0) {
primaryRegistration.getContainer().decrementUnstableServices();
for (StabilityMonitor monitor : monitors) {
monitor.decrementUnstableServices();
Expand Down Expand Up @@ -675,7 +671,7 @@ void transition(final ArrayList<Runnable> tasks) {
if (failCount > 0) {
tasks.add(new DependencyRetryingTask(dependents));
}
tasks.add(new RemoveTask());
tasks.add(new RemoveTask(true));
break;
}
case REMOVING_to_REMOVED: {
Expand Down Expand Up @@ -2244,8 +2240,11 @@ public void run() {
}

private class RemoveTask implements Runnable {

private final boolean stabilityNotification;

RemoveTask() {
RemoveTask(final boolean stabilityNotification) {
this.stabilityNotification = stabilityNotification;
}

public void run() {
Expand All @@ -2268,7 +2267,7 @@ public void run() {
asyncTasks --;
transition(tasks);
asyncTasks += tasks.size();
updateStabilityState(leavingRestState);
if (stabilityNotification) updateStabilityState(leavingRestState);
}
doExecute(tasks);
} catch (Throwable t) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/org/jboss/msc/service/StabilityMonitor.java
Expand Up @@ -128,8 +128,7 @@ void decrementUnstableServices() {
if (--unstableServices == 0) {
lock.notifyAll();
}
// ensure invariant
if (unstableServices < 0) throw new IllegalStateException();
assert unstableServices >= 0;
}
}
}

0 comments on commit 90efcf1

Please sign in to comment.