You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/09/29 20:25:57 UTC

[1/2] activemq-artemis git commit: ARTEMIS-756 introduce CDI based integration for Artemis. Includes integration tests on both Weld and OWB.

Repository: activemq-artemis
Updated Branches:
  refs/heads/master 507deb6a8 -> f10752b68


ARTEMIS-756 introduce CDI based integration for Artemis.  Includes integration tests on both Weld and OWB.


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/9163c679
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/9163c679
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/9163c679

Branch: refs/heads/master
Commit: 9163c679ef21e70ba94f54c9a1bed9a12ad6bcca
Parents: 507deb6
Author: John D. Ament <jo...@apache.org>
Authored: Sun Jul 31 22:12:50 2016 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Thu Sep 29 16:25:47 2016 -0400

----------------------------------------------------------------------
 docs/user-manual/en/cdi-integration.md          |  32 +++++
 integration/artemis-cdi-integration/pom.xml     | 121 +++++++++++++++++++
 .../ArtemisClientConfiguration.java             |  76 ++++++++++++
 .../DefaultArtemisClientConfigurationImpl.java  |  95 +++++++++++++++
 .../client/cdi/extension/AnyLiteral.java        |  28 +++++
 .../cdi/extension/ArtemisClientConfigBean.java  |  99 +++++++++++++++
 .../ArtemisEmbeddedServerConfigBean.java        | 104 ++++++++++++++++
 .../client/cdi/extension/ArtemisExtension.java  |  62 ++++++++++
 .../client/cdi/extension/DefaultLiteral.java    |  28 +++++
 .../cdi/factory/ConnectionFactoryProvider.java  | 106 ++++++++++++++++
 .../client/cdi/logger/ActiveMQCDILogger.java    |  65 ++++++++++
 .../artemis/cdi/bootstrap/CDIBootstrapTest.java |  76 ++++++++++++
 pom.xml                                         |  62 +++++++++-
 13 files changed, 953 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/docs/user-manual/en/cdi-integration.md
----------------------------------------------------------------------
diff --git a/docs/user-manual/en/cdi-integration.md b/docs/user-manual/en/cdi-integration.md
new file mode 100644
index 0000000..cca8990
--- /dev/null
+++ b/docs/user-manual/en/cdi-integration.md
@@ -0,0 +1,32 @@
+# CDI Integration
+
+Apache ActiveMQ Artemis provides a simple CDI integration.  It can either use an embedded broker or connect to a remote broker.
+
+## Configuring a connection
+
+Configuration is provided by implementing the `ArtemisClientConfiguration` interface.
+
+```java
+public interface ArtemisClientConfiguration {
+   String getHost();
+
+   Integer getPort();
+
+   String getUsername();
+
+   String getPassword();
+
+   String getUrl();
+
+   String getConnectorFactory();
+
+   boolean startEmbeddedBroker();
+
+   boolean isHa();
+
+   boolean hasAuthentication();
+}
+```
+
+There's a default configuration out of the box, if none is specified.  This will generate an embedded broker.
+

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/integration/artemis-cdi-integration/pom.xml
----------------------------------------------------------------------
diff --git a/integration/artemis-cdi-integration/pom.xml b/integration/artemis-cdi-integration/pom.xml
new file mode 100644
index 0000000..c04ab0c
--- /dev/null
+++ b/integration/artemis-cdi-integration/pom.xml
@@ -0,0 +1,121 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements. See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership. The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License. You may obtain a copy of the License at
+  ~
+  ~ http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied. See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>artemis-pom</artifactId>
+        <groupId>org.apache.activemq</groupId>
+        <version>1.5.0-SNAPSHOT</version>
+        <relativePath>../..</relativePath>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <properties>
+        <activemq.basedir>${project.basedir}/../../</activemq.basedir>
+    </properties>
+
+    <artifactId>artemis-cdi-client</artifactId>
+    <name>ActiveMQ Artemis CDI Integration</name>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.jboss.logging</groupId>
+            <artifactId>jboss-logging-processor</artifactId>
+            <scope>provided</scope>
+            <optional>true</optional>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.logging</groupId>
+            <artifactId>jboss-logging</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.activemq</groupId>
+            <artifactId>artemis-jms-client</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.activemq</groupId>
+            <artifactId>artemis-jms-server</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <dependency>
+            <groupId>javax.enterprise</groupId>
+            <artifactId>cdi-api</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.logmanager</groupId>
+            <artifactId>jboss-logmanager</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.arquillian.junit</groupId>
+            <artifactId>arquillian-junit-container</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+        </dependency>
+    </dependencies>
+    <profiles>
+        <profile>
+            <id>Weld</id>
+            <activation>
+                <activeByDefault>true</activeByDefault>
+            </activation>
+            <dependencies>
+                <dependency>
+                    <groupId>org.jboss.weld.se</groupId>
+                    <artifactId>weld-se</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>org.jboss.arquillian.container</groupId>
+                    <artifactId>arquillian-weld-embedded</artifactId>
+                </dependency>
+            </dependencies>
+        </profile>
+        <profile>
+            <id>OWB</id>
+            <dependencies>
+                <dependency>
+                    <groupId>org.apache.openwebbeans</groupId>
+                    <artifactId>openwebbeans-impl</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>org.apache.openwebbeans</groupId>
+                    <artifactId>openwebbeans-spi</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>org.apache.openwebbeans</groupId>
+                    <artifactId>openwebbeans-resource</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>org.apache.openwebbeans.arquillian</groupId>
+                    <artifactId>owb-arquillian-standalone</artifactId>
+                </dependency>
+                <dependency>
+                    <groupId>org.apache.geronimo.specs</groupId>
+                    <artifactId>geronimo-annotation_1.2_spec</artifactId>
+                </dependency>
+            </dependencies>
+        </profile>
+    </profiles>
+</project>

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/configuration/ArtemisClientConfiguration.java
----------------------------------------------------------------------
diff --git a/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/configuration/ArtemisClientConfiguration.java b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/configuration/ArtemisClientConfiguration.java
new file mode 100644
index 0000000..4bd816c
--- /dev/null
+++ b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/configuration/ArtemisClientConfiguration.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.artemis.client.cdi.configuration;
+
+import org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory;
+import org.apache.activemq.artemis.core.remoting.impl.netty.NettyConnectorFactory;
+
+public interface ArtemisClientConfiguration {
+
+   String IN_VM_CONNECTOR = InVMConnectorFactory.class.getName();
+   String REMOTE_CONNECTOR = NettyConnectorFactory.class.getName();
+
+   /**
+    * @return if present, sends a username for the connection
+    */
+   String getUsername();
+
+   /**
+    * @return the password for the connection.  If username is set, password must be set
+    */
+   String getPassword();
+
+   /**
+    * Either url should be set, or host, port, connector factory should be set.
+    *
+    * @return if set, will be used in the server locator to look up the server instead of the hostname/port combination
+    */
+   String getUrl();
+
+   /**
+    * @return The hostname to connect to
+    */
+   String getHost();
+
+   /**
+    * @return the port number to connect to
+    */
+   Integer getPort();
+
+   /**
+    * @return the connector factory to use for connections.
+    */
+   String getConnectorFactory();
+
+   /**
+    * @return Whether or not to start the embedded broker
+    */
+   boolean startEmbeddedBroker();
+
+   /**
+    * @return whether or not this is an HA connection
+    */
+   boolean isHa();
+
+   /**
+    * @return whether or not the authentication parameters should be used
+    */
+   boolean hasAuthentication();
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/configuration/DefaultArtemisClientConfigurationImpl.java
----------------------------------------------------------------------
diff --git a/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/configuration/DefaultArtemisClientConfigurationImpl.java b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/configuration/DefaultArtemisClientConfigurationImpl.java
new file mode 100644
index 0000000..272e1bf
--- /dev/null
+++ b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/configuration/DefaultArtemisClientConfigurationImpl.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.artemis.client.cdi.configuration;
+
+import javax.enterprise.inject.Vetoed;
+import java.util.Map;
+
+@Vetoed
+public class DefaultArtemisClientConfigurationImpl implements ArtemisClientConfiguration {
+
+   private String host;
+   private Integer port;
+   private String url;
+   private String username;
+   private String password;
+   private boolean ha;
+
+   public DefaultArtemisClientConfigurationImpl() {
+   }
+
+   public DefaultArtemisClientConfigurationImpl(Map<String, Object> params) {
+      host = (String) params.get("host");
+      port = (Integer) params.get("port");
+      url = (String) params.get("url");
+      username = (String) params.get("username");
+      password = (String) params.get("password");
+      Boolean isHa = (Boolean) params.get("ha");
+      if (isHa == null) {
+         isHa = false;
+      }
+      ha = isHa;
+   }
+
+   @Override
+   public String getHost() {
+      return host;
+   }
+
+   @Override
+   public Integer getPort() {
+      return port;
+   }
+
+   @Override
+   public String getUsername() {
+      return username;
+   }
+
+   @Override
+   public String getPassword() {
+      return password;
+   }
+
+   @Override
+   public String getUrl() {
+      return url;
+   }
+
+   @Override
+   public String getConnectorFactory() {
+      return startEmbeddedBroker() ? IN_VM_CONNECTOR : REMOTE_CONNECTOR;
+   }
+
+   @Override
+   public boolean startEmbeddedBroker() {
+      return host == null && url == null;
+   }
+
+   @Override
+   public boolean isHa() {
+      return ha;
+   }
+
+   @Override
+   public boolean hasAuthentication() {
+      return getUsername() != null && getUsername().length() > 0;
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/AnyLiteral.java
----------------------------------------------------------------------
diff --git a/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/AnyLiteral.java b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/AnyLiteral.java
new file mode 100644
index 0000000..6d0ccaf
--- /dev/null
+++ b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/AnyLiteral.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.artemis.client.cdi.extension;
+
+import javax.enterprise.inject.Any;
+import javax.enterprise.util.AnnotationLiteral;
+
+class AnyLiteral extends AnnotationLiteral<Any> implements Any {
+
+   static final Any INSTANCE = new AnyLiteral();
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisClientConfigBean.java
----------------------------------------------------------------------
diff --git a/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisClientConfigBean.java b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisClientConfigBean.java
new file mode 100644
index 0000000..ef91f4d
--- /dev/null
+++ b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisClientConfigBean.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.artemis.client.cdi.extension;
+
+import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration;
+import org.apache.artemis.client.cdi.configuration.DefaultArtemisClientConfigurationImpl;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashSet;
+import java.util.Set;
+
+import static java.util.Collections.emptySet;
+
+class ArtemisClientConfigBean implements Bean<ArtemisClientConfiguration> {
+
+   @Override
+   public Class<?> getBeanClass() {
+      return DefaultArtemisClientConfigurationImpl.class;
+   }
+
+   @Override
+   public Set<InjectionPoint> getInjectionPoints() {
+      return emptySet();
+   }
+
+   @Override
+   public boolean isNullable() {
+      return false;
+   }
+
+   @Override
+   public ArtemisClientConfiguration create(CreationalContext<ArtemisClientConfiguration> creationalContext) {
+      return new DefaultArtemisClientConfigurationImpl();
+   }
+
+   @Override
+   public void destroy(ArtemisClientConfiguration configuration,
+                       CreationalContext<ArtemisClientConfiguration> creationalContext) {
+   }
+
+   @Override
+   public Set<Type> getTypes() {
+      Set<Type> types = new HashSet<>();
+      types.add(DefaultArtemisClientConfigurationImpl.class);
+      types.add(ArtemisClientConfiguration.class);
+      return types;
+   }
+
+   @Override
+   public Set<Annotation> getQualifiers() {
+      Set<Annotation> qualifiers = new HashSet<>();
+      qualifiers.add(AnyLiteral.INSTANCE);
+      qualifiers.add(DefaultLiteral.INSTANCE);
+      return qualifiers;
+
+   }
+
+   @Override
+   public Class<? extends Annotation> getScope() {
+      return ApplicationScoped.class;
+   }
+
+   @Override
+   public String getName() {
+      return null;
+   }
+
+   @Override
+   public Set<Class<? extends Annotation>> getStereotypes() {
+      return emptySet();
+   }
+
+   @Override
+   public boolean isAlternative() {
+      return false;
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisEmbeddedServerConfigBean.java
----------------------------------------------------------------------
diff --git a/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisEmbeddedServerConfigBean.java b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisEmbeddedServerConfigBean.java
new file mode 100644
index 0000000..07ae6cd
--- /dev/null
+++ b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisEmbeddedServerConfigBean.java
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.artemis.client.cdi.extension;
+
+import org.apache.activemq.artemis.api.core.TransportConfiguration;
+import org.apache.activemq.artemis.core.config.Configuration;
+import org.apache.activemq.artemis.core.config.impl.ConfigurationImpl;
+import org.apache.activemq.artemis.core.remoting.impl.invm.InVMAcceptorFactory;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.InjectionPoint;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import static java.util.Collections.emptySet;
+
+public class ArtemisEmbeddedServerConfigBean implements Bean<Configuration> {
+
+   @Override
+   public Class<?> getBeanClass() {
+      return ConfigurationImpl.class;
+   }
+
+   @Override
+   public Set<InjectionPoint> getInjectionPoints() {
+      return emptySet();
+   }
+
+   @Override
+   public boolean isNullable() {
+      return false;
+   }
+
+   @Override
+   public Configuration create(CreationalContext<Configuration> creationalContext) {
+      Map<String, Object> params = new HashMap<>();
+      params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "1");
+      return new ConfigurationImpl().setSecurityEnabled(false).setPersistenceEnabled(false).setJMXManagementEnabled(false).addAcceptorConfiguration(new TransportConfiguration(InVMAcceptorFactory.class.getName(), params));
+   }
+
+   @Override
+   public void destroy(Configuration configuration, CreationalContext<Configuration> creationalContext) {
+   }
+
+   @Override
+   public Set<Type> getTypes() {
+      Set<Type> types = new HashSet<>();
+      types.add(ConfigurationImpl.class);
+      types.add(Configuration.class);
+      return types;
+   }
+
+   @Override
+   public Set<Annotation> getQualifiers() {
+      Set<Annotation> qualifiers = new HashSet<>();
+      qualifiers.add(AnyLiteral.INSTANCE);
+      qualifiers.add(DefaultLiteral.INSTANCE);
+      return qualifiers;
+
+   }
+
+   @Override
+   public Class<? extends Annotation> getScope() {
+      return ApplicationScoped.class;
+   }
+
+   @Override
+   public String getName() {
+      return null;
+   }
+
+   @Override
+   public Set<Class<? extends Annotation>> getStereotypes() {
+      return emptySet();
+   }
+
+   @Override
+   public boolean isAlternative() {
+      return false;
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisExtension.java
----------------------------------------------------------------------
diff --git a/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisExtension.java b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisExtension.java
new file mode 100644
index 0000000..1b644f9
--- /dev/null
+++ b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/ArtemisExtension.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.artemis.client.cdi.extension;
+
+import org.apache.activemq.artemis.core.config.Configuration;
+import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration;
+import org.apache.artemis.client.cdi.logger.ActiveMQCDILogger;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+public class ArtemisExtension implements Extension {
+
+   private boolean foundEmbeddedConfig = false;
+   private boolean foundConfiguration = false;
+
+   <T extends ArtemisClientConfiguration> void foundClientConfig(@Observes ProcessAnnotatedType<T> pat) {
+      ActiveMQCDILogger.LOGGER.discoveredConfiguration(pat);
+      foundConfiguration = true;
+   }
+
+   <T extends Configuration> void foundEmbeddedConfig(@Observes ProcessAnnotatedType<T> pat) {
+      ActiveMQCDILogger.LOGGER.discoveredClientConfiguration(pat);
+      foundEmbeddedConfig = true;
+   }
+
+   void afterBeanDiscovery(@Observes AfterBeanDiscovery afterBeanDiscovery) {
+      if (!foundConfiguration) {
+         afterBeanDiscovery.addBean(new ArtemisClientConfigBean());
+      }
+      else {
+         ActiveMQCDILogger.LOGGER.notUsingDefaultConfiguration();
+      }
+      if (!foundEmbeddedConfig) {
+         afterBeanDiscovery.addBean(new ArtemisEmbeddedServerConfigBean());
+      }
+      else {
+         ActiveMQCDILogger.LOGGER.notUsingDefaultClientConfiguration();
+      }
+
+   }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/DefaultLiteral.java
----------------------------------------------------------------------
diff --git a/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/DefaultLiteral.java b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/DefaultLiteral.java
new file mode 100644
index 0000000..2280535
--- /dev/null
+++ b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/extension/DefaultLiteral.java
@@ -0,0 +1,28 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.artemis.client.cdi.extension;
+
+import javax.enterprise.inject.Default;
+import javax.enterprise.util.AnnotationLiteral;
+
+class DefaultLiteral extends AnnotationLiteral<Default> implements Default {
+
+   static final Default INSTANCE = new DefaultLiteral();
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/factory/ConnectionFactoryProvider.java
----------------------------------------------------------------------
diff --git a/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/factory/ConnectionFactoryProvider.java b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/factory/ConnectionFactoryProvider.java
new file mode 100644
index 0000000..9a6fe9d
--- /dev/null
+++ b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/factory/ConnectionFactoryProvider.java
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.artemis.client.cdi.factory;
+
+import org.apache.activemq.artemis.api.core.TransportConfiguration;
+import org.apache.activemq.artemis.api.jms.ActiveMQJMSClient;
+import org.apache.activemq.artemis.api.jms.JMSFactoryType;
+import org.apache.activemq.artemis.core.config.Configuration;
+import org.apache.activemq.artemis.core.remoting.impl.netty.TransportConstants;
+import org.apache.activemq.artemis.core.server.ActiveMQServer;
+import org.apache.activemq.artemis.core.server.ActiveMQServers;
+import org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory;
+import org.apache.activemq.artemis.jms.server.impl.JMSServerManagerImpl;
+import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.jms.JMSContext;
+import java.util.HashMap;
+import java.util.Map;
+
+@ApplicationScoped
+public class ConnectionFactoryProvider {
+
+   @Produces
+   @ApplicationScoped
+   private ActiveMQConnectionFactory activeMQConnectionFactory;
+
+   @Inject
+   private ArtemisClientConfiguration configuration;
+
+   @Inject
+   private Configuration embeddedConfiguration;
+
+   @PostConstruct
+   public void setupConnection() {
+      if (configuration.startEmbeddedBroker()) {
+         try {
+            ActiveMQServer activeMQServer = ActiveMQServers.newActiveMQServer(embeddedConfiguration, false);
+            JMSServerManagerImpl jmsServerManager = new JMSServerManagerImpl(activeMQServer);
+            jmsServerManager.start();
+         }
+         catch (Exception e) {
+            throw new RuntimeException("Unable to start embedded JMS", e);
+         }
+      }
+
+      try {
+         this.activeMQConnectionFactory = createConnectionFactory();
+      }
+      catch (Exception e) {
+         throw new RuntimeException("Unable to connect to remote server", e);
+      }
+   }
+
+   @Produces
+   @ApplicationScoped
+   public JMSContext createJMSContext() {
+      return this.activeMQConnectionFactory.createContext();
+   }
+
+   private ActiveMQConnectionFactory createConnectionFactory() throws Exception {
+      Map<String, Object> params = new HashMap<>();
+      params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "1");
+      final ActiveMQConnectionFactory activeMQConnectionFactory;
+      if (configuration.getUrl() != null) {
+         activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactory(configuration.getUrl(), null);
+      }
+      else {
+         if (configuration.getHost() != null) {
+            params.put(TransportConstants.HOST_PROP_NAME, configuration.getHost());
+            params.put(TransportConstants.PORT_PROP_NAME, configuration.getPort());
+         }
+         if (configuration.isHa()) {
+            activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params));
+         }
+         else {
+            activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params));
+         }
+      }
+      if (configuration.hasAuthentication()) {
+         activeMQConnectionFactory.setUser(configuration.getUsername());
+         activeMQConnectionFactory.setPassword(configuration.getPassword());
+      }
+      return activeMQConnectionFactory;
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/logger/ActiveMQCDILogger.java
----------------------------------------------------------------------
diff --git a/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/logger/ActiveMQCDILogger.java b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/logger/ActiveMQCDILogger.java
new file mode 100644
index 0000000..ef8952f
--- /dev/null
+++ b/integration/artemis-cdi-integration/src/main/java/org/apache/artemis/client/cdi/logger/ActiveMQCDILogger.java
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.artemis.client.cdi.logger;
+
+import org.jboss.logging.BasicLogger;
+import org.jboss.logging.Logger;
+import org.jboss.logging.annotations.LogMessage;
+import org.jboss.logging.annotations.Message;
+import org.jboss.logging.annotations.MessageLogger;
+
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+
+/**
+ * Logger code 57
+ *
+ * each message id must be 6 digits long starting with 57, the 3rd digit donates the level so
+ *
+ * INF0  1
+ * WARN  2
+ * DEBUG 3
+ * ERROR 4
+ * TRACE 5
+ * FATAL 6
+ *
+ * so an INFO message would be 571000 to 571999
+ */
+@MessageLogger(projectCode = "AMQ")
+public interface ActiveMQCDILogger extends BasicLogger {
+
+   ActiveMQCDILogger LOGGER = Logger.getMessageLogger(ActiveMQCDILogger.class,
+                                                      ActiveMQCDILogger.class.getPackage().getName());
+
+   @LogMessage
+   @Message(id = 571000, value = "Discovered configuration class {0}", format = Message.Format.MESSAGE_FORMAT)
+   void discoveredConfiguration(ProcessAnnotatedType<?> pat);
+
+   @LogMessage
+   @Message(id = 571001, value = "Discovered client configuration class {0}", format = Message.Format.MESSAGE_FORMAT)
+   void discoveredClientConfiguration(ProcessAnnotatedType<?> pat);
+
+   @LogMessage(level = Logger.Level.DEBUG)
+   @Message(id = 573000, value = "Configuration found, not using built in configuration")
+   void notUsingDefaultConfiguration();
+
+   @LogMessage(level = Logger.Level.DEBUG)
+   @Message(id = 573001, value = "Configuration found, not using built in configuration")
+   void notUsingDefaultClientConfiguration();
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/integration/artemis-cdi-integration/src/test/java/org/apache/activemq/artemis/cdi/bootstrap/CDIBootstrapTest.java
----------------------------------------------------------------------
diff --git a/integration/artemis-cdi-integration/src/test/java/org/apache/activemq/artemis/cdi/bootstrap/CDIBootstrapTest.java b/integration/artemis-cdi-integration/src/test/java/org/apache/activemq/artemis/cdi/bootstrap/CDIBootstrapTest.java
new file mode 100644
index 0000000..6762dd6
--- /dev/null
+++ b/integration/artemis-cdi-integration/src/test/java/org/apache/activemq/artemis/cdi/bootstrap/CDIBootstrapTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.activemq.artemis.cdi.bootstrap;
+
+import org.apache.artemis.client.cdi.configuration.ArtemisClientConfiguration;
+import org.apache.artemis.client.cdi.configuration.DefaultArtemisClientConfigurationImpl;
+import org.apache.artemis.client.cdi.extension.ArtemisExtension;
+import org.apache.artemis.client.cdi.factory.ConnectionFactoryProvider;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.Extension;
+import javax.inject.Inject;
+import javax.jms.JMSContext;
+import javax.jms.Queue;
+
+import static org.junit.Assert.assertEquals;
+
+@RunWith(Arquillian.class)
+public class CDIBootstrapTest {
+
+   @Deployment
+   public static Archive<?> createArchive() {
+      return ShrinkWrap.create(JavaArchive.class)
+         .addAsServiceProviderAndClasses(Extension.class, ArtemisExtension.class)
+         .addClasses(NativeConfig.class, ConnectionFactoryProvider.class)
+         .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+   }
+
+   @Inject
+   private JMSContext jmsContext;
+
+   @Test
+   public void shouldStartJMS() throws Exception {
+      String body = "This is a test";
+      Queue queue = jmsContext.createQueue("test");
+      jmsContext.createProducer().send(queue, body);
+      String receivedBody = jmsContext.createConsumer(queue).receiveBody(String.class, 5000);
+      Assert.assertNotNull(receivedBody);
+      assertEquals(body, receivedBody);
+   }
+
+   @ApplicationScoped
+   public static class NativeConfig extends DefaultArtemisClientConfigurationImpl {
+
+      @Override
+      public String getConnectorFactory() {
+         return ArtemisClientConfiguration.IN_VM_CONNECTOR;
+      }
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/9163c679/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d0586b8..b561726 100644
--- a/pom.xml
+++ b/pom.xml
@@ -54,6 +54,7 @@
       <module>integration/activemq-spring-integration</module>
       <module>integration/activemq-aerogear-integration</module>
       <module>integration/activemq-vertx-integration</module>
+      <module>integration/artemis-cdi-integration</module>
       <module>artemis-distribution</module>
       <module>tests</module>
       <module>artemis-features</module>
@@ -96,6 +97,10 @@
       <geronimo.ejb.3.0.spec.version>1.0.1</geronimo.ejb.3.0.spec.version>
       <geronimo.jta.1.1.spec.version>1.1.1</geronimo.jta.1.1.spec.version>
       <geronimo.jms.2.spec.version>1.0-alpha-2</geronimo.jms.2.spec.version>
+      <weld.version>2.4.0.Final</weld.version>
+      <arquillian-weld-embedded.version>2.0.0.Beta3</arquillian-weld-embedded.version>
+      <owb.version>1.7.0</owb.version>
+      <arquillian.version>1.1.11.Final</arquillian.version>
 
       <owasp.version>1.4.3</owasp.version>
 
@@ -155,6 +160,8 @@
       <javac-compiler-id>javac-with-errorprone</javac-compiler-id>
 
       <directory-version>1.5.7</directory-version>
+      <cdi-api.version>1.2</cdi-api.version>
+      <geronimo-annotation_1.2_spec.version>1.0</geronimo-annotation_1.2_spec.version>
    </properties>
 
    <scm>
@@ -586,7 +593,60 @@
             <!-- License: Apache 2.0 -->
          </dependency>
 
-
+         <dependency>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-impl</artifactId>
+            <version>${owb.version}</version>
+            <scope>test</scope>
+         </dependency>
+         <dependency>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-spi</artifactId>
+            <version>${owb.version}</version>
+            <scope>test</scope>
+         </dependency>
+         <dependency>
+            <groupId>org.apache.openwebbeans</groupId>
+            <artifactId>openwebbeans-resource</artifactId>
+            <version>${owb.version}</version>
+            <scope>test</scope>
+         </dependency>
+         <dependency>
+            <groupId>org.apache.openwebbeans.arquillian</groupId>
+            <artifactId>owb-arquillian-standalone</artifactId>
+            <version>${owb.version}</version>
+            <scope>test</scope>
+         </dependency>
+         <dependency>
+            <groupId>org.apache.geronimo.specs</groupId>
+            <artifactId>geronimo-annotation_1.2_spec</artifactId>
+            <version>${geronimo-annotation_1.2_spec.version}</version>
+            <scope>provided</scope>
+         </dependency>
+         <dependency>
+            <groupId>org.jboss.weld.se</groupId>
+            <artifactId>weld-se</artifactId>
+            <version>${weld.version}</version>
+            <scope>test</scope>
+         </dependency>
+         <dependency>
+            <groupId>org.jboss.arquillian.container</groupId>
+            <artifactId>arquillian-weld-embedded</artifactId>
+            <version>${arquillian-weld-embedded.version}</version>
+            <scope>test</scope>
+         </dependency>
+         <dependency>
+            <groupId>org.jboss.arquillian.junit</groupId>
+            <artifactId>arquillian-junit-container</artifactId>
+            <version>${arquillian.version}</version>
+            <scope>test</scope>
+         </dependency>
+         <dependency>
+            <groupId>javax.enterprise</groupId>
+            <artifactId>cdi-api</artifactId>
+            <version>${cdi-api.version}</version>
+            <scope>provided</scope>
+         </dependency>
       </dependencies>
    </dependencyManagement>
 


[2/2] activemq-artemis git commit: This closes #800

Posted by cl...@apache.org.
This closes #800


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

Branch: refs/heads/master
Commit: f10752b681c8b5094a87fc6645b338c0a5aed128
Parents: 507deb6 9163c67
Author: Clebert Suconic <cl...@apache.org>
Authored: Thu Sep 29 16:25:48 2016 -0400
Committer: Clebert Suconic <cl...@apache.org>
Committed: Thu Sep 29 16:25:48 2016 -0400

----------------------------------------------------------------------
 docs/user-manual/en/cdi-integration.md          |  32 +++++
 integration/artemis-cdi-integration/pom.xml     | 121 +++++++++++++++++++
 .../ArtemisClientConfiguration.java             |  76 ++++++++++++
 .../DefaultArtemisClientConfigurationImpl.java  |  95 +++++++++++++++
 .../client/cdi/extension/AnyLiteral.java        |  28 +++++
 .../cdi/extension/ArtemisClientConfigBean.java  |  99 +++++++++++++++
 .../ArtemisEmbeddedServerConfigBean.java        | 104 ++++++++++++++++
 .../client/cdi/extension/ArtemisExtension.java  |  62 ++++++++++
 .../client/cdi/extension/DefaultLiteral.java    |  28 +++++
 .../cdi/factory/ConnectionFactoryProvider.java  | 106 ++++++++++++++++
 .../client/cdi/logger/ActiveMQCDILogger.java    |  65 ++++++++++
 .../artemis/cdi/bootstrap/CDIBootstrapTest.java |  76 ++++++++++++
 pom.xml                                         |  62 +++++++++-
 13 files changed, 953 insertions(+), 1 deletion(-)
----------------------------------------------------------------------