Return-Path: X-Original-To: apmail-usergrid-commits-archive@minotaur.apache.org Delivered-To: apmail-usergrid-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 5FC9417C4D for ; Wed, 1 Oct 2014 14:51:38 +0000 (UTC) Received: (qmail 2460 invoked by uid 500); 1 Oct 2014 14:51:38 -0000 Delivered-To: apmail-usergrid-commits-archive@usergrid.apache.org Received: (qmail 2394 invoked by uid 500); 1 Oct 2014 14:51:38 -0000 Mailing-List: contact commits-help@usergrid.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@usergrid.incubator.apache.org Delivered-To: mailing list commits@usergrid.incubator.apache.org Received: (qmail 2210 invoked by uid 99); 1 Oct 2014 14:51:38 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 01 Oct 2014 14:51:38 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 06D9C882B82; Wed, 1 Oct 2014 14:51:38 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: snoopdave@apache.org To: commits@usergrid.apache.org Date: Wed, 01 Oct 2014 14:51:58 -0000 Message-Id: <59455ccd78da4ebe89bf5f8d4b7ffa1e@git.apache.org> In-Reply-To: <68ade1d05fb940afb4b371372ac114b8@git.apache.org> References: <68ade1d05fb940afb4b371372ac114b8@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [22/35] git commit: Fixes spring configuration of queue listener Fixes spring configuration of queue listener Fixes bug where executor pool size is always 1. Now matches number of threads so that more than 1 task will actually be running. Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/9e2743d0 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/9e2743d0 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/9e2743d0 Branch: refs/heads/two-dot-o-rebuildable-index Commit: 9e2743d0debe99f044f2b36105feb364fbe9325c Parents: cbea83c Author: Todd Nine Authored: Mon Sep 29 12:02:24 2014 -0600 Committer: Todd Nine Committed: Mon Sep 29 12:02:24 2014 -0600 ---------------------------------------------------------------------- .../services/notifications/QueueListener.java | 29 ++++++++++---------- .../resources/usergrid-services-context.xml | 9 ++++-- .../apns/NotificationsServiceIT.java | 2 +- .../gcm/NotificationsServiceIT.java | 4 +-- 4 files changed, 24 insertions(+), 20 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9e2743d0/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java ---------------------------------------------------------------------- diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java index d8acdfe..42f9dc4 100644 --- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java +++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/QueueListener.java @@ -40,16 +40,14 @@ public class QueueListener { private static final Logger LOG = LoggerFactory.getLogger(QueueListener.class); - @Autowired + private MetricsFactory metricsService; - @Autowired private ServiceManagerFactory smf; - @Autowired private EntityManagerFactory emf; - @Autowired + private Properties properties; private org.apache.usergrid.mq.QueueManager queueManager; @@ -60,18 +58,16 @@ public class QueueListener { private long sleepBetweenRuns = 5000; - ExecutorService pool; - List futures; + private ExecutorService pool; + private List futures; public final String MAX_THREADS = "2"; private Integer batchSize = 1000; private String[] queueNames; - public QueueListener() { - pool = Executors.newFixedThreadPool(1); - } + + public QueueListener(ServiceManagerFactory smf, EntityManagerFactory emf, MetricsFactory metricsService, Properties props){ - this(); this.smf = smf; this.emf = emf; this.metricsService = metricsService; @@ -79,11 +75,7 @@ public class QueueListener { } @PostConstruct - void init() { - run(); - } - - public void run(){ + public void start(){ boolean shouldRun = new Boolean(properties.getProperty("usergrid.notifications.listener.run", "true")); if(shouldRun) { @@ -98,6 +90,11 @@ public class QueueListener { int maxThreads = new Integer(properties.getProperty("usergrid.notifications.listener.maxThreads", MAX_THREADS)); futures = new ArrayList(maxThreads); + + //create our thread pool based on our threadcount. + + pool = Executors.newFixedThreadPool(maxThreads); + while (threadCount++ < maxThreads) { LOG.info("QueueListener: Starting thread {}.", threadCount); Runnable task = new Runnable() { @@ -212,6 +209,8 @@ public class QueueListener { for(Future future : futures){ future.cancel(true); } + + pool.shutdownNow(); } private QueueResults getDeliveryBatch(org.apache.usergrid.mq.QueueManager queueManager,String queuePath) throws Exception { http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9e2743d0/stack/services/src/main/resources/usergrid-services-context.xml ---------------------------------------------------------------------- diff --git a/stack/services/src/main/resources/usergrid-services-context.xml b/stack/services/src/main/resources/usergrid-services-context.xml index be47f08..56883fa 100644 --- a/stack/services/src/main/resources/usergrid-services-context.xml +++ b/stack/services/src/main/resources/usergrid-services-context.xml @@ -89,7 +89,12 @@ - - + + + + + + http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9e2743d0/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java ---------------------------------------------------------------------- diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java index 1985b19..8d994e9 100644 --- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java +++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/apns/NotificationsServiceIT.java @@ -132,7 +132,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT { listener = new QueueListener(ns.getServiceManagerFactory(),ns.getEntityManagerFactory(),ns.getMetricsFactory(), new Properties()); listener.DEFAULT_SLEEP = 200; - listener.run(); + listener.start(); } @After http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/9e2743d0/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java ---------------------------------------------------------------------- diff --git a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java index fdcf7b6..c540c5a 100644 --- a/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java +++ b/stack/services/src/test/java/org/apache/usergrid/services/notifications/gcm/NotificationsServiceIT.java @@ -108,7 +108,7 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT { ns.getEntityManagerFactory(),ns.getMetricsFactory(), new Properties()); listener.DEFAULT_SLEEP = 200; - listener.run(); + listener.start(); } @After @@ -571,4 +571,4 @@ public class NotificationsServiceIT extends AbstractServiceNotificationIT { // assertNull(device2.getProperty(notifier.getName() + // NOTIFIER_ID_POSTFIX)); // } -} \ No newline at end of file +}