activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1157667 - 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/ apollo-broker/src/main/scala/org/apache/activemq/a...
Date Sun, 14 Aug 2011 21:02:24 GMT
Author: chirino
Date: Sun Aug 14 21:02:23 2011
New Revision: 1157667

URL: http://svn.apache.org/viewvc?rev=1157667&view=rev
Log:
Support pluggable connector and virtual host implementations.  Drop the pluggable router implementation
support since that's just a implementation detail of the pluggable virtual host.

Added:
    activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/connector-factory.index
    activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/virtual-host-factory.index
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/AcceptingConnectorDTO.java
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ConnectorTypeDTO.java
Removed:
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ConnectorDTO.java
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/RouterDTO.java
Modified:
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Router.scala
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/VirtualHost.scala
    activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/transport/VMTransport.scala
    activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/jaxb/XMLBrokerFactoryTest.scala
    activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/perf/BrokerPerfSupport.scala
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/BrokerDTO.java
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/VirtualHostDTO.java
    activemq/activemq-apollo/trunk/apollo-dto/src/main/resources/org/apache/activemq/apollo/dto/jaxb.index
    activemq/activemq-apollo/trunk/apollo-dto/src/test/java/org/apache/activemq/apollo/dto/XmlCodecTest.java
    activemq/activemq-apollo/trunk/apollo-dto/src/test/resources/org/apache/activemq/apollo/dto/XmlCodecTest.xml
    activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireProtocolHandler.scala
    activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
    activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/dto/XmlCodecTest.java
    activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala

Added: activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/connector-factory.index
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/connector-factory.index?rev=1157667&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/connector-factory.index
(added)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/connector-factory.index
Sun Aug 14 21:02:23 2011
@@ -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.AcceptingConnectorFactory

Added: activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/virtual-host-factory.index
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/virtual-host-factory.index?rev=1157667&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/virtual-host-factory.index
(added)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/virtual-host-factory.index
Sun Aug 14 21:02:23 2011
@@ -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.DefaultVirtualHostFactory

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Broker.scala
Sun Aug 14 21:02:23 2011
@@ -220,7 +220,7 @@ class Broker() extends BaseService {
     rc
   })
   config.connectors.add({
-    val rc = new ConnectorDTO
+    val rc = new AcceptingConnectorDTO()
     rc.id = "default"
     rc.bind = "tcp://0.0.0.0:0"
     rc
@@ -380,28 +380,44 @@ class Broker() extends BaseService {
             virtual_hosts_by_hostname.remove(ascii(name))
           }
 
-          host.update(config, tracker.task("update: "+host))
+          if( host.config.getClass == config.getClass ) {
+            host.update(config, tracker.task("update: "+host))
+            config.host_names.foreach { name =>
+              virtual_hosts_by_hostname += ascii(name) -> host
+            }
+          } else {
+            // The dto type changed.. so we have to re-create
+            val on_completed = tracker.task("recreate virtual host: "+id)
+            host.stop(^{
+              val host = VirtualHostFactory.create(this, config)
+              if( host == null ) {
+                console_log.warn("Could not create virtual host: "+config.id);
+                on_completed.run()
+              } else {
+                config.host_names.foreach { name =>
+                  virtual_hosts_by_hostname += ascii(name) -> host
+                }
+                host.start(on_completed)
+              }
+            })
 
-          config.host_names.foreach { name =>
-            virtual_hosts_by_hostname += ascii(name) -> host
           }
-
         }
       }
 
       added.foreach { id=>
         for( config <- host_config_by_id.get(id) ) {
-
-          val host = new VirtualHost(this, config.id)
-          host.config = config
-          virtual_hosts += ascii(config.id) -> host
-
-          // add all the host names of the virtual host to the virtual_hosts_by_hostname
map..
-          config.host_names.foreach { name =>
-            virtual_hosts_by_hostname += ascii(name) -> host
+          val host = VirtualHostFactory.create(this, config)
+          if( host == null ) {
+            console_log.warn("Could not create virtual host: "+config.id);
+          } else {
+            virtual_hosts += ascii(config.id) -> host
+            // add all the host names of the virtual host to the virtual_hosts_by_hostname
map..
+            config.host_names.foreach { name =>
+              virtual_hosts_by_hostname += ascii(name) -> host
+            }
+            tracker.start(host)
           }
-
-          tracker.start(host)
         }
       }
     }
@@ -412,12 +428,13 @@ class Broker() extends BaseService {
     }
 
 
-    val connector_config_by_id = HashMap[String, ConnectorDTO]()
+    val connector_config_by_id = HashMap[String, ConnectorTypeDTO]()
     config.connectors.foreach{ value =>
       connector_config_by_id += value.id -> value
     }
 
     diff(connectors.keySet.toSet, connector_config_by_id.keySet.toSet) match { case (added,
updated, removed) =>
+
       removed.foreach { id =>
         for( connector <- connectors.remove(id) ) {
           tracker.stop(connector)
@@ -426,16 +443,34 @@ class Broker() extends BaseService {
 
       updated.foreach { id=>
         for( connector <- connectors.get(id); config <- connector_config_by_id.get(id)
) {
-          connector.update(config,  tracker.task("update: "+connector))
+          if( connector.config.getClass == config.getClass ) {
+            connector.update(config,  tracker.task("update: "+connector))
+          } else {
+            // The dto type changed.. so we have to re-create the connector.
+            val on_completed = tracker.task("recreate connector: "+id)
+            connector.stop(^{
+              val connector = ConnectorFactory.create(this, config)
+              if( connector == null ) {
+                console_log.warn("Could not create connector: "+config.id);
+                on_completed.run()
+              } else {
+                connectors += config.id -> connector
+                connector.start(on_completed)
+              }
+            })
+          }
         }
       }
 
       added.foreach { id=>
         for( config <- connector_config_by_id.get(id) ) {
-          val connector = new AcceptingConnector(this, config.id)
-          connector.config = config
-          connectors += config.id -> connector
-          tracker.start(connector)
+          val connector = ConnectorFactory.create(this, config)
+          if( connector == null ) {
+            console_log.warn("Could not create connector: "+config.id);
+          } else {
+            connectors += config.id -> connector
+            tracker.start(connector)
+          }
         }
       }
     }
@@ -463,6 +498,7 @@ class Broker() extends BaseService {
               val service = CustomServiceFactory.create(this, new_dto)
               if( service == null ) {
                 console_log.warn("Could not create service: "+new_dto.id);
+                task.run()
               } else {
                 // start it again..
                 services += new_dto.id -> (new_dto, service)

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Connector.scala
Sun Aug 14 21:02:23 2011
@@ -18,13 +18,13 @@ package org.apache.activemq.apollo.broke
 
 import org.fusesource.hawtdispatch._
 import org.fusesource.hawtdispatch.{Dispatch}
-import org.apache.activemq.apollo.dto.{ConnectorDTO}
 import protocol.{ProtocolFactory, Protocol}
 import org.apache.activemq.apollo.transport._
 import org.apache.activemq.apollo.util._
 import org.apache.activemq.apollo.util.OptionSupport._
 import java.net.SocketAddress
-
+import org.apache.activemq.apollo.util.{Log, Service, ClassFinder}
+import org.apache.activemq.apollo.dto._
 
 /**
  * <p>
@@ -40,12 +40,57 @@ trait Connector extends BaseService {
   def broker:Broker
   def id:String
   def stopped(connection:BrokerConnection):Unit
-  def config:ConnectorDTO
+  def config:ConnectorTypeDTO
   def accepted:LongCounter
   def connected:LongCounter
-  def update(config: ConnectorDTO, on_complete:Runnable):Unit
+  def update(config: ConnectorTypeDTO, on_complete:Runnable):Unit
   def socket_address:SocketAddress
+  def status:ServiceStatusDTO
+}
+
+/**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+object ConnectorFactory {
+
+  trait Provider {
+    def create(broker:Broker, dto:ConnectorTypeDTO):Connector
+  }
+
+  val providers = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/connector-factory.index",classOf[Provider])
+
+  def create(broker:Broker, dto:ConnectorTypeDTO):Connector = {
+    if( dto == null ) {
+      return null
+    }
+    providers.singletons.foreach { provider=>
+      val connector = provider.create(broker, dto)
+      if( connector!=null ) {
+        return connector;
+      }
+    }
+    return null
+  }
+}
+
+object AcceptingConnectorFactory extends ConnectorFactory.Provider with Log {
 
+  def create(broker: Broker, dto: ConnectorTypeDTO): Connector = dto match {
+    case dto:AcceptingConnectorDTO =>
+      if( dto.getClass != classOf[AcceptingConnectorDTO] ) {
+        // ignore sub classes of AcceptingConnectorDTO
+        null;
+      } else {
+        val rc = new AcceptingConnector(broker, dto.id)
+        rc.config = dto
+        rc
+      }
+    case _ =>
+      null
+  }
 }
 
 /**
@@ -60,7 +105,7 @@ class AcceptingConnector(val broker:Brok
 
   override val dispatch_queue = broker.dispatch_queue
 
-  var config:ConnectorDTO = new ConnectorDTO
+  var config = new AcceptingConnectorDTO
   config.id = id
   config.bind = "tcp://0.0.0.:0"
 
@@ -73,6 +118,20 @@ class AcceptingConnector(val broker:Brok
 
   def socket_address = Option(transport_server).map(_.getSocketAddress).getOrElse(null)
 
+  def status = {
+    val result = new ConnectorStatusDTO
+    result.id = id.toString
+    result.state = service_state.toString
+    result.state_since = service_state.since
+    result.connection_counter = accepted.get
+    result.connected = connected.get
+    result.protocol = Option(config.protocol).getOrElse("any")
+    result.local_address = Option(socket_address).map(_.toString).getOrElse("any")
+    result
+  }
+
+
+
   object BrokerAcceptListener extends TransportAcceptListener {
     def onAcceptError(e: Exception): Unit = {
       warn(e, "Error occured while accepting client connection.")
@@ -115,15 +174,15 @@ class AcceptingConnector(val broker:Brok
 
   /**
    */
-  def update(config: ConnectorDTO, on_completed:Runnable) = dispatch_queue {
+  def update(config: ConnectorTypeDTO, on_completed:Runnable) = dispatch_queue {
     if ( !service_state.is_started || this.config == config ) {
-      this.config = config
+      this.config = config.asInstanceOf[AcceptingConnectorDTO]
       on_completed.run
     } else {
       // if the connector config is updated.. lets stop, apply config, then restart
       // the connector.
       stop(^{
-        this.config = config
+        this.config = config.asInstanceOf[AcceptingConnectorDTO]
         start(on_completed)
       })
     }

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Router.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Router.scala?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Router.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/Router.scala
Sun Aug 14 21:02:23 2011
@@ -50,37 +50,6 @@ trait Router extends Service {
 }
 
 /**
- * <p>
- * </p>
- *
- * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
- */
-object RouterFactory {
-
-  trait Provider {
-    def create(host:VirtualHost):Router
-  }
-
-  val providers = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/router-factory.index",
classOf[Provider])
-
-  def create(host:VirtualHost):Router = {
-    val config = host.config.router;
-    if( config==null ) {
-      return new LocalRouter(host)
-    }
-    providers.singletons.foreach { provider=>
-      val rc = provider.create(host)
-      if( rc!=null ) {
-        return rc
-      }
-    }
-    throw new IllegalArgumentException("Uknonwn router type: "+config.getClass)
-  }
-
-}
-
-
-/**
  * An object which produces deliveries to which allows new DeliveryConsumer
  * object to bind so they can also receive those deliveries.
  *

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/VirtualHost.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/VirtualHost.scala?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/VirtualHost.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/VirtualHost.scala
Sun Aug 14 21:02:23 2011
@@ -34,6 +34,51 @@ import org.apache.activemq.apollo.broker
 import org.apache.activemq.apollo.dto._
 
 /**
+ * <p>
+ * </p>
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+object VirtualHostFactory {
+
+  trait Provider {
+    def create(broker:Broker, dto:VirtualHostDTO):VirtualHost
+  }
+
+  val providers = new ClassFinder[Provider]("META-INF/services/org.apache.activemq.apollo/virtual-host-factory.index",classOf[Provider])
+
+  def create(broker:Broker, dto:VirtualHostDTO):VirtualHost = {
+    if( dto == null ) {
+      return null
+    }
+    providers.singletons.foreach { provider=>
+      val connector = provider.create(broker, dto)
+      if( connector!=null ) {
+        return connector;
+      }
+    }
+    return null
+  }
+}
+
+object DefaultVirtualHostFactory extends VirtualHostFactory.Provider with Log {
+
+  def create(broker: Broker, dto: VirtualHostDTO): VirtualHost = dto match {
+    case dto:VirtualHostDTO =>
+      if( dto.getClass != classOf[VirtualHostDTO] ) {
+        // ignore sub classes of AcceptingVirtualHostDTO
+        null;
+      } else {
+        val rc = new VirtualHost(broker, dto.id)
+        rc.config = dto
+        rc
+      }
+    case _ =>
+      null
+  }
+}
+
+/**
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
  */
 object VirtualHost extends Log {
@@ -48,7 +93,7 @@ class VirtualHost(val broker: Broker, va
   override val dispatch_queue:DispatchQueue = createQueue("virtual-host") // getGlobalQueue(DispatchPriority.HIGH).createQueue("virtual-host")
 
   var config:VirtualHostDTO = _
-  var router:Router = _
+  val router:Router = new LocalRouter(this)
 
   var names:List[String] = Nil;
 
@@ -77,7 +122,7 @@ class VirtualHost(val broker: Broker, va
     } else {
 
       // in some cases we have to restart the virtual host..
-      if( config.store != this.config.store || config.router != this.config.router) {
+      if( config.store != this.config.store ) {
         stop(^{
           this.config = config
           start(on_completed)
@@ -117,10 +162,8 @@ class VirtualHost(val broker: Broker, va
   }
 
   override protected def _start(on_completed:Runnable):Unit = {
-
     apply_update
 
-    router = RouterFactory.create(this)
     store = StoreFactory.create(config.store)
 
     val tracker = new LoggingTracker("virtual host startup", console_log)

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/transport/VMTransport.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/transport/VMTransport.scala?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/transport/VMTransport.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/transport/VMTransport.scala
Sun Aug 14 21:02:23 2011
@@ -30,8 +30,7 @@ import org.apache.activemq.apollo.transp
 import org.apache.activemq.apollo.transport.pipe.PipeTransportServer
 import org.apache.activemq.apollo.util._
 import java.lang.String
-import org.apache.activemq.apollo.dto.ConnectorDTO
-
+import org.apache.activemq.apollo.dto.{AcceptingConnectorDTO, ConnectorTypeDTO}
 
 /**
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
@@ -128,7 +127,7 @@ class VMTransportFactory extends PipeTra
       if (server == null && create) {
 
         // This is the connector that the broker needs.
-        val connector = new ConnectorDTO
+        val connector = new AcceptingConnectorDTO
         connector.id = "vm"
         connector.bind = "vm://" + name
 
@@ -143,7 +142,11 @@ class VMTransportFactory extends PipeTra
           // Use the user specified config
           broker = BrokerFactory.createBroker(brokerURI);
           // we need to add in the connector if it was not in the config...
-          if (broker.config.connectors.toList.filter(_.bind == connector.bind).isEmpty) {
+          val found = broker.config.connectors.toList.find { _ match {
+            case dto:AcceptingConnectorDTO=> dto.bind == connector.bind
+            case _ => false
+          }}
+          if (found.isEmpty) {
             broker.config.connectors.add(connector)
           }
         }

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/jaxb/XMLBrokerFactoryTest.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/jaxb/XMLBrokerFactoryTest.scala?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/jaxb/XMLBrokerFactoryTest.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/jaxb/XMLBrokerFactoryTest.scala
Sun Aug 14 21:02:23 2011
@@ -18,6 +18,7 @@ package org.apache.activemq.apollo.broke
 
 import org.apache.activemq.apollo.broker.BrokerFactory
 import org.apache.activemq.apollo.util.FunSuiteSupport
+import org.apache.activemq.apollo.dto.AcceptingConnectorDTO
 
 /**
  * <p>
@@ -36,11 +37,11 @@ class XMLBrokerFactoryTest extends FunSu
     }
 
     expect("pipe://test1") {
-      broker.config.connectors.get(0).bind
+      broker.config.connectors.get(0).asInstanceOf[AcceptingConnectorDTO].bind
     }
 
     expect("tcp://127.0.0.1:61616") {
-      broker.config.connectors.get(1).bind
+      broker.config.connectors.get(1).asInstanceOf[AcceptingConnectorDTO].bind
     }
 
     expect(2) {

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/perf/BrokerPerfSupport.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/perf/BrokerPerfSupport.scala?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/perf/BrokerPerfSupport.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/test/scala/org/apache/activemq/apollo/broker/perf/BrokerPerfSupport.scala
Sun Aug 14 21:02:23 2011
@@ -27,7 +27,7 @@ import org.fusesource.hawtbuf.AsciiBuffe
 import java.net.URL
 import org.apache.activemq.apollo.util._
 import collection.mutable.{ArrayBuffer, ListBuffer}
-import org.apache.activemq.apollo.dto.{DestinationDTO, BrokerDTO}
+import org.apache.activemq.apollo.dto.{AcceptingConnectorDTO, DestinationDTO, BrokerDTO}
 
 /**
  *
@@ -199,7 +199,7 @@ abstract class BrokerPerfSupport extends
 
   def createBrokerConfig(name: String, bindURI: String, connectUri: String): BrokerDTO =
{
     val config = (new Broker).config
-    val connector = config.connectors.get(0)
+    val connector = config.connectors.get(0).asInstanceOf[AcceptingConnectorDTO]
     connector.bind = bindURI
     connector.protocol = getBrokerProtocolName
 

Added: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/AcceptingConnectorDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/AcceptingConnectorDTO.java?rev=1157667&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/AcceptingConnectorDTO.java
(added)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/AcceptingConnectorDTO.java
Sun Aug 14 21:02:23 2011
@@ -0,0 +1,74 @@
+/**
+ * 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 javax.xml.bind.annotation.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+@XmlRootElement(name = "connector")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class AcceptingConnectorDTO extends ConnectorTypeDTO {
+
+  /**
+   * The transport uri which it will accept connections on.
+   */
+  @XmlAttribute
+  public String bind;
+
+  /**
+   * The protocol that the transport will use.
+   */
+  @XmlAttribute
+  public String protocol;
+
+  /**
+   * A broker accepts connections via it's configured connectors.
+   */
+  @XmlElementRef
+  public List<ProtocolDTO> protocols = new ArrayList<ProtocolDTO>();
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) return true;
+    if (!(o instanceof AcceptingConnectorDTO)) return false;
+    if (!super.equals(o)) return false;
+
+    AcceptingConnectorDTO that = (AcceptingConnectorDTO) o;
+
+    if (bind != null ? !bind.equals(that.bind) : that.bind != null)
+      return false;
+    if (protocol != null ? !protocol.equals(that.protocol) : that.protocol != null)
+      return false;
+    if (protocols != null ? !protocols.equals(that.protocols) : that.protocols != null)
+      return false;
+
+    return true;
+  }
+
+  @Override
+  public int hashCode() {
+    int result = super.hashCode();
+    result = 31 * result + (bind != null ? bind.hashCode() : 0);
+    result = 31 * result + (protocol != null ? protocol.hashCode() : 0);
+    result = 31 * result + (protocols != null ? protocols.hashCode() : 0);
+    return result;
+  }
+}
\ No newline at end of file

Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/BrokerDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/BrokerDTO.java?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/BrokerDTO.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/BrokerDTO.java
Sun Aug 14 21:02:23 2011
@@ -38,14 +38,14 @@ public class BrokerDTO {
     /**
      * A broker can service many virtual hosts.
      */
-    @XmlElement(name="virtual_host")
+    @XmlElementRef
     public List<VirtualHostDTO> virtual_hosts = new ArrayList<VirtualHostDTO>();
 
     /**
      * A broker accepts connections via it's configured connectors.
      */
-    @XmlElement(name="connector")
-    public List<ConnectorDTO> connectors = new ArrayList<ConnectorDTO>();
+    @XmlElementRef
+    public List<ConnectorTypeDTO> connectors = new ArrayList<ConnectorTypeDTO>();
 
     /**
      * The clients should use to connect to this

Added: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ConnectorTypeDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ConnectorTypeDTO.java?rev=1157667&view=auto
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ConnectorTypeDTO.java
(added)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/ConnectorTypeDTO.java
Sun Aug 14 21:02:23 2011
@@ -0,0 +1,73 @@
+/**
+ * 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.JsonTypeInfo;
+
+import javax.xml.bind.annotation.*;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ *
+ * 
+ *
+ * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
+ */
+@XmlType (name = "connector_type")
+@XmlAccessorType(XmlAccessType.FIELD)
+@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
+abstract public class ConnectorTypeDTO extends ServiceDTO {
+
+  @XmlElement(name="acl")
+  public ConnectorAclDTO acl;
+
+  @XmlAttribute(name="connection_limit")
+  public Integer connection_limit;
+
+//  /**
+//   * 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 ConnectorTypeDTO)) return false;
+//    if (!super.equals(o)) return false;
+//
+//    ConnectorTypeDTO that = (ConnectorTypeDTO) o;
+//
+//    if (acl != null ? !acl.equals(that.acl) : that.acl != null) return false;
+//    if (connection_limit != null ? !connection_limit.equals(that.connection_limit) : that.connection_limit
!= null)
+//      return false;
+//    if (other != null ? !other.equals(that.other) : that.other != null)
+//      return false;
+//
+//    return true;
+//  }
+//
+//  @Override
+//  public int hashCode() {
+//    int result = super.hashCode();
+//    result = 31 * result + (acl != null ? acl.hashCode() : 0);
+//    result = 31 * result + (connection_limit != null ? connection_limit.hashCode() : 0);
+//    result = 31 * result + (other != null ? other.hashCode() : 0);
+//    return result;
+//  }
+}
\ No newline at end of file

Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/VirtualHostDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/VirtualHostDTO.java?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/VirtualHostDTO.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/VirtualHostDTO.java
Sun Aug 14 21:02:23 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.activemq.apollo.dto;
 
+import org.codehaus.jackson.annotate.JsonTypeInfo;
+
 import java.util.ArrayList;
 import java.util.List;
 
@@ -26,6 +28,7 @@ import javax.xml.bind.annotation.*;
  */
 @XmlRootElement(name = "virtual_host")
 @XmlAccessorType(XmlAccessType.FIELD)
+@JsonTypeInfo(use=JsonTypeInfo.Id.CLASS, include=JsonTypeInfo.As.PROPERTY, property="@class")
 public class VirtualHostDTO extends ServiceDTO {
 
     @XmlElement(name="host_name", required=true)
@@ -77,9 +80,6 @@ public class VirtualHostDTO extends Serv
     @XmlElement(name="authentication")
     public AuthenticationDTO authentication;
 
-    @XmlElementRef
-    public RouterDTO router;
-
     @XmlElement(name="log_category")
     public LogCategoryDTO log_category;
 
@@ -111,7 +111,6 @@ public class VirtualHostDTO extends Serv
         if (queues != null ? !queues.equals(that.queues) : that.queues != null) return false;
         if (regroup_connections != null ? !regroup_connections.equals(that.regroup_connections)
: that.regroup_connections != null)
             return false;
-        if (router != null ? !router.equals(that.router) : that.router != null) return false;
         if (store != null ? !store.equals(that.store) : that.store != null) return false;
         if (topics != null ? !topics.equals(that.topics) : that.topics != null) return false;
 
@@ -131,7 +130,6 @@ public class VirtualHostDTO extends Serv
         result = 31 * result + (regroup_connections != null ? regroup_connections.hashCode()
: 0);
         result = 31 * result + (acl != null ? acl.hashCode() : 0);
         result = 31 * result + (authentication != null ? authentication.hashCode() : 0);
-        result = 31 * result + (router != null ? router.hashCode() : 0);
         result = 31 * result + (log_category != null ? log_category.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=1157667&r1=1157666&r2=1157667&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
Sun Aug 14 21:02:23 2011
@@ -17,7 +17,7 @@
 BrokerDTO
 BrokerStatusDTO
 ConnectionStatusDTO
-ConnectorDTO
+AcceptingConnectorDTO
 ConnectorStatusDTO
 TopicStatusDTO
 EntryStatusDTO

Modified: activemq/activemq-apollo/trunk/apollo-dto/src/test/java/org/apache/activemq/apollo/dto/XmlCodecTest.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/test/java/org/apache/activemq/apollo/dto/XmlCodecTest.java?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/test/java/org/apache/activemq/apollo/dto/XmlCodecTest.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/test/java/org/apache/activemq/apollo/dto/XmlCodecTest.java
Sun Aug 14 21:02:23 2011
@@ -55,6 +55,10 @@ public class XmlCodecTest {
         assertTrue(dto.acl.admins.contains(new PrincipalDTO("hiram")));
         assertTrue(dto.acl.admins.contains(new PrincipalDTO("james")));
         assertTrue(dto.acl.admins.contains(new PrincipalDTO("admins", "org.apache.activemq.jaas.GroupPrincipal")));
+
+        AcceptingConnectorDTO connector = (AcceptingConnectorDTO)dto.connectors.get(0);
+        assertNotNull(connector);
+
     }
 
 
@@ -68,7 +72,7 @@ public class XmlCodecTest {
         host.host_names.add("example.com");
         broker.virtual_hosts.add(host);
 
-        ConnectorDTO connector = new ConnectorDTO();
+        AcceptingConnectorDTO connector = new AcceptingConnectorDTO();
         connector.id = "port-61616";
         connector.bind = "tcp://0.0.0.0:61616";
         broker.connectors.add(connector);

Modified: activemq/activemq-apollo/trunk/apollo-dto/src/test/resources/org/apache/activemq/apollo/dto/XmlCodecTest.xml
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/test/resources/org/apache/activemq/apollo/dto/XmlCodecTest.xml?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/test/resources/org/apache/activemq/apollo/dto/XmlCodecTest.xml
(original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/test/resources/org/apache/activemq/apollo/dto/XmlCodecTest.xml
Sun Aug 14 21:02:23 2011
@@ -36,4 +36,6 @@
 
   <topic id="topic1"/>
 
+  <connector id="tcp" bind="tcp://0.0.0.0:61613"/>
+
 </broker>

Modified: activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireProtocolHandler.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireProtocolHandler.scala?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireProtocolHandler.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-openwire/src/main/scala/org/apache/activemq/apollo/openwire/OpenwireProtocolHandler.scala
Sun Aug 14 21:02:23 2011
@@ -40,7 +40,7 @@ import tcp.TcpTransport
 import codec.OpenWireFormat
 import command._
 import org.apache.activemq.apollo.openwire.dto.{OpenwireConnectionStatusDTO,OpenwireDTO}
-import org.apache.activemq.apollo.dto.{TopicDestinationDTO, DurableSubscriptionDestinationDTO,
DestinationDTO}
+import org.apache.activemq.apollo.dto.{AcceptingConnectorDTO, TopicDestinationDTO, DurableSubscriptionDestinationDTO,
DestinationDTO}
 
 object OpenwireProtocolHandler extends Log {
 
@@ -123,7 +123,8 @@ class OpenwireProtocolHandler extends Pr
     import collection.JavaConversions._
 
     codec = connection.transport.getProtocolCodec.asInstanceOf[OpenwireCodec]
-    config = connection.connector.config.protocols.find( _.isInstanceOf[OpenwireDTO]).map(_.asInstanceOf[OpenwireDTO]).getOrElse(new
OpenwireDTO)
+    var connector_config = connection.connector.config.asInstanceOf[AcceptingConnectorDTO]
+    config = connector_config.protocols.find( _.isInstanceOf[OpenwireDTO]).map(_.asInstanceOf[OpenwireDTO]).getOrElse(new
OpenwireDTO)
 
 //    protocol_filters = ProtocolFilter.create_filters(config.protocol_filters.toList, this)
 //

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/main/scala/org/apache/activemq/apollo/stomp/StompProtocolHandler.scala
Sun Aug 14 21:02:23 2011
@@ -496,7 +496,8 @@ class StompProtocolHandler extends Proto
     import collection.JavaConversions._
 
     codec = connection.transport.getProtocolCodec.asInstanceOf[StompCodec]
-    config = connection.connector.config.protocols.find( _.isInstanceOf[StompDTO]).map(_.asInstanceOf[StompDTO]).getOrElse(new
StompDTO)
+    val connector_config = connection.connector.config.asInstanceOf[AcceptingConnectorDTO]
+    config = connector_config.protocols.find( _.isInstanceOf[StompDTO]).map(_.asInstanceOf[StompDTO]).getOrElse(new
StompDTO)
 
     protocol_filters = ProtocolFilter.create_filters(config.protocol_filters.toList, this)
 

Modified: activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/dto/XmlCodecTest.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/dto/XmlCodecTest.java?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/dto/XmlCodecTest.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-stomp/src/test/scala/org/apache/activemq/apollo/stomp/dto/XmlCodecTest.java
Sun Aug 14 21:02:23 2011
@@ -42,7 +42,7 @@ public class XmlCodecTest {
         assertNotNull(dto);
 
         assertEquals(1, dto.connectors.size());
-        ConnectorDTO connector = dto.connectors.get(0);
+        AcceptingConnectorDTO connector = (AcceptingConnectorDTO)dto.connectors.get(0);
         assertEquals(1, connector.protocols.size());
         ProtocolDTO stomp = connector.protocols.get(0);
         assertTrue(stomp instanceof StompDTO);

Modified: activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala?rev=1157667&r1=1157666&r2=1157667&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-web/src/main/scala/org/apache/activemq/apollo/web/resources/BrokerResource.scala
Sun Aug 14 21:02:23 2011
@@ -565,34 +565,22 @@ case class BrokerResource() extends Reso
     with_broker { broker =>
       monitoring(broker) {
         val records = broker.connectors.values.map { value =>
-          Success(status(value))
+          Success(value.status)
         }
-        FutureResult(narrow(classOf[ConnectorStatusDTO], records, f, q, p, ps, o))
+        FutureResult(narrow(classOf[ServiceStatusDTO], records, f, q, p, ps, o))
       }
     }
   }
 
   @GET @Path("connectors/{id}")
-  def connector(@PathParam("id") id : String):ConnectorStatusDTO = {
+  def connector(@PathParam("id") id : String):ServiceStatusDTO = {
     with_connector(id) { connector =>
       monitoring(connector.broker) {
-        status(connector)
+        connector.status
       }
     }
   }
 
-  def status(connector: Connector): ConnectorStatusDTO = {
-    val result = new ConnectorStatusDTO
-    result.id = connector.id.toString
-    result.state = connector.service_state.toString
-    result.state_since = connector.service_state.since
-    result.connection_counter = connector.accepted.get
-    result.connected = connector.connected.get
-    result.protocol = Option(connector.config.protocol).getOrElse("any")
-    result.local_address = Option(connector.socket_address).map(_.toString).getOrElse("any")
-    result
-  }
-
   @POST @Path("connectors/{id}/action/stop")
   @Produces(Array("application/json", "application/xml","text/xml"))
   def post_connector_stop(@PathParam("id") id : String):Unit = unwrap_future_result {



Mime
View raw message