activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbert...@apache.org
Subject [1/2] activemq-artemis git commit: NO-JIRA: using scheduled component on message counters
Date Fri, 23 Sep 2016 16:08:56 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master d64903fcc -> 42c708094


NO-JIRA: using scheduled component on message counters


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

Branch: refs/heads/master
Commit: b98c24e749f61e3d6ca1ca10e69e44c3469a54d4
Parents: d64903f
Author: Clebert Suconic <clebertsuconic@apache.org>
Authored: Thu Sep 15 13:49:55 2016 -0400
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Fri Sep 23 09:09:37 2016 -0400

----------------------------------------------------------------------
 .../impl/MessageCounterManagerImpl.java         | 73 +++++---------------
 .../management/impl/ManagementServiceImpl.java  |  2 +-
 2 files changed, 18 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b98c24e7/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/impl/MessageCounterManagerImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/impl/MessageCounterManagerImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/impl/MessageCounterManagerImpl.java
index 0f60cf6..a5c1be4 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/impl/MessageCounterManagerImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/messagecounter/impl/MessageCounterManagerImpl.java
@@ -20,13 +20,14 @@ import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
-import java.util.concurrent.Future;
+import java.util.concurrent.Executor;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration;
 import org.apache.activemq.artemis.core.messagecounter.MessageCounter;
 import org.apache.activemq.artemis.core.messagecounter.MessageCounterManager;
+import org.apache.activemq.artemis.core.server.ActiveMQScheduledComponent;
 
 /**
  * A MessageCounterManager
@@ -41,45 +42,25 @@ public class MessageCounterManagerImpl implements MessageCounterManager
{
 
    private final Map<String, MessageCounter> messageCounters;
 
-   private boolean started;
-
-   private long period = MessageCounterManagerImpl.DEFAULT_SAMPLE_PERIOD;
-
-   private MessageCountersPinger messageCountersPinger;
+   private final MessageCountersPinger messageCountersPinger;
 
    private int maxDayCount = MessageCounterManagerImpl.DEFAULT_MAX_DAY_COUNT;
 
-   private final ScheduledExecutorService scheduledThreadPool;
-
-   public MessageCounterManagerImpl(final ScheduledExecutorService scheduledThreadPool) {
+   public MessageCounterManagerImpl(final ScheduledExecutorService scheduledThreadPool, Executor
executor) {
       messageCounters = new HashMap<>();
-
-      this.scheduledThreadPool = scheduledThreadPool;
+      messageCountersPinger = new MessageCountersPinger(scheduledThreadPool, executor,  MessageCounterManagerImpl.DEFAULT_SAMPLE_PERIOD,
TimeUnit.MILLISECONDS, false);
    }
 
    @Override
    public synchronized void start() {
-      if (started) {
-         return;
-      }
-
-      messageCountersPinger = new MessageCountersPinger();
 
-      Future<?> future = scheduledThreadPool.scheduleAtFixedRate(messageCountersPinger,
0, period, TimeUnit.MILLISECONDS);
-      messageCountersPinger.setFuture(future);
+      messageCountersPinger.start();
 
-      started = true;
    }
 
    @Override
    public synchronized void stop() {
-      if (!started) {
-         return;
-      }
-
       messageCountersPinger.stop();
-
-      started = false;
    }
 
    @Override
@@ -89,22 +70,12 @@ public class MessageCounterManagerImpl implements MessageCounterManager
{
 
    @Override
    public synchronized void reschedule(final long newPeriod) {
-      boolean wasStarted = started;
-
-      if (wasStarted) {
-         stop();
-      }
-
-      period = newPeriod;
-
-      if (wasStarted) {
-         start();
-      }
+      messageCountersPinger.setPeriod(newPeriod);
    }
 
    @Override
    public long getSamplePeriod() {
-      return period;
+      return messageCountersPinger.getPeriod();
    }
 
    @Override
@@ -155,17 +126,18 @@ public class MessageCounterManagerImpl implements MessageCounterManager
{
       }
    }
 
-   private class MessageCountersPinger implements Runnable {
+   private class MessageCountersPinger extends ActiveMQScheduledComponent {
 
-      private boolean closed = false;
-
-      private Future<?> future;
+      MessageCountersPinger(ScheduledExecutorService scheduledExecutorService,
+                                   Executor executor,
+                                   long checkPeriod,
+                                   TimeUnit timeUnit,
+                                   boolean onDemand) {
+         super(scheduledExecutorService, executor, checkPeriod, timeUnit, onDemand);
+      }
 
       @Override
-      public synchronized void run() {
-         if (closed) {
-            return;
-         }
+      public void run() {
 
          synchronized (messageCounters) {
             for (MessageCounter counter : messageCounters.values()) {
@@ -174,17 +146,6 @@ public class MessageCounterManagerImpl implements MessageCounterManager
{
          }
       }
 
-      public void setFuture(final Future<?> future) {
-         this.future = future;
-      }
-
-      synchronized void stop() {
-         if (future != null) {
-            future.cancel(false);
-         }
-
-         closed = true;
-      }
    }
 
 }

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/b98c24e7/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
index 22b4e50..26b6450 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/management/impl/ManagementServiceImpl.java
@@ -190,7 +190,7 @@ public class ManagementServiceImpl implements ManagementService {
       this.messagingServer = messagingServer;
       this.pagingManager = pagingManager;
 
-      messageCounterManager = new MessageCounterManagerImpl(scheduledThreadPool);
+      messageCounterManager = new MessageCounterManagerImpl(scheduledThreadPool, messagingServer.getExecutorFactory().getExecutor());
       messageCounterManager.setMaxDayCount(configuration.getMessageCounterMaxDayHistory());
       messageCounterManager.reschedule(configuration.getMessageCounterSamplePeriod());
 


Mime
View raw message