sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From o...@apache.org
Subject [sling-org-apache-sling-jcr-oak-server] 01/02: SLING-7607 Move ThreadPool (Executor) handling out of OakSlingRepositoryManager
Date Sat, 21 Apr 2018 22:54:02 GMT
This is an automated email from the ASF dual-hosted git repository.

olli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-oak-server.git

commit 8a1ad8b49b7c6c094a667638f9107a94920184c2
Author: Oliver Lietz <olli@apache.org>
AuthorDate: Sun Apr 22 00:53:09 2018 +0200

    SLING-7607 Move ThreadPool (Executor) handling out of OakSlingRepositoryManager
---
 bnd.bnd                                            |  3 ++
 .../internal/DefaultThreadPoolRegistrar.java       | 61 ++++++++++++++++++++++
 .../server/internal/OakSlingRepositoryManager.java | 23 --------
 3 files changed, 64 insertions(+), 23 deletions(-)

diff --git a/bnd.bnd b/bnd.bnd
index 4069512..e0eb921 100644
--- a/bnd.bnd
+++ b/bnd.bnd
@@ -17,6 +17,9 @@ Import-Package:\
   org.apache.jackrabbit.test; resolution:=optional,\
   *
 
+Provide-Capability:\
+  osgi.service;objectClass:List<String>="java.util.concurrent.Executor,org.apache.sling.commons.threads.ThreadPool"
+
 -baseline: *
 
 -includeresource:\
diff --git a/src/main/java/org/apache/sling/jcr/oak/server/internal/DefaultThreadPoolRegistrar.java
b/src/main/java/org/apache/sling/jcr/oak/server/internal/DefaultThreadPoolRegistrar.java
new file mode 100644
index 0000000..2219538
--- /dev/null
+++ b/src/main/java/org/apache/sling/jcr/oak/server/internal/DefaultThreadPoolRegistrar.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sling.jcr.oak.server.internal;
+
+import org.apache.sling.commons.threads.ThreadPool;
+import org.apache.sling.commons.threads.ThreadPoolManager;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceRegistration;
+import org.osgi.service.component.annotations.Activate;
+import org.osgi.service.component.annotations.Component;
+import org.osgi.service.component.annotations.Deactivate;
+import org.osgi.service.component.annotations.Reference;
+
+@Component(
+    immediate = true
+)
+public class DefaultThreadPoolRegistrar {
+
+    @Reference
+    private ThreadPoolManager threadPoolManager;
+
+    private ThreadPool threadPool;
+
+    private ServiceRegistration<ThreadPool> serviceRegistration;
+
+    public DefaultThreadPoolRegistrar() {
+    }
+
+    @Activate
+    private void activate(final BundleContext bundleContext) {
+        threadPool = threadPoolManager.get(null);
+        serviceRegistration = bundleContext.registerService(ThreadPool.class, threadPool,
null);
+    }
+
+    @Deactivate
+    private void deactivate() {
+        if (serviceRegistration != null) {
+            serviceRegistration.unregister();
+            serviceRegistration = null;
+        }
+        threadPoolManager.release(threadPool);
+        threadPool = null;
+    }
+
+}
diff --git a/src/main/java/org/apache/sling/jcr/oak/server/internal/OakSlingRepositoryManager.java
b/src/main/java/org/apache/sling/jcr/oak/server/internal/OakSlingRepositoryManager.java
index 365f8bf..d7b3143 100644
--- a/src/main/java/org/apache/sling/jcr/oak/server/internal/OakSlingRepositoryManager.java
+++ b/src/main/java/org/apache/sling/jcr/oak/server/internal/OakSlingRepositoryManager.java
@@ -25,8 +25,6 @@ import static org.apache.jackrabbit.oak.plugins.index.IndexUtils.createIndexDefi
 
 import java.util.Collections;
 import java.util.Dictionary;
-import java.util.Hashtable;
-import java.util.concurrent.Executor;
 
 import javax.jcr.Repository;
 
@@ -55,8 +53,6 @@ import org.apache.jackrabbit.oak.spi.security.user.UserConstants;
 import org.apache.jackrabbit.oak.spi.state.NodeBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStore;
 import org.apache.jackrabbit.oak.spi.whiteboard.Whiteboard;
-import org.apache.sling.commons.threads.ThreadPool;
-import org.apache.sling.commons.threads.ThreadPoolManager;
 import org.apache.sling.jcr.base.AbstractSlingRepository2;
 import org.apache.sling.jcr.base.AbstractSlingRepositoryManager;
 import org.apache.sling.serviceusermapping.ServiceUserMapper;
@@ -96,13 +92,6 @@ public class OakSlingRepositoryManager extends AbstractSlingRepositoryManager
{
 
     private ComponentContext componentContext;
 
-    @Reference
-    private ThreadPoolManager threadPoolManager = null;
-
-    private ThreadPool threadPool;
-
-    private ServiceRegistration oakExecutorServiceReference;
-
     private final WhiteboardIndexProvider indexProvider = new WhiteboardIndexProvider();
 
     private final WhiteboardIndexEditorProvider indexEditorProvider = new WhiteboardIndexEditorProvider();
@@ -130,13 +119,6 @@ public class OakSlingRepositoryManager extends AbstractSlingRepositoryManager
{
         final Whiteboard whiteboard = new OsgiWhiteboard(bundleContext);
         this.indexProvider.start(whiteboard);
         this.indexEditorProvider.start(whiteboard);
-        this.oakExecutorServiceReference = bundleContext.registerService(
-                Executor.class.getName(), new Executor() {
-            @Override
-            public void execute(Runnable command) {
-                threadPool.execute(command);
-            }
-        }, new Hashtable<String, Object>());
 
         final Oak oak = new Oak(nodeStore)
             .withAsyncIndexing("async", 5);
@@ -192,8 +174,6 @@ public class OakSlingRepositoryManager extends AbstractSlingRepositoryManager
{
     protected void disposeRepository(Repository repository) {
         this.indexProvider.stop();
         this.indexEditorProvider.stop();
-        this.oakExecutorServiceReference.unregister();
-        this.oakExecutorServiceReference = null;
         ((JackrabbitRepository) repository).shutdown();
     }
 
@@ -209,7 +189,6 @@ public class OakSlingRepositoryManager extends AbstractSlingRepositoryManager
{
         if (configuration.oak_observation_limitCommitRate()) {
             commitRateLimiter = new CommitRateLimiter();
         }
-        this.threadPool = threadPoolManager.get("oak-observation");
         this.nodeAggregatorRegistration = bundleContext.registerService(NodeAggregator.class.getName(),
getNodeAggregator(), null);
 
         super.start(bundleContext, new Config(defaultWorkspace, disableLoginAdministrative));
@@ -219,8 +198,6 @@ public class OakSlingRepositoryManager extends AbstractSlingRepositoryManager
{
     private void deactivate() {
         super.stop();
         this.componentContext = null;
-        this.threadPoolManager.release(this.threadPool);
-        this.threadPool = null;
         this.nodeAggregatorRegistration.unregister();
     }
 

-- 
To stop receiving notification emails like this one, please contact
olli@apache.org.

Mime
View raw message