Since
jboss.org is down I'll answer here...
On Wed, 2007-11-14 at 10:48 -0500, alesj wrote:
Regarding
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?
You don't need to do anything so complicated.
You just need the relevant deployers to record the context names in some
well defined place, e.g. the Deployment{Unit|Context}
It's probably important enough to use a special method rather than
an attachment.
e.g.
public class BeanMetaDataDeployer extends
AbstractSimpleRealDeployer<BeanMetaData>
{
/** The kernel controller */
private final KernelController controller;
/**
* Create a new BeanDeployer.
*
* @param kernel the kernel
* @throws IllegalArgumentException for a null kernel
*/
public BeanMetaDataDeployer(Kernel kernel)
{
super(BeanMetaData.class);
if (kernel == null)
throw new IllegalArgumentException("Null kernel");
controller = kernel.getController();
setComponentsOnly(true);
}
@Override
public void deploy(DeploymentUnit unit, BeanMetaData deployment)
throws DeploymentException
{
KernelControllerContext context = new
AbstractKernelControllerContext(null, deployment, null);
try
{
controller.install(context);
+ unit.addControllerContextName(deployment.getName());
}
catch (Throwable t)
{
throw DeploymentException.rethrowAsDeploymentException("Error
deploying: " + deployment.getName(), t);
}
}
@Override
public void undeploy(DeploymentUnit unit, BeanMetaData deployment)
{
+ unit.removeControllerContextName(deployment.getName());
controller.uninstall(deployment.getName());
}
}
In practice, the component deployment unit name should be the context
name.
This is at least true for the POJO and Service deployers.
So you could just add it as some kind of easy declaration in the
constructor:
public BeanMetaDataDeployer(Kernel kernel)
{
super(BeanMetaData.class);
if (kernel == null)
throw new IllegalArgumentException("Null kernel");
controller = kernel.getController();
setComponentsOnly(true);
// obviously some shorter property name ;-)
setComponentDeploymentNameIsControllerContextName(true);
}
and handle it in the abstract classes:
deploy(...); // will throw an error if not registered in the
controller
if (unit.isComponent() &&
isComponentDeploymentNameControllerContextName())
addComponentContextName(unit.getSimpleName());
--
xxxxxxxxxxxxxxxxxxxxxxxxxxxx
Adrian Brock
Chief Scientist
JBoss, a division of Red Hat
xxxxxxxxxxxxxxxxxxxxxxxxxxxx