camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmoulli...@apache.org
Subject [1/2] git commit: Add BeanManager as parameter - will be injected by @Observes & PassivationCapable
Date Wed, 06 Nov 2013 15:03:40 GMT
Updated Branches:
  refs/heads/master 61312f51c -> 5de774cb1


Add BeanManager as parameter - will be injected by @Observes & PassivationCapable


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/c97601f5
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/c97601f5
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/c97601f5

Branch: refs/heads/master
Commit: c97601f546323279931ea9a0f1ff8df72b3d1b7e
Parents: 71758b5
Author: Charles Mouliard <cmoulliard@apache.org>
Authored: Wed Nov 6 16:01:51 2013 +0100
Committer: Charles Mouliard <cmoulliard@apache.org>
Committed: Wed Nov 6 16:01:51 2013 +0100

----------------------------------------------------------------------
 .../org/apache/camel/cdi/internal/BeanAdapter.java   | 14 +++++++++-----
 .../apache/camel/cdi/internal/CamelContextBean.java  | 11 +++++++++--
 .../apache/camel/cdi/internal/CamelExtension.java    | 15 ++++++++++-----
 3 files changed, 28 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c97601f5/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/BeanAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/BeanAdapter.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/BeanAdapter.java
index db986f6..504ac11 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/BeanAdapter.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/BeanAdapter.java
@@ -20,6 +20,8 @@ import java.lang.reflect.Field;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
 
 import org.apache.camel.Consume;
 import org.apache.camel.EndpointInject;
@@ -38,6 +40,8 @@ public class BeanAdapter {
     private final List<Field> endpointFields = new ArrayList<Field>();
     private final ContextName startup;
 
+    @Inject BeanManager beanManager;
+
     public BeanAdapter(ContextName startup) {
         this.startup = startup;
     }
@@ -80,7 +84,7 @@ public class BeanAdapter {
             if (annotation != null) {
                 String contextName = CamelExtension.getCamelContextName(annotation.context(),
startup);
                 DefaultCamelBeanPostProcessor postProcessor = camelExtension.getPostProcessor(
-                        contextName);
+                        contextName, beanManager);
                 if (postProcessor != null) {
                     postProcessor.getPostProcessorHelper().consumerInjection(method, reference,
beanName);
                 }
@@ -91,7 +95,7 @@ public class BeanAdapter {
             if (annotation != null) {
                 String contextName = CamelExtension.getCamelContextName(annotation.context(),
startup);
                 DefaultCamelBeanPostProcessor postProcessor = camelExtension.getPostProcessor(
-                        contextName);
+                        contextName, beanManager);
                 if (postProcessor != null && postProcessor.getPostProcessorHelper().matchContext(contextName))
{
                     postProcessor.setterInjection(method, reference, beanName, annotation.uri(),
annotation.ref(),
                             annotation.property());
@@ -103,7 +107,7 @@ public class BeanAdapter {
             if (annotation != null) {
                 String contextName = CamelExtension.getCamelContextName(annotation.context(),
startup);
                 DefaultCamelBeanPostProcessor postProcessor = camelExtension.getPostProcessor(
-                        contextName);
+                        contextName, beanManager);
                 if (postProcessor != null && postProcessor.getPostProcessorHelper().matchContext(contextName))
{
                     postProcessor.setterInjection(method, reference, beanName, annotation.uri(),
annotation.ref(),
                             annotation.property());
@@ -116,7 +120,7 @@ public class BeanAdapter {
             if (annotation != null) {
                 String contextName = CamelExtension.getCamelContextName(annotation.context(),
startup);
                 DefaultCamelBeanPostProcessor postProcessor = camelExtension.getPostProcessor(
-                        contextName);
+                        contextName, beanManager);
                 if (postProcessor != null && postProcessor.getPostProcessorHelper().matchContext(contextName))
{
                     postProcessor.injectField(field, annotation.uri(), annotation.ref(),
                             annotation.property(), reference, beanName);
@@ -127,7 +131,7 @@ public class BeanAdapter {
             EndpointInject annotation = field.getAnnotation(EndpointInject.class);
             String contextName = CamelExtension.getCamelContextName(annotation.context(),
startup);
             DefaultCamelBeanPostProcessor postProcessor = camelExtension.getPostProcessor(
-                    contextName);
+                    contextName, beanManager);
             if (postProcessor != null && postProcessor.getPostProcessorHelper().matchContext(contextName))
{
                 postProcessor.injectField(field, annotation.uri(), annotation.ref(),
                         annotation.property(), reference, beanName);

http://git-wip-us.apache.org/repos/asf/camel/blob/c97601f5/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelContextBean.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelContextBean.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelContextBean.java
index 7e97f66..f94d371 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelContextBean.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelContextBean.java
@@ -21,13 +21,14 @@ import java.lang.reflect.Type;
 import java.util.Arrays;
 import java.util.HashSet;
 import java.util.Set;
-
+import java.util.UUID;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.inject.spi.Bean;
 import javax.enterprise.inject.spi.BeanManager;
 import javax.enterprise.inject.spi.InjectionPoint;
 import javax.enterprise.inject.spi.InjectionTarget;
+import javax.enterprise.inject.spi.PassivationCapable;
 
 import org.apache.camel.CamelContext;
 import org.apache.camel.cdi.CdiCamelContext;
@@ -39,7 +40,9 @@ import org.apache.deltaspike.core.api.literal.DefaultLiteral;
  * Description of camel context bean.
  */
 @SuppressWarnings("unchecked")
-public class CamelContextBean implements Bean<CdiCamelContext> {
+public class CamelContextBean implements Bean<CdiCamelContext>, PassivationCapable
{
+
+    private static final UUID uniqueId = UUID.randomUUID();
 
     private final BeanManager beanManager;
     private final String name;
@@ -130,4 +133,8 @@ public class CamelContextBean implements Bean<CdiCamelContext> {
     public void configureCamelContext(CdiCamelContext camelContext) {
         config.configure(camelContext, beanManager);
     }
+
+    @Override public String getId() {
+        return uniqueId.toString();
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/c97601f5/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelExtension.java
----------------------------------------------------------------------
diff --git a/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelExtension.java
b/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelExtension.java
index a05f9c2..44a44b5 100644
--- a/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelExtension.java
+++ b/components/camel-cdi/src/main/java/org/apache/camel/cdi/internal/CamelExtension.java
@@ -63,6 +63,7 @@ import org.apache.deltaspike.core.util.metadata.builder.AnnotatedTypeBuilder;
  * Set of camel specific hooks for CDI.
  */
 public class CamelExtension implements Extension {
+
     private static class InjectLiteral extends AnnotationLiteral<Inject> implements
Inject {
         private static final long serialVersionUID = 1L;
     }
@@ -223,7 +224,7 @@ public class CamelExtension implements Extension {
         throws Exception {
         for (CamelContextBean bean : camelContextBeans) {
             String name = bean.getCamelContextName();
-            CamelContext context = getCamelContext(name);
+            CamelContext context = getCamelContext(name, beanManager);
             if (context == null) {
                 throw new IllegalStateException(
                         "CamelContext '" + name + "' has not been injected into the CamelContextMap");
@@ -317,8 +318,8 @@ public class CamelExtension implements Extension {
         return adapter;
     }
 
-    protected DefaultCamelBeanPostProcessor getPostProcessor(String context) {
-        CamelContext camelContext = getCamelContext(context);
+    protected DefaultCamelBeanPostProcessor getPostProcessor(String context, BeanManager
beanManager) {
+        CamelContext camelContext = getCamelContext(context, beanManager);
         if (camelContext != null) {
             return new DefaultCamelBeanPostProcessor(camelContext);
         } else {
@@ -326,9 +327,13 @@ public class CamelExtension implements Extension {
         }
     }
 
-    protected CamelContext getCamelContext(String context) {
+    protected CamelContext getCamelContext(String context, BeanManager beanManager) {
         if (camelContextMap == null) {
-            camelContextMap = BeanProvider.getContextualReference(CamelContextMap.class);
+            //camelContextMap = BeanProvider.getContextualReference(CamelContextMap.class);
+            Set<Bean<?>> beans = beanManager.getBeans(CamelContextMap.class);
+            Bean<?> bean = beanManager.resolve(beans);
+            CreationalContext<?> creationalContext = beanManager.createCreationalContext(bean);
+            camelContextMap = (CamelContextMap) beanManager.getReference(bean, bean.getBeanClass(),
creationalContext);
             ObjectHelper.notNull(camelContextMap, "Could not resolve CamelContextMap");
         }
         return camelContextMap.getCamelContext(context);


Mime
View raw message