Checking DeploymentContext for failures
alesj Nov 14, 2007 10:48 AMRegarding http://jira.jboss.com/jira/browse/JBMICROCONT-187.
What's the best way to get failing ControllerContexts that belong to DeploymentContext param?
This is what I came up currently:
protected final void checkComplete(
DeploymentContext context,
Map<String, Throwable> contextsInError,
Map<String, Set<MissingDependency>> contextsMissingDependencies,
Set<ControllerContext> notInstalled,
List<ControllerState> states)
{
Attachments attachments = context.getDeploymentUnit();
if (attachments != null && checkers != null)
{
for (AttachmentChecker checker : checkers)
{
ControllerContext cc = checker.getControllerContext(controller, attachments);
if (cc != null)
{
if (cc.getState().equals(cc.getRequiredState()) == false && notInstalled.contains(cc))
{
checkControllerContext(cc, contextsInError, contextsMissingDependencies, states);
}
}
}
}
List<DeploymentContext> children = context.getChildren();
if (children != null && children.isEmpty() == false)
{
for(DeploymentContext child : children)
checkComplete(child, contextsInError, contextsMissingDependencies, notInstalled, states);
}
}
where AttachmentChecker looks like this, e.g. Bean checker:
public abstract class AbstractAttachmentChecker<T> implements AttachmentChecker
{
private Class<T> type;
protected AbstractAttachmentChecker(Class<T> type)
{
if (type == null)
throw new IllegalArgumentException("Null type.");
this.type = type;
}
public ControllerContext getControllerContext(Controller controller, Attachments attachments)
{
T attachment = attachments.getAttachment(type);
if (attachment != null)
return getControllerContext(controller, attachment);
return null;
}
protected abstract ControllerContext getControllerContext(Controller controller, T attachment);
}
public class BeanAttachmentChecker extends AbstractAttachmentChecker<BeanMetaData>
{
public BeanAttachmentChecker()
{
super(BeanMetaData.class);
}
protected ControllerContext getControllerContext(Controller controller, BeanMetaData attachment)
{
return controller.getContext(attachment.getName(), null);
}
}
Another checker implementations would include ServiceAC (mbeans) and ControllerContextAC (OSGi deployments).
Any others?