Skip to content

Commit

Permalink
Container is a little more stable. Doesn't re-load already loaded add…
Browse files Browse the repository at this point in the history
…ons.
  • Loading branch information
lincolnthree committed Mar 20, 2013
1 parent ad67f1b commit a435f41
Show file tree
Hide file tree
Showing 9 changed files with 100 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.jboss.forge.container.exception.ContainerException;
import org.jboss.forge.container.impl.AddonRepositoryImpl;
import org.jboss.forge.container.repositories.MutableAddonRepository;
import org.jboss.forge.container.util.Addons;
import org.jboss.forge.container.util.ClassLoaders;
import org.jboss.forge.container.util.Files;
import org.jboss.forge.container.util.Threads;
Expand Down Expand Up @@ -188,8 +189,9 @@ public void undeploy(Archive<?> archive) throws DeploymentException
try
{
repository.disable(addonToUndeploy);
if (registry.isRegistered(addonToUndeploy))
registry.stop(registry.getRegisteredAddon(addonToUndeploy));
Addon registeredAddon = registry.getRegisteredAddon(addonToUndeploy);
registry.stop(registeredAddon);
Addons.waitUntilStopped(registry.getRegisteredAddon(addonToUndeploy));
}
catch (Exception e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public TestResult invoke(final TestMethodExecutor testMethodExecutor)

try
{
System.out.println("Executing test class: "
+ testMethodExecutor.getInstance().getClass().getName());

final String testClassName = testMethodExecutor.getInstance().getClass().getName();
final AddonRegistry addonRegistry = forge.getAddonRegistry();

Expand Down Expand Up @@ -148,7 +151,10 @@ public Object call() throws Exception
{
try
{
System.out.println("Executing test method: " + method);
System.out.println("Executing test method: "
+ testMethodExecutor.getInstance().getClass().getName() + "."
+ testMethodExecutor.getMethod().getName() + "()");

method.invoke(instance);
result = new TestResult(Status.PASSED);
}
Expand Down Expand Up @@ -189,9 +195,11 @@ public Object call() throws Exception
}
catch (Exception e)
{
throw new IllegalStateException("Error launching test "
String message = "Error launching test "
+ testMethodExecutor.getInstance().getClass().getName() + "."
+ testMethodExecutor.getMethod().getName() + "()", e);
+ testMethodExecutor.getMethod().getName() + "()";
System.out.println(message);
throw new IllegalStateException(message, e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,22 @@ public static void waitUntilStarted(Addon addon)
}
catch (Exception e)
{
throw new ContainerException("Addon was not started.", e);
throw new ContainerException("Addon [" + addon + "] was not started.", e);
}
}

public static void waitUntilStopped(Addon addon)
{
try
{
while (!(addon.getStatus().isStopped() || addon.getStatus().isMissing()))
{
Thread.sleep(10);
}
}
catch (Exception e)
{
throw new ContainerException("Addon [" + addon + "] was not stopped.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jboss.forge.container.dependencies;
package org.jboss.forge.container.deployment;

import java.util.Set;
import java.util.concurrent.Future;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.jboss.forge.container.dependencies;
package org.jboss.forge.container.deployment;

import javax.inject.Inject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class ForgeImpl implements Forge

private List<AddonRepository> repositories = new ArrayList<AddonRepository>();

private LockManager lock = new LockManagerImpl();
private final LockManager lock = new LockManagerImpl();

public ForgeImpl()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,23 @@ public AddonTree(LockManager lock)

public void add(final Addon addon)
{
ValuedVisitor<Boolean, Addon> exists = new ValuedVisitor<Boolean, Addon>()
for (Addon existing : this)
{
@Override
public void visit(Addon instance)
{
if (instance.equals(addon) || instance.getId().equals(addon.getId()))
setResult(true);
}
};

if (exists.getResult() != null && exists.getResult() == true)
{
throw new IllegalArgumentException("Cannot add duplicate Addon [" + addon + "] to the registry.");
if (existing.equals(addon) || existing.getId().equals(addon.getId()))
throw new IllegalArgumentException("Cannot add duplicate Addon [" + addon + "] to the registry.");
}
else
reattach(addon);

System.out.println("Added [" + addon + "]");
}

public void reattach(Addon addon)
{
if (!contains(addon))
{
root.getMutableDependencies().add(
new AddonDependencyImpl(lock, root, new SingleVersionRange(addon.getId().getVersion()), addon,
false, false));

prune();
}
}
Expand Down Expand Up @@ -100,6 +97,7 @@ public void visit(Addon instance)
public void depthFirst(Visitor<Addon> visitor)
{
Set<Addon> seen = new HashSet<Addon>();
seen.add(root);
visitDepthFirst(seen, root, visitor);
}

Expand All @@ -122,9 +120,7 @@ public void breadthFirst(Visitor<Addon> visitor)
Queue<Addon> queue = new LinkedList<Addon>();
Set<Addon> seen = new HashSet<Addon>();

visitor.visit(root);
seen.add(root);

queue.add(root);

while (!queue.isEmpty())
Expand Down Expand Up @@ -154,7 +150,8 @@ public Iterator<Addon> iterator()
@Override
public void visit(Addon instance)
{
getResult().add(instance);
if (!root.equals(instance))
getResult().add(instance);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ private static class Memento
public Future<Addon> future;
public AddonRepository repository;
public ServiceRegistry registry;

@Override
public String toString()
{
return status.toString();
}

}

@SuppressWarnings("unused")
Expand Down
Loading

0 comments on commit a435f41

Please sign in to comment.