activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject git commit: Implementing AMQ-4788 - make sure you can configure the partition broker plugin via activemq.xml
Date Mon, 07 Oct 2013 17:20:15 GMT
Updated Branches:
  refs/heads/trunk f88f2803a -> 21edf2b5b


Implementing AMQ-4788 - make sure you can configure the partition broker plugin via activemq.xml

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

Branch: refs/heads/trunk
Commit: 21edf2b5bb4e5a6b05429161eb5110ba33449c15
Parents: f88f280
Author: Hiram Chirino <hiram@hiramchirino.com>
Authored: Mon Oct 7 13:19:42 2013 -0400
Committer: Hiram Chirino <hiram@hiramchirino.com>
Committed: Mon Oct 7 13:19:42 2013 -0400

----------------------------------------------------------------------
 .../partition/PartitionBrokerPlugin.java        |  8 +++
 .../activemq/partition/dto/Partitioning.java    |  9 ++-
 .../apache/activemq/partition/dto/Target.java   |  2 -
 activemq-unit-tests/pom.xml                     |  4 ++
 .../partition/SpringPartitionBrokerTest.java    | 53 ++++++++++++++++++
 .../src/test/resources/activemq-partition.xml   | 58 ++++++++++++++++++++
 pom.xml                                         |  5 ++
 7 files changed, 135 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/21edf2b5/activemq-partition/src/main/java/org/apache/activemq/partition/PartitionBrokerPlugin.java
----------------------------------------------------------------------
diff --git a/activemq-partition/src/main/java/org/apache/activemq/partition/PartitionBrokerPlugin.java
b/activemq-partition/src/main/java/org/apache/activemq/partition/PartitionBrokerPlugin.java
index 936d2ea..815687f 100644
--- a/activemq-partition/src/main/java/org/apache/activemq/partition/PartitionBrokerPlugin.java
+++ b/activemq-partition/src/main/java/org/apache/activemq/partition/PartitionBrokerPlugin.java
@@ -19,6 +19,9 @@ package org.apache.activemq.partition;
 import org.apache.activemq.broker.Broker;
 import org.apache.activemq.broker.BrokerPlugin;
 import org.apache.activemq.partition.dto.Partitioning;
+import org.codehaus.jackson.JsonParseException;
+
+import java.io.IOException;
 
 /**
  * A BrokerPlugin which partitions client connections over a cluster of brokers.
@@ -50,4 +53,9 @@ public class PartitionBrokerPlugin implements BrokerPlugin {
     public void setConfig(Partitioning config) {
         this.config = config;
     }
+
+    public void setConfigAsJson(String config) throws IOException {
+        this.config = Partitioning.MAPPER.readValue(config, Partitioning.class);
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/activemq/blob/21edf2b5/activemq-partition/src/main/java/org/apache/activemq/partition/dto/Partitioning.java
----------------------------------------------------------------------
diff --git a/activemq-partition/src/main/java/org/apache/activemq/partition/dto/Partitioning.java
b/activemq-partition/src/main/java/org/apache/activemq/partition/dto/Partitioning.java
index 299d73b..8c339b4 100644
--- a/activemq-partition/src/main/java/org/apache/activemq/partition/dto/Partitioning.java
+++ b/activemq-partition/src/main/java/org/apache/activemq/partition/dto/Partitioning.java
@@ -20,6 +20,7 @@ import org.codehaus.jackson.annotate.JsonProperty;
 import org.codehaus.jackson.map.DeserializationConfig;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.codehaus.jackson.map.SerializationConfig;
+import org.codehaus.jackson.map.annotate.JsonDeserialize;
 import org.codehaus.jackson.map.annotate.JsonSerialize;
 
 import java.io.IOException;
@@ -27,8 +28,6 @@ import java.util.HashMap;
 
 /**
  * The main Configuration class for the PartitionBroker plugin
- *
- * @org.apache.xbean.XBean element="partitioning"
  */
 public class Partitioning {
 
@@ -50,6 +49,7 @@ public class Partitioning {
      * to the partition target immediately.
      */
     @JsonProperty("by_client_id")
+    @JsonDeserialize(contentAs = Target.class)
     public HashMap<String, Target> byClientId;
 
     /**
@@ -58,6 +58,7 @@ public class Partitioning {
      * to the partition target immediately.
      */
     @JsonProperty("by_user_name")
+    @JsonDeserialize(contentAs = Target.class)
     public HashMap<String, Target> byUserName;
 
     /**
@@ -66,6 +67,7 @@ public class Partitioning {
      * to the partition target immediately.
      */
     @JsonProperty("by_source_ip")
+    @JsonDeserialize(contentAs = Target.class)
     public HashMap<String, Target> bySourceIp;
 
     /**
@@ -75,6 +77,7 @@ public class Partitioning {
      * will be reconnected to the appropriate target.
      */
     @JsonProperty("by_queue")
+    @JsonDeserialize(contentAs = Target.class)
     public HashMap<String, Target> byQueue;
 
     /**
@@ -84,12 +87,14 @@ public class Partitioning {
      * will be reconnected to the appropriate target.
      */
     @JsonProperty("by_topic")
+    @JsonDeserialize(contentAs = Target.class)
     public HashMap<String, Target> byTopic;
 
     /**
      * Maps broker names to broker URLs.
      */
     @JsonProperty("brokers")
+    @JsonDeserialize(contentAs = String.class)
     public HashMap<String, String> brokers;
 
 

http://git-wip-us.apache.org/repos/asf/activemq/blob/21edf2b5/activemq-partition/src/main/java/org/apache/activemq/partition/dto/Target.java
----------------------------------------------------------------------
diff --git a/activemq-partition/src/main/java/org/apache/activemq/partition/dto/Target.java
b/activemq-partition/src/main/java/org/apache/activemq/partition/dto/Target.java
index b6f0ee2..2087f17 100644
--- a/activemq-partition/src/main/java/org/apache/activemq/partition/dto/Target.java
+++ b/activemq-partition/src/main/java/org/apache/activemq/partition/dto/Target.java
@@ -26,8 +26,6 @@ import java.util.HashSet;
 /**
  * Represents a partition target.  This identifies the brokers that
  * a partition lives on.
- *
- * @org.apache.xbean.XBean element="target"
  */
 public class Target {
 

http://git-wip-us.apache.org/repos/asf/activemq/blob/21edf2b5/activemq-unit-tests/pom.xml
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/pom.xml b/activemq-unit-tests/pom.xml
index cff5289..22e162a 100755
--- a/activemq-unit-tests/pom.xml
+++ b/activemq-unit-tests/pom.xml
@@ -71,6 +71,10 @@
       <artifactId>activemq-amqp</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.apache.activemq</groupId>
+      <artifactId>activemq-partition</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.geronimo.specs</groupId>
       <artifactId>geronimo-jms_1.1_spec</artifactId>
     </dependency>

http://git-wip-us.apache.org/repos/asf/activemq/blob/21edf2b5/activemq-unit-tests/src/test/java/org/apache/activemq/broker/partition/SpringPartitionBrokerTest.java
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/broker/partition/SpringPartitionBrokerTest.java
b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/partition/SpringPartitionBrokerTest.java
new file mode 100644
index 0000000..dcf4e69
--- /dev/null
+++ b/activemq-unit-tests/src/test/java/org/apache/activemq/broker/partition/SpringPartitionBrokerTest.java
@@ -0,0 +1,53 @@
+/**
+ * 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.broker.partition;
+
+import junit.framework.TestCase;
+import org.apache.activemq.broker.BrokerFactory;
+import org.apache.activemq.broker.BrokerService;
+import org.apache.activemq.partition.PartitionBrokerPlugin;
+import org.apache.activemq.partition.dto.Partitioning;
+
+/**
+ */
+public class SpringPartitionBrokerTest extends TestCase {
+
+    public void testCreatePartitionBroker() throws Exception {
+
+        BrokerService broker = BrokerFactory.createBroker("xbean:activemq-partition.xml");
+        assertEquals(1, broker.getPlugins().length);
+        PartitionBrokerPlugin plugin = (PartitionBrokerPlugin)broker.getPlugins()[0];
+        Partitioning config = plugin.getConfig();
+        assertEquals(2,  config.getBrokers().size());
+
+        Object o;
+        String json = "{\n" +
+        "  \"by_client_id\":{\n" +
+        "    \"client1\":{\"ids\":[\"broker1\"]},\n" +
+        "    \"client2\":{\"ids\":[\"broker1\",\"broker2\"]}\n" +
+        "  },\n" +
+        "  \"brokers\":{\n" +
+        "    \"broker1\":\"tcp://localhost:61616\",\n" +
+        "    \"broker2\":\"tcp://localhost:61616\"\n" +
+        "  }\n" +
+        "}";
+        Partitioning expected = Partitioning.MAPPER.readValue(json, Partitioning.class);
+        assertEquals(expected.toString(), config.toString());
+
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/activemq/blob/21edf2b5/activemq-unit-tests/src/test/resources/activemq-partition.xml
----------------------------------------------------------------------
diff --git a/activemq-unit-tests/src/test/resources/activemq-partition.xml b/activemq-unit-tests/src/test/resources/activemq-partition.xml
new file mode 100755
index 0000000..4bb96f2
--- /dev/null
+++ b/activemq-unit-tests/src/test/resources/activemq-partition.xml
@@ -0,0 +1,58 @@
+<?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.
+-->
+<!-- START SNIPPET: xbean -->
+<beans 
+  xmlns="http://www.springframework.org/schema/beans" 
+  xmlns:amq="http://activemq.apache.org/schema/core"
+  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
+  http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
+ 
+  <bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
+
+  <bean id="config" class="java.lang.String">
+    <constructor-arg><value>
+    <![CDATA[
+      {
+        "by_client_id":{
+          "client1":{"ids":["broker1"]},
+          "client2":{"ids":["broker1","broker2"]}
+        },
+        "brokers":{
+          "broker1":"tcp://localhost:61616",
+          "broker2":"tcp://localhost:61616"
+        }
+      }
+    ]]>
+    </value></constructor-arg>
+  </bean>
+
+  <broker useJmx="false"  xmlns="http://activemq.apache.org/schema/core" persistent="false">
+
+    <plugins>
+      <partitionBrokerPlugin minTransferCount="5" configAsJson="#config"/>
+    </plugins>
+
+    <transportConnectors>
+      <transportConnector uri="tcp://localhost:61616"/>
+    </transportConnectors>
+        
+  </broker>
+  
+</beans>
+<!-- END SNIPPET: xbean -->

http://git-wip-us.apache.org/repos/asf/activemq/blob/21edf2b5/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 19b6c64..de0673a 100755
--- a/pom.xml
+++ b/pom.xml
@@ -348,6 +348,11 @@
       </dependency>
       <dependency>
         <groupId>org.apache.activemq</groupId>
+        <artifactId>activemq-partition</artifactId>
+        <version>${project.version}</version>
+      </dependency>
+      <dependency>
+        <groupId>org.apache.activemq</groupId>
         <artifactId>activemq-unit-tests</artifactId>
         <version>${project.version}</version>
         <type>test-jar</type>


Mime
View raw message