Skip to content

Commit

Permalink
Addon dependency shutdown is working
Browse files Browse the repository at this point in the history
  • Loading branch information
lincolnthree committed Jan 25, 2013
1 parent d39899e commit dfbb21b
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,33 +136,29 @@ public Future<Addon> start(Addon addon)
public void stop(Addon addon)
{
Assert.notNull(addon, "Addon must not be null.");
AddonImpl addonImpl = (AddonImpl) getRegisteredAddon(addon.getId());
AddonImpl addonToStop = (AddonImpl) getRegisteredAddon(addon.getId());

Set<AddonImpl> stopped = new HashSet<AddonImpl>();
for (AddonImpl dependentAddon : addons)
{
for (AddonDependency dependency : dependentAddon.getDependencies())
{
if (addon.getId().equals(dependency.getId()) && dependentAddon.getFuture() != null)
{
stop(dependentAddon);
stopped.add(dependentAddon);
}
}
}

addons.removeAll(stopped);

synchronized (addons)
{
if (addonImpl != null)
if (addonToStop != null)
{
Future<Addon> future = addonImpl.getFuture();
Future<Addon> future = addonToStop.getFuture();
try
{
if (future != null)
if (future != null && addon.getStatus().isStarted())
{
addonImpl.getRunnable().shutdown();
addonToStop.getRunnable().shutdown();
}
}
catch (Exception e)
Expand All @@ -173,6 +169,8 @@ public void stop(Addon addon)
{
if (future != null && !future.isDone())
future.cancel(true);

addons.remove(addonToStop);
}
}
}
Expand Down Expand Up @@ -234,7 +232,11 @@ public void updateAddons()
toRemove.add(addon);
}
}
addons.removeAll(toRemove);

for (Addon addon : toRemove)
{
stop(addon);
}

for (AddonId entry : enabledCompatible)
{
Expand Down

0 comments on commit dfbb21b

Please sign in to comment.