activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From chir...@apache.org
Subject svn commit: r1336411 - in /activemq/activemq-apollo/trunk: apollo-broker/src/main/scala/org/apache/activemq/apollo/broker/CustomServiceFactory.scala apollo-dto/src/main/java/org/apache/activemq/apollo/dto/AutoGCServiceDTO.java
Date Wed, 09 May 2012 21:25:44 GMT
Author: chirino
Date: Wed May  9 21:25:44 2012
New Revision: 1336411

URL: http://svn.apache.org/viewvc?rev=1336411&view=rev
Log:
Adding an optional auto gc service which can periodically auto trigger the JVM GC cycle.

Modified:
    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

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=1336411&r1=1336410&r2=1336411&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 21:25:44 2012
@@ -16,8 +16,10 @@
  */
 package org.apache.activemq.apollo.broker
 
-import org.apache.activemq.apollo.dto.CustomServiceDTO
-import org.apache.activemq.apollo.util.{Log, Service, ClassFinder}
+import org.apache.activemq.apollo.dto.{AutoGCServiceDTO, CustomServiceDTO}
+import org.apache.activemq.apollo.util._
+import org.fusesource.hawtdispatch._
+import java.util.concurrent.TimeUnit
 
 trait CustomServiceFactory {
   def create(broker:Broker, dto:CustomServiceDTO):Service
@@ -83,4 +85,36 @@ object ReflectiveCustomServiceFactory ex
     service
 
   }
+}
+
+object AutoGCServiceFactory extends CustomServiceFactory with Log {
+  def create(broker: Broker, dto: CustomServiceDTO): Service = dto match {
+
+    case dto:AutoGCServiceDTO => new BaseService {
+
+      def interval = OptionSupport(dto.interval).getOrElse(1)
+      var run_counter = 0
+
+      protected def _start(on_completed: Task) = {
+        schedule_gc(run_counter)
+        on_completed.run
+      }
+
+      protected def _stop(on_completed: Task) = {
+        run_counter += 1
+        on_completed.run
+      }
+
+      def schedule_gc(counter:Int):Unit = {
+        if(counter == run_counter) {
+          dispatch_queue.after(interval, TimeUnit.SECONDS) {
+            Runtime.getRuntime.gc()
+            schedule_gc(counter)
+          }
+        }
+      }
+
+    }
+    case _ => null
+  }
 }
\ No newline at end of file

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=1336411&r1=1336410&r2=1336411&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 21:25:44 2012
@@ -27,23 +27,13 @@ import java.util.List;
 /**
  * @author <a href="http://hiramchirino.com">Hiram Chirino</a>
  */
-@XmlRootElement(name="service")
+@XmlRootElement(name="auto_gc_service")
 @XmlAccessorType(XmlAccessType.FIELD)
 @JsonIgnoreProperties(ignoreUnknown = true)
-public class AutoGCServiceDTO extends ServiceDTO {
+public class AutoGCServiceDTO extends CustomServiceDTO {
 
-    /**
-     * 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>();
-
+    public Integer interval;
 
     @Override
     public boolean equals(Object o) {
@@ -53,8 +43,8 @@ public class AutoGCServiceDTO extends Se
 
         AutoGCServiceDTO that = (AutoGCServiceDTO) 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;
+        if (interval != null ? !interval.equals(that.interval) : that.interval != null)
+            return false;
 
         return true;
     }
@@ -62,8 +52,7 @@ public class AutoGCServiceDTO extends Se
     @Override
     public int hashCode() {
         int result = super.hashCode();
-        result = 31 * result + (kind != null ? kind.hashCode() : 0);
-        result = 31 * result + (other != null ? other.hashCode() : 0);
+        result = 31 * result + (interval != null ? interval.hashCode() : 0);
         return result;
     }
 }
\ No newline at end of file



Mime
View raw message