Author: chetanm
Date: Mon Nov 28 04:36:09 2016
New Revision: 1771679

URL: http://svn.apache.org/viewvc?rev=1771679&view=rev
Log:
OAK-5165 - Close AsyncIndexUpdate instance upon deactivate

Modified:
    
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexerService.java
    
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexerServiceTest.java

Modified: 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexerService.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexerService.java?rev=1771679&r1=1771678&r2=1771679&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexerService.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexerService.java
 Mon Nov 28 04:36:09 2016
@@ -19,6 +19,7 @@
 
 package org.apache.jackrabbit.oak.plugins.index;
 
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -26,6 +27,7 @@ import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 import com.google.common.collect.Lists;
+import com.google.common.io.Closer;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.ConfigurationPolicy;
@@ -106,6 +108,8 @@ public class AsyncIndexerService {
 
     private IndexMBeanRegistration indexRegistration;
 
+    private final Closer closer = Closer.create();
+
     @Activate
     public void activate(BundleContext bundleContext, Map<String, Object> 
config) {
         List<AsyncConfig> asyncIndexerConfig = 
getAsyncConfig(PropertiesUtil.toStringArray(config.get
@@ -131,16 +135,20 @@ public class AsyncIndexerService {
             task.setLeaseTimeOut(TimeUnit.MINUTES.toMillis(leaseTimeOutMin));
 
             indexRegistration.registerAsyncIndexer(task, c.timeIntervalInSecs);
+            closer.register(task);
         }
         log.info("Configured async indexers {} ", asyncIndexerConfig);
         log.info("Lease time: {} mins and AsyncIndexUpdate configured with 
{}", leaseTimeOutMin, validatorProvider.getClass().getName());
     }
 
     @Deactivate
-    public void deactivate() {
+    public void deactivate() throws IOException {
         if (indexRegistration != null) {
             indexRegistration.unregister();
         }
+
+        //Close the task *after* unregistering the jobs
+        closer.close();
     }
 
     //~-------------------------------------------< internal >

Modified: 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexerServiceTest.java
URL: 
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexerServiceTest.java?rev=1771679&r1=1771678&r2=1771679&view=diff
==============================================================================
--- 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexerServiceTest.java
 (original)
+++ 
jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/plugins/index/AsyncIndexerServiceTest.java
 Mon Nov 28 04:36:09 2016
@@ -69,8 +69,11 @@ public class AsyncIndexerServiceTest {
         assertNotNull(context.getService(Runnable.class));
         assertEquals(TimeUnit.MINUTES.toMillis(15), 
getIndexUpdate("async").getLeaseTimeOut());
 
+        AsyncIndexUpdate indexUpdate = getIndexUpdate("async");
+
         MockOsgi.deactivate(service);
         assertNull(context.getService(Runnable.class));
+        assertTrue(indexUpdate.isClosed());
     }
 
     @Test


Reply via email to