activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1335599 - in /activemq/activemq-apollo/trunk: apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/ apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/ apollo-dto/src/main/java/org/apache/activ...
Date Tue, 08 May 2012 15:52:46 GMT
Author: chirino
Date: Tue May  8 15:52:45 2012
New Revision: 1335599

URL: http://svn.apache.org/viewvc?rev=1335599&view=rev
Log:
Fixes APLO-200 : Support configuring protocol filters

Added:
    activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/protocol-filter-factory.index
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ProtocolFilterDTO.java
      - copied, changed from r1330940, activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/Module.java
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/SimpleProtocolFilterDTO.java
Modified:
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/ProtocolFactory.scala
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/Module.java
    activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/jaxb.index
    activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/dto/StompDTO.java

Added: activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/protocol-filter-factory.index
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/protocol-filter-factory.index?rev=1335599&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/protocol-filter-factory.index
(added)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/protocol-filter-factory.index
Tue May  8 15:52:45 2012
@@ -0,0 +1,17 @@
+## ---------------------------------------------------------------------------
+## 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.
+## ---------------------------------------------------------------------------
+org.apache.activemq.apollo.broker.protocol.SimpleProtocolFilter2Factory
\ No newline at end of file

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/ProtocolFactory.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/ProtocolFactory.scala?rev=1335599&r1=1335598&r2=1335599&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/ProtocolFactory.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/protocol/ProtocolFactory.scala
Tue May  8 15:52:45 2012
@@ -19,9 +19,9 @@ package org.apache.activemq.apollo.broke
 import java.io.IOException
 import org.apache.activemq.apollo.broker.store.MessageRecord
 import org.fusesource.hawtdispatch._
-import org.apache.activemq.apollo.dto.ConnectionStatusDTO
 import org.apache.activemq.apollo.util.{Log, ClassFinder}
 import org.apache.activemq.apollo.broker.{Broker, Message, BrokerConnection}
+import org.apache.activemq.apollo.dto.{SimpleProtocolFilterDTO, ProtocolFilterDTO, ConnectionStatusDTO}
 
 trait ProtocolFactory {
   def create():Protocol
@@ -95,34 +95,56 @@ trait ProtocolFilter {
   def filter[T](command: T):T
 }
 
-object ProtocolFilter2 {
+object ProtocolFilter2Factory {
+
+  val providers = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/protocol-filter-factory.index",classOf[Provider])
 
-  def create_filters(clazzes:List[String], handler:ProtocolHandler) = {
-    clazzes.map { clazz =>
-      val filter = ProtocolFilter2(Broker.class_loader.loadClass(clazz).newInstance().asInstanceOf[AnyRef])
+  trait Provider {
+    def create( dto:ProtocolFilterDTO, handler:ProtocolHandler ):ProtocolFilter2
+  }
+
+  def create( dto:ProtocolFilterDTO, handler:ProtocolHandler ):ProtocolFilter2 = {
+    for( p <- providers.singletons ) {
+      val rc = p.create(dto, handler)
+      if( rc!=null ) {
+        return rc;
+      }  
+    }
+    throw new IllegalArgumentException("Cannot create a protocol filter for DTO: "+dto)
+  }
+}
 
-      type ProtocolHandlerAware = { var protocol_handler:ProtocolHandler }
+object SimpleProtocolFilter2Factory extends ProtocolFilter2Factory.Provider {
+  def create( dto:ProtocolFilterDTO, handler:ProtocolHandler ):ProtocolFilter2 = dto match
{
+    case dto:SimpleProtocolFilterDTO =>
+      val instance = Broker.class_loader.loadClass(dto.kind).newInstance().asInstanceOf[AnyRef]
+      val filter = instance match {
+        case self:ProtocolFilter2 => self
+        case self:ProtocolFilter => new ProtocolFilter2() {
+          override def filter_inbound[T](command: T): Option[T] = Some(self.filter(command))
+          override def filter_outbound[T](command: T): Option[T] = Some(command)
+        }
+        case null => null
+        case _ => throw new IllegalArgumentException("Invalid protocol filter type: "+instance.getClass)
+      }
+      type FilterDuckType = {
+        var protocol_handler:ProtocolHandler
+        var dto:SimpleProtocolFilterDTO
+      }
       try {
-        filter.asInstanceOf[ProtocolHandlerAware].protocol_handler = handler
+        filter.asInstanceOf[FilterDuckType].protocol_handler = handler
+      } catch { case _ => }
+      try {
+        filter.asInstanceOf[FilterDuckType].dto = dto
       } catch { case _ => }
-
       filter
-    }
+    case _ => null
   }
+}
 
-  /**
-   * Allows you to convert any ProtocolFilter object into a ProtocolFilter2 object.
-   */
-  def apply(filter:AnyRef):ProtocolFilter2 = {
-    filter match {
-      case self:ProtocolFilter2 => self
-      case self:ProtocolFilter => new ProtocolFilter2() {
-        override def filter_inbound[T](command: T): Option[T] = Some(self.filter(command))
-        override def filter_outbound[T](command: T): Option[T] = Some(command)
-      } 
-      case null => null
-      case _ => throw new IllegalArgumentException("Invalid protocol filter type: "+filter.getClass)
-    }
+object ProtocolFilter2 {
+  def create_filters(dtos:List[ProtocolFilterDTO], handler:ProtocolHandler) = {
+    dtos.map(ProtocolFilter2Factory.create(_, handler))
   }
 }
 

Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/Module.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/Module.java?rev=1335599&r1=1335598&r2=1335599&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/Module.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/Module.java
Tue May  8 15:52:45 2012
@@ -37,7 +37,8 @@ public class Module implements DtoModule
                 NullStoreDTO.class,
                 SimpleStoreStatusDTO.class,
                 DetectDTO.class,
-                UdpDTO.class
+                UdpDTO.class,
+                SimpleProtocolFilterDTO.class
         };
     }
 }

Copied: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ProtocolFilterDTO.java
(from r1330940, activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/Module.java)
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ProtocolFilterDTO.java?p2=activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ProtocolFilterDTO.java&p1=activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/Module.java&r1=1330940&r2=1335599&rev=1335599&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/Module.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ProtocolFilterDTO.java
Tue May  8 15:52:45 2012
@@ -16,28 +16,20 @@
  */
 package org.apache.activemq.apollo.dto;
 
-import org.apache.activemq.apollo.util.DtoModule;
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.annotate.JsonTypeInfo;
+import org.codehaus.jackson.map.annotate.JsonTypeIdResolver;
+
+import javax.xml.bind.annotation.*;
+import java.util.ArrayList;
+import java.util.List;
 
 /**
- * <p>
- * </p>
- *
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
  */
-public class Module implements DtoModule {
-    public String dto_package() {
-        return "org.apache.activemq.apollo.dto";
-    }
-    public Class<?>[] extension_classes() {
-        return new Class<?>[]{
-                AcceptingConnectorDTO.class,
-                TopicDestinationDTO.class,
-                DurableSubscriptionDestinationDTO.class,
-                QueueDestinationDTO.class,
-                NullStoreDTO.class,
-                SimpleStoreStatusDTO.class,
-                DetectDTO.class,
-                UdpDTO.class
-        };
-    }
+@XmlType (name = "protocol_filter_type")
+@JsonTypeInfo(use=JsonTypeInfo.Id.CUSTOM, include=JsonTypeInfo.As.PROPERTY, property="@class")
+@JsonTypeIdResolver(ApolloTypeIdResolver.class)
+@JsonIgnoreProperties(ignoreUnknown = true)
+abstract public class ProtocolFilterDTO {
 }

Added: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/SimpleProtocolFilterDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/SimpleProtocolFilterDTO.java?rev=1335599&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/SimpleProtocolFilterDTO.java
(added)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/SimpleProtocolFilterDTO.java
Tue May  8 15:52:45 2012
@@ -0,0 +1,69 @@
+/**
+ * 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.apollo.dto;
+
+import org.codehaus.jackson.annotate.JsonIgnoreProperties;
+import org.codehaus.jackson.annotate.JsonTypeInfo;
+import org.codehaus.jackson.map.annotate.JsonTypeIdResolver;
+
+import javax.xml.bind.annotation.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+@JsonTypeInfo(use=JsonTypeInfo.Id.CUSTOM, include=JsonTypeInfo.As.PROPERTY, property="@class")
+@JsonTypeIdResolver(ApolloTypeIdResolver.class)
+@JsonIgnoreProperties(ignoreUnknown = true)
+@XmlRootElement(name = "protocol_filter")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class SimpleProtocolFilterDTO extends ProtocolFilterDTO {
+
+    /**
+     */
+    @XmlAttribute
+    public String kind;
+
+    /**
+     * To hold any other non-matching XML elements
+     */
+    @XmlAnyElement(lax=true)
+    public List<Object> other = new ArrayList<Object>();
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (!(o instanceof SimpleProtocolFilterDTO)) return false;
+
+        SimpleProtocolFilterDTO that = (SimpleProtocolFilterDTO) o;
+
+        if (kind != null ? !kind.equals(that.kind) : that.kind != null)
+            return false;
+        if (other != null ? !other.equals(that.other) : that.other != null)
+            return false;
+
+        return true;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = kind != null ? kind.hashCode() : 0;
+        result = 31 * result + (other != null ? other.hashCode() : 0);
+        return result;
+    }
+}

Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/jaxb.index
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/jaxb.index?rev=1335599&r1=1335598&r2=1335599&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/jaxb.index
(original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/jaxb.index
Tue May  8 15:52:45 2012
@@ -46,6 +46,8 @@ MemoryMetricsDTO
 NullStoreDTO
 PrincipalDTO
 ProtocolDTO
+ProtocolFilterDTO
+SimpleProtocolFilterDTO
 QueueConsumerLinkDTO
 QueueDTO
 QueueDestinationDTO

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/dto/StompDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/dto/StompDTO.java?rev=1335599&r1=1335598&r2=1335599&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/dto/StompDTO.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/dto/StompDTO.java
Tue May  8 15:52:45 2012
@@ -18,6 +18,7 @@ package org.apache.activemq.apollo.stomp
 
 import org.apache.activemq.apollo.dto.AddUserHeaderDTO;
 import org.apache.activemq.apollo.dto.ProtocolDTO;
+import org.apache.activemq.apollo.dto.ProtocolFilterDTO;
 import org.codehaus.jackson.annotate.JsonIgnoreProperties;
 
 import javax.xml.bind.annotation.*;
@@ -67,11 +68,8 @@ public class StompDTO extends ProtocolDT
     @XmlAttribute(name="max_data_length")
     public String max_data_length;
 
-    /**
-     * A broker accepts connections via it's configured connectors.
-     */
-    @XmlElement(name="protocol_filter")
-    public List<String> protocol_filters = new ArrayList<String>();
+    @XmlElementRef
+    public List<ProtocolFilterDTO> protocol_filters = new ArrayList<ProtocolFilterDTO>();
 
     @XmlAttribute(name="queue_prefix")
     public String queue_prefix;



Mime
View raw message