[Design the new POJO MicroContainer] - Re: Annotation Tests in deployers-vfs
by adrian@jboss.org
"alesj" wrote :
| Does this somehow fit into the picture you have/had?
|
No not really.
I wanted you to seperate the annotation scanning from the component creation.
i.e the annotation @Bean or a "collection" of them @Beans?
becomes an attachment in its own right.
The component deployer should not care where the annotation(s) come from.
One possible source is the annoation scanning.
Schematically:
BeanAnnotationScanner: class scan -> annotation attachments
Component deployer: metadata or annotations -> BeanMetaData components
That way if I dont want annotation scanning for beans or I want to use
some other logic I can remove, replace or insert a new deployer to do what I want.
e.g. Hypothetically: suppose I want all beans scanned from classes to be "on-demand"
I can add a deployer inbetween that modifies the annotations but doesn't touch
those created using normal metadata.
Like I said before, I don't really think anybody will do this kind of thing,
but we should do it properly just in case.
Also it keeps the processing to "TO DO ONE THING WELL"
i.e. one deployer knows how to scan for bean annotations
one knows how to create components from a set of such annotations
(mod those that already have metadata).
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4154690#4154690
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4154690
16 years, 7 months
[Design the new POJO MicroContainer] - Re: Annotation Tests in deployers-vfs
by alesj
This is what I came up with:
| public abstract class AbstractAnnotationDeployer<D, C> extends AbstractComponentDeployer<D, C>
| {
| /** The annotation processors */
| private AnnotationProcessor<?, C>[] processors;
|
| public AbstractAnnotationDeployer(AnnotationProcessor<?, C>... processors)
| {
| super();
| if (processors != null && processors.length > 0)
| {
| addInput(AnnotationEnvironment.class);
| this.processors = processors;
| for (AnnotationProcessor processor : processors)
| {
| addInput(processor.getAnnotation());
| }
| }
| }
|
| public void internalDeploy(DeploymentUnit unit) throws DeploymentException
| {
| super.internalDeploy(unit);
|
| if (processors != null && compVisitor != null)
| {
| try
| {
| AnnotationEnvironment env = unit.getAttachment(AnnotationEnvironment.class);
| for (AnnotationProcessor<?, C> processor : processors)
| {
| List<C> components = new ArrayList<C>();
|
| if (env != null)
| {
| // from classes
| Set<Class<?>> classes = env.classIsAnnotatedWith(processor.getAnnotation());
| for (Class clazz : classes)
| {
| C component = processor.createComponent(clazz);
| if (component != null)
| components.add(component);
| }
| }
|
| // from attachments
| Annotation annotation = unit.getAttachment(processor.getAnnotation());
| if (annotation != null)
| {
| C component = processor.createComponent(annotation);
| if (component != null)
| components.add(component);
| }
|
| int i = 0;
| try
| {
| for (i = 0; i < components.size(); i++)
| {
| deployComponent(unit, processor, components.get(i));
| }
| }
| catch (Throwable t)
| {
| for (; i >= 0; i--)
| {
| try
| {
| compVisitor.undeploy(unit, components.get(i));
| }
| catch (Throwable ignored)
| {
| }
| }
| throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + unit.getName(), t);
| }
| }
| }
| catch (Throwable t)
| {
| super.internalUndeploy(unit);
| throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + unit.getName(), t);
| }
| }
| }
|
| protected void deployComponent(DeploymentUnit unit, AnnotationProcessor<?, C> processor, C component) throws DeploymentException
| {
| String name = processor.getComponentName(component);
| DeploymentUnit componentUnit = unit.getComponent(name);
| C previous = null;
| if (componentUnit != null)
| previous = componentUnit.getAttachment(getOutput());
|
| if (previous != null)
| {
| processor.merge(previous, component);
| }
| else if (processor.isValidComponent(component))
| {
| compVisitor.deploy(unit, component);
| }
| }
|
| public void internalUndeploy(DeploymentUnit unit)
| {
| if (processors != null && compVisitor != null)
| {
| try
| {
| AnnotationEnvironment env = unit.getAttachment(AnnotationEnvironment.class);
| for (AnnotationProcessor<?, C> processor : processors)
| {
| List<C> components = new ArrayList<C>();
|
| if (env != null)
| {
| // from classes
| Set<Class<?>> classes = env.classIsAnnotatedWith(processor.getAnnotation());
| for (Class clazz : classes)
| {
| C component = processor.createUndeployableComponent(clazz);
| if (component != null)
| components.add(component);
| }
| }
|
| // from attachments
| Annotation annotation = unit.getAttachment(processor.getAnnotation());
| if (annotation != null)
| {
| C component = processor.createUndeployableComponent(annotation);
| if (component != null)
| components.add(component);
| }
|
| for (int i = components.size() - 1; i >= 0; i--)
| {
| try
| {
| compVisitor.undeploy(unit, components.get(i));
| }
| catch (Throwable ignored)
| {
| log.warn("Error during undeploy: " + unit.getName(), ignored);
| }
| }
| }
| }
| catch (Throwable ignored)
| {
| log.warn("Error during undeploy: " + unit.getName(), ignored);
| }
| }
|
| super.internalUndeploy(unit);
| }
| }
|
The two issues that I see here are
- I'm not able to differ between previous (merged) component while undeploying
- I have to re-create component for undeploy (that's why I use that createUndeployableComponent method)
Does this somehow fit into the picture you have/had?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4154666#4154666
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4154666
16 years, 7 months
[Design the new POJO MicroContainer] - fixing AbstractComponentDeployer
by alesj
I did a couple of small fixes to AbstractComponentDeployer.
I'll comment my changes on the svn diff
| public void internalDeploy(DeploymentUnit unit) throws DeploymentException
| {
| super.internalDeploy(unit);
|
| try
| {
| deployComponents(unit);
| }
| catch (Throwable t)
| {
| // we need to unwind the super too
| // the actual component unwinding is done
| // at the point of failure
| - undeployComponents(unit);
| + super.internalUndeploy(unit);
| throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + unit.getName(), t);
| }
| }
|
| public void internalUndeploy(DeploymentUnit unit)
| {
| // make it asymetric
| - super.internalUndeploy(unit);
| undeployComponents(unit);
| + super.internalUndeploy(unit);
| }
|
| protected void deployComponents(DeploymentUnit unit) throws DeploymentException
| @@ -100,9 +101,7 @@
| if (compVisitor == null)
| return;
|
| // this now uses extracted super method - see below
| - Set<? extends C> components = unit.getAllMetaData(getOutput());
| - for (C component : components)
| - compVisitor.deploy(unit, component);
| + deploy(unit, compVisitor);
| }
|
The extracted deploy method - for both, deployment and components:
| protected <U> void deploy(DeploymentUnit unit, DeploymentVisitor<U> visitor) throws DeploymentException
| {
| List<U> visited = new ArrayList<U>();
| try
| {
| Set<? extends U> deployments = unit.getAllMetaData(visitor.getVisitorType());
| for (U deployment : deployments)
| {
| visitor.deploy(unit, deployment);
| visited.add(deployment);
| }
| }
| catch (Throwable t)
| {
| for (int i = visited.size()-1; i >= 0; --i)
| {
| try
| {
| visitor.undeploy(unit, visited.get(i));
| }
| catch (Throwable ignored)
| {
| log.warn("Error during undeploy: " + unit.getName(), ignored);
| }
| }
| throw DeploymentException.rethrowAsDeploymentException("Error deploying: " + unit.getName(), t);
| }
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4154594#4154594
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4154594
16 years, 7 months