activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1336432 - 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-dto/src/main/java/org/apache/activemq/apoll...
Date Wed, 09 May 2012 22:31:17 GMT
Author: chirino
Date: Wed May  9 22:31:17 2012
New Revision: 1336432

URL: http://svn.apache.org/viewvc?rev=1336432&view=rev
Log:
Fixes APLO-202 - Support an option to periodically for a GC so that reported heap usages can
drop when the broker goes idle.

Added:
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/SimpleCustomServiceDTO.java
      - copied, changed from r1336411, activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/CustomServiceDTO.java
Modified:
    activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/custom-service-factory.index
    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/CustomServiceFactory.scala
    activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/AutoGCServiceDTO.java
    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/CustomServiceDTO.java
    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

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/custom-service-factory.index
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/custom-service-factory.index?rev=1336432&r1=1336431&r2=1336432&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/custom-service-factory.index
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/resources/META-INF/services/org.apache.activemq.apollo/custom-service-factory.index
Wed May  9 22:31:17 2012
@@ -14,5 +14,5 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
-org.apache.activemq.apollo.broker.ReflectiveCustomServiceFactory
+org.apache.activemq.apollo.broker.SimpleCustomServiceFactory
 org.apache.activemq.apollo.broker.AutoGCServiceFactory
\ No newline at end of file

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=1336432&r1=1336431&r2=1336432&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
Wed May  9 22:31:17 2012
@@ -266,7 +266,7 @@ class Broker() extends BaseService with 
   var security_log:Log  = Broker
   var connection_log:Log = Broker
   var console_log:Log = Broker
-  var services = Map[String, (CustomServiceDTO, Service)]()
+  var services = Map[CustomServiceDTO, Service]()
 
   override def toString() = "broker: "+id
 
@@ -310,9 +310,7 @@ class Broker() extends BaseService with 
     val tracker = new LoggingTracker("broker shutdown", console_log, SERVICE_TIMEOUT)
 
     // Stop the services...
-    services.values.foreach( x=>
-      tracker.stop(x._2)
-    )
+    services.values.foreach(tracker.stop(_))
     services = Map()
 
     // Stop accepting connections..
@@ -511,50 +509,24 @@ class Broker() extends BaseService with 
       }
     }
 
-    val t:Seq[(String, CustomServiceDTO)] = asScalaBuffer(config.services).map(x => (x.id
->x) )
-    val services_config = Map(t: _*)
-    diff(services.keySet, services_config.keySet) match { case (added, updated, removed)
=>
-      removed.foreach { id =>
-        for( service <- services.get(id) ) {
-          services -= id
-          tracker.stop(service._2)
-        }
-      }
+    val services_config = asScalaBuffer(config.services).toSet
+    diff(services.keySet, services_config) match { case (added, updated, removed) =>
 
-      // Handle the updates.
-      added.foreach { id=>
-        for( new_dto <- services_config.get(id); (old_dto, service) <- services.get(id)
) {
-          if( new_dto != old_dto ) {
-
-            // restart.. needed.
-            val task = tracker.task("restart "+service)
-            service.stop(dispatch_queue.runnable {
-
-              // create with the new config..
-              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)
-                service.start(task)
-              }
-            })
-          }
+      removed.foreach { service_config =>
+        for( service <- services.get(service_config) ) {
+          services -= service_config
+          tracker.stop(service)
         }
       }
 
       // Create the new services..
-      added.foreach { id=>
-        for( dto <- services_config.get(id) ) {
-          val service = CustomServiceFactory.create(this, dto)
-          if( service == null ) {
-            console_log.warn("Could not create service: "+dto.id);
-          } else {
-            services += dto.id -> (dto, service)
-            tracker.start(service)
-          }
+      added.foreach { service_config =>
+        val service = CustomServiceFactory.create(this, service_config)
+        if( service == null ) {
+          console_log.warn("Could not create service: "+service_config);
+        } else {
+          services += service_config -> service
+          tracker.start(service)
         }
       }
     }

Modified: activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/CustomServiceFactory.scala
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/CustomServiceFactory.scala?rev=1336432&r1=1336431&r2=1336432&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/CustomServiceFactory.scala
(original)
+++ activemq/activemq-apollo/trunk/apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/CustomServiceFactory.scala
Wed May  9 22:31:17 2012
@@ -16,10 +16,10 @@
  */
 package org.apache.activemq.apollo.broker
 
-import org.apache.activemq.apollo.dto.{AutoGCServiceDTO, CustomServiceDTO}
 import org.apache.activemq.apollo.util._
 import org.fusesource.hawtdispatch._
 import java.util.concurrent.TimeUnit
+import org.apache.activemq.apollo.dto.{SimpleCustomServiceDTO, AutoGCServiceDTO, CustomServiceDTO}
 
 trait CustomServiceFactory {
   def create(broker:Broker, dto:CustomServiceDTO):Service
@@ -50,40 +50,44 @@ object CustomServiceFactory {
 
 }
 
-object ReflectiveCustomServiceFactory extends CustomServiceFactory with Log {
+object SimpleCustomServiceFactory extends CustomServiceFactory with Log {
 
-  def create(broker: Broker, dto: CustomServiceDTO): Service = {
-    if( dto.getClass != classOf[CustomServiceDTO] ) {
-      // don't process sub classes of CustomServiceDTO
-      return null;
-    }
-
-    val service = try {
-      Broker.class_loader.loadClass(dto.kind).newInstance().asInstanceOf[Service]
-    } catch {
-      case e:Throwable =>
-        debug(e, "could not create instance of %d for service %s", dto.kind, dto.id)
+  def create(broker: Broker, dto: CustomServiceDTO): Service = dto match {
+    case dto:SimpleCustomServiceDTO =>
+      if( dto.getClass != classOf[CustomServiceDTO] ) {
+        // don't process sub classes of CustomServiceDTO
         return null;
-    }
+      }
 
-    // Try to inject the broker via reflection..
-    try {
-      type BrokerAware = {var broker: Broker}
-      service.asInstanceOf[BrokerAware].broker = broker
-    } catch {
-      case _ =>
-    }
+      val service = try {
+        Broker.class_loader.loadClass(dto.kind).newInstance().asInstanceOf[Service]
+      } catch {
+        case e:Throwable =>
+          debug(e, "could not create instance of %d for service %s", dto.kind, Option(dto.id).getOrElse("<not
set>"))
+          return null;
+      }
 
-    // Try to inject the config via reflection..
-    try {
-      type ConfigAware = {var config: CustomServiceDTO}
-      service.asInstanceOf[ConfigAware].config = dto
-    } catch {
-      case _ =>
-    }
+      type ServiceDuckType = {
+        var broker: Broker
+        var config: CustomServiceDTO
+      }
 
-    service
+      // Try to inject the broker via reflection..
+      try {
+        service.asInstanceOf[ServiceDuckType].broker = broker
+      } catch {
+        case _ =>
+      }
 
+      // Try to inject the config via reflection..
+      try {
+        service.asInstanceOf[ServiceDuckType].config = dto
+      } catch {
+        case _ =>
+      }
+
+      service
+    case _ => null
   }
 }
 
@@ -92,7 +96,9 @@ object AutoGCServiceFactory extends Cust
 
     case dto:AutoGCServiceDTO => new BaseService {
 
-      def interval = OptionSupport(dto.interval).getOrElse(1)
+      val dispatch_queue = createQueue("auto gc service")
+
+      def interval = OptionSupport(dto.interval).getOrElse(30)
       var run_counter = 0
 
       protected def _start(on_completed: Task) = {

Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/AutoGCServiceDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/AutoGCServiceDTO.java?rev=1336432&r1=1336431&r2=1336432&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/AutoGCServiceDTO.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/AutoGCServiceDTO.java
Wed May  9 22:31:17 2012
@@ -27,11 +27,14 @@ import java.util.List;
 /**
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
  */
-@XmlRootElement(name="auto_gc_service")
+@XmlRootElement(name="auto_gc")
 @XmlAccessorType(XmlAccessType.FIELD)
 @JsonIgnoreProperties(ignoreUnknown = true)
 public class AutoGCServiceDTO extends CustomServiceDTO {
 
+    /**
+     * How often to force a GC in seconds.  Defaults to 30.
+     */
     @XmlAttribute
     public Integer interval;
 

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=1336432&r1=1336431&r2=1336432&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
Wed May  9 22:31:17 2012
@@ -93,7 +93,7 @@ public class BrokerDTO {
      * Opaque service class names which gets started/stopped when the broker
      * starts/stops.
      */
-    @XmlElement(name="service")
+    @XmlElementRef
     public List<CustomServiceDTO> services = new ArrayList<CustomServiceDTO>();
 
     /**

Modified: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/CustomServiceDTO.java
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/CustomServiceDTO.java?rev=1336432&r1=1336431&r2=1336432&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/CustomServiceDTO.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/CustomServiceDTO.java
Wed May  9 22:31:17 2012
@@ -16,54 +16,30 @@
  */
 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;
+import javax.xml.bind.annotation.XmlType;
 
 /**
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
  */
-@XmlRootElement(name="service")
-@XmlAccessorType(XmlAccessType.FIELD)
+@XmlType (name = "service_type")
+@JsonTypeInfo(use=JsonTypeInfo.Id.CUSTOM, include=JsonTypeInfo.As.PROPERTY, property="@class")
+@JsonTypeIdResolver(ApolloTypeIdResolver.class)
 @JsonIgnoreProperties(ignoreUnknown = true)
-public class CustomServiceDTO extends ServiceDTO {
-
-    /**
-     * The class name of the service.
-     */
-    @XmlAttribute
-    public String kind;
-
-    /**
-     * To hold any other non-matching XML elements
-     */
-    @XmlAnyElement(lax=true)
-    public List<Object> other = new ArrayList<Object>();
-
+abstract public class CustomServiceDTO {
 
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;
         if (!(o instanceof CustomServiceDTO)) return false;
-        if (!super.equals(o)) return false;
-
-        CustomServiceDTO that = (CustomServiceDTO) 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 = super.hashCode();
-        result = 31 * result + (kind != null ? kind.hashCode() : 0);
-        result = 31 * result + (other != null ? other.hashCode() : 0);
-        return result;
+        return 0;
     }
 }
\ No newline at end of file

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=1336432&r1=1336431&r2=1336432&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
Wed May  9 22:31:17 2012
@@ -38,7 +38,9 @@ public class Module implements DtoModule
                 SimpleStoreStatusDTO.class,
                 DetectDTO.class,
                 UdpDTO.class,
-                SimpleProtocolFilterDTO.class
+                SimpleProtocolFilterDTO.class,
+                SimpleCustomServiceDTO.class,
+                AutoGCServiceDTO.class
         };
     }
 }

Copied: activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/SimpleCustomServiceDTO.java
(from r1336411, activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/CustomServiceDTO.java)
URL: http://svn.apache.org/viewvc/activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/SimpleCustomServiceDTO.java?p2=activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/SimpleCustomServiceDTO.java&p1=activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/CustomServiceDTO.java&r1=1336411&r2=1336432&rev=1336432&view=diff
==============================================================================
--- activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/CustomServiceDTO.java
(original)
+++ activemq/activemq-apollo/trunk/apollo-dto/src/main/java/org/apache/activemq/apollo/dto/SimpleCustomServiceDTO.java
Wed May  9 22:31:17 2012
@@ -30,7 +30,13 @@ import java.util.List;
 @XmlRootElement(name="service")
 @XmlAccessorType(XmlAccessType.FIELD)
 @JsonIgnoreProperties(ignoreUnknown = true)
-public class CustomServiceDTO extends ServiceDTO {
+public class SimpleCustomServiceDTO extends CustomServiceDTO {
+
+    /**
+     * Optional id for the object
+     */
+    @XmlAttribute
+    public String id;
 
     /**
      * The class name of the service.
@@ -48,11 +54,12 @@ public class CustomServiceDTO extends Se
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;
-        if (!(o instanceof CustomServiceDTO)) return false;
+        if (!(o instanceof SimpleCustomServiceDTO)) return false;
         if (!super.equals(o)) return false;
 
-        CustomServiceDTO that = (CustomServiceDTO) o;
+        SimpleCustomServiceDTO that = (SimpleCustomServiceDTO) o;
 
+        if (id != null ? !id.equals(that.id) : that.id != null) return false;
         if (kind != null ? !kind.equals(that.kind) : that.kind != null) return false;
         if (other != null ? !other.equals(that.other) : that.other != null) return false;
 
@@ -62,6 +69,7 @@ public class CustomServiceDTO extends Se
     @Override
     public int hashCode() {
         int result = super.hashCode();
+        result = 31 * result + (id != null ? id.hashCode() : 0);
         result = 31 * 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=1336432&r1=1336431&r2=1336432&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
Wed May  9 22:31:17 2012
@@ -20,6 +20,7 @@ AddUserHeaderDTO
 AggregateConnectionMetricsDTO
 AggregateDestMetricsDTO
 AuthenticationDTO
+AutoGCServiceDTO
 BrokerDTO
 BrokerStatusDTO
 ConnectionStatusDTO
@@ -54,6 +55,7 @@ QueueDestinationDTO
 QueueStatusDTO
 ServiceDTO
 ServiceStatusDTO
+SimpleCustomServiceDTO
 SimpleStoreStatusDTO
 StoreDTO
 StoreStatusDTO



Mime
View raw message