You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sn...@apache.org on 2014/10/01 16:51:58 UTC
[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 <to...@apache.org>
Authored: Mon Sep 29 12:02:24 2014 -0600
Committer: Todd Nine <to...@apache.org>
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<Future> futures;
+ private ExecutorService pool;
+ private List<Future> 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<Future>(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 @@
<bean id="exportJob" class="org.apache.usergrid.management.export.ExportJob" />
- <bean id="notificationsQueueListener" class="org.apache.usergrid.services.notifications.QueueListener" scope="singleton"/>
-
+ <bean id="notificationsQueueListener" class="org.apache.usergrid.services.notifications.QueueListener"
+ scope="singleton">
+ <constructor-arg name="emf" ref="entityManagerFactory" />
+ <constructor-arg name="metricsService" ref="metricsFactory" />
+ <constructor-arg name="props" ref="properties" />
+ <constructor-arg name="smf" ref="serviceManagerFactory" />
+ </bean>
</beans>
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
+}