incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r724794 - in /incubator/sling/trunk/extensions/event/src: main/java/org/apache/sling/event/ main/java/org/apache/sling/event/impl/ test/java/org/apache/sling/event/impl/
Date Tue, 09 Dec 2008 17:34:56 GMT
Author: cziegeler
Date: Tue Dec  9 09:34:55 2008
New Revision: 724794

URL: http://svn.apache.org/viewvc?rev=724794&view=rev
Log:
SLING-764 : Add an own thread pool service and change configuration with a fixed queue. By
using a fixed queue, the max pool size is used and the pool growth. In
addition the minimum size of the pool is increased to all ootb more parallel job queues.

Added:
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/ThreadPool.java
  (with props)
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java
  (with props)
Modified:
    incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
    incubator/sling/trunk/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java

Added: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/ThreadPool.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/ThreadPool.java?rev=724794&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/ThreadPool.java
(added)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/ThreadPool.java
Tue Dec  9 09:34:55 2008
@@ -0,0 +1,30 @@
+/*
+ * 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.event;
+
+/**
+ * The eventing thread pool is a special thread pool used for the eventing.
+ * The eventing uses a service registered as this interface.
+ * The default implementation is a configurable pool registered with
+ * commons threads.
+ *
+ * @version $Id$
+ */
+public interface ThreadPool extends org.apache.sling.commons.threads.ThreadPool {
+
+    // this is just a marker interface
+}

Propchange: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/ThreadPool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/ThreadPool.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/ThreadPool.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java?rev=724794&r1=724793&r2=724794&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
(original)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/AbstractRepositoryEventHandler.java
Tue Dec  9 09:34:55 2008
@@ -30,13 +30,11 @@
 import javax.jcr.observation.EventListener;
 
 import org.apache.sling.commons.osgi.OsgiUtil;
-import org.apache.sling.commons.threads.ThreadPool;
-import org.apache.sling.commons.threads.ThreadPoolConfig;
-import org.apache.sling.commons.threads.ThreadPoolManager;
 import org.apache.sling.engine.SlingSettingsService;
 import org.apache.sling.event.EventPropertiesMap;
 import org.apache.sling.event.EventUtil;
 import org.apache.sling.event.JobStatusProvider;
+import org.apache.sling.event.ThreadPool;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.apache.sling.jcr.resource.JcrResourceUtil;
 import org.osgi.service.component.ComponentContext;
@@ -88,10 +86,9 @@
     /** A local queue for writing received events into the repository. */
     protected final BlockingQueue<Event> writeQueue = new LinkedBlockingQueue<Event>();
 
-    /** @scr.reference */
-    protected ThreadPoolManager threadPoolManager;
-
-    /** Our thread pool. */
+    /**
+     * Our thread pool.
+     * @scr.reference */
     protected ThreadPool threadPool;
 
     /** @scr.reference
@@ -125,21 +122,6 @@
         this.repositoryPath = OsgiUtil.toString(context.getProperties().get(
             CONFIG_PROPERTY_REPO_PATH), DEFAULT_PROPERTY_REPO_PATH);
 
-        // start background threads
-        if ( this.threadPoolManager == null ) {
-            throw new Exception("No ThreadPoolManager found.");
-        }
-        final ThreadPoolConfig config = new ThreadPoolConfig();
-        config.setMinPoolSize(10);
-        config.setMaxPoolSize(30);
-        config.setQueueSize(-1);
-        config.setShutdownGraceful(true);
-        threadPoolManager.create(EventHelper.THREAD_POOL_NAME, config);
-
-        this.threadPool = threadPoolManager.get(EventHelper.THREAD_POOL_NAME);
-        if ( this.threadPool == null ) {
-            throw new Exception("No thread pool found.");
-        }
         this.running = true;
         // start writer thread
         this.threadPool.execute(new Runnable() {
@@ -193,7 +175,6 @@
         } catch (InterruptedException e) {
             this.ignoreException(e);
         }
-        this.threadPool = null;
     }
 
     /**

Added: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java?rev=724794&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java
(added)
+++ incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java
Tue Dec  9 09:34:55 2008
@@ -0,0 +1,110 @@
+/*
+ * 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.event.impl;
+
+import org.apache.sling.commons.osgi.OsgiUtil;
+import org.apache.sling.commons.threads.ThreadPoolConfig;
+import org.apache.sling.commons.threads.ThreadPoolManager;
+import org.apache.sling.event.ThreadPool;
+import org.osgi.service.component.ComponentContext;
+
+
+/**
+ * The configurable eventing thread pool.
+ * @scr.component
+ * @scr.service interface="org.apache.sling.event.ThreadPool"
+ *
+ * @scr.property nameRef="PROPERTY_MIN_POOL_SIZE" valueRef="DEFAULT_MIN_POOL_SIZE"
+ * @scr.property nameRef="PROPERTY_MAX_POOL_SIZE" valueRef="DEFAULT_MAX_POOL_SIZE"
+ * @scr.property nameRef="PROPERTY_QUEUEL_SIZE" valueRef="DEFAULT_QUEUE_SIZE"
+ */
+public class EventingThreadPool implements ThreadPool {
+
+    /** @scr.reference */
+    protected ThreadPoolManager threadPoolManager;
+
+    /** The real thread pool used. */
+    private org.apache.sling.commons.threads.ThreadPool threadPool;
+
+    private static final String PROPERTY_MIN_POOL_SIZE = "minPoolSize";
+    private static final String PROPERTY_MAX_POOL_SIZE = "maxPoolSize";
+    private static final String PROPERTY_QUEUEL_SIZE = "queueSize";
+
+    private static final int DEFAULT_MIN_POOL_SIZE = 20; // this is sufficient for all threads
+ approx 10 job queues
+    private static final int DEFAULT_MAX_POOL_SIZE = 30;
+    private static final int DEFAULT_QUEUE_SIZE = 50; // queue upto 50 threads
+
+    /**
+     * Activate this component.
+     * @param context
+     */
+    protected void activate(final ComponentContext ctx) throws Exception {
+        // start background threads
+        if ( this.threadPoolManager == null ) {
+            throw new Exception("No ThreadPoolManager found.");
+        }
+        final ThreadPoolConfig config = new ThreadPoolConfig();
+        config.setMinPoolSize(OsgiUtil.toInteger(ctx.getProperties().get(PROPERTY_MIN_POOL_SIZE),
DEFAULT_MIN_POOL_SIZE));
+        config.setMaxPoolSize(OsgiUtil.toInteger(ctx.getProperties().get(PROPERTY_MAX_POOL_SIZE),
DEFAULT_MAX_POOL_SIZE));
+        config.setQueueSize(OsgiUtil.toInteger(ctx.getProperties().get(PROPERTY_QUEUEL_SIZE),
DEFAULT_QUEUE_SIZE));
+        config.setShutdownGraceful(true);
+        threadPoolManager.create(EventHelper.THREAD_POOL_NAME, config);
+
+        this.threadPool = threadPoolManager.get(EventHelper.THREAD_POOL_NAME);
+        if ( this.threadPool == null ) {
+            throw new Exception("No thread pool with name " + EventHelper.THREAD_POOL_NAME
+ " found.");
+        }
+    }
+
+    /**
+     * Deactivate this component.
+     * @param context
+     */
+    protected void deactivate(final ComponentContext context) {
+        this.threadPool = null;
+    }
+
+    /**
+     * @see org.apache.sling.commons.threads.ThreadPool#execute(java.lang.Runnable)
+     */
+    public void execute(Runnable runnable) {
+        threadPool.execute(runnable);
+    }
+
+    /**
+     * @see org.apache.sling.commons.threads.ThreadPool#getConfiguration()
+     */
+    public ThreadPoolConfig getConfiguration() {
+        return threadPool.getConfiguration();
+    }
+
+    /**
+     * @see org.apache.sling.commons.threads.ThreadPool#getName()
+     */
+    public String getName() {
+        return threadPool.getName();
+    }
+
+    /**
+     * @see org.apache.sling.commons.threads.ThreadPool#shutdown()
+     */
+    public void shutdown() {
+        threadPool.shutdown();
+    }
+}

Propchange: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: incubator/sling/trunk/extensions/event/src/main/java/org/apache/sling/event/impl/EventingThreadPool.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: incubator/sling/trunk/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java?rev=724794&r1=724793&r2=724794&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
(original)
+++ incubator/sling/trunk/extensions/event/src/test/java/org/apache/sling/event/impl/AbstractRepositoryEventHandlerTest.java
Tue Dec  9 09:34:55 2008
@@ -32,10 +32,9 @@
 import javax.jcr.observation.EventListenerIterator;
 
 import org.apache.sling.commons.testing.jcr.RepositoryUtil;
-import org.apache.sling.commons.threads.ThreadPool;
 import org.apache.sling.commons.threads.ThreadPoolConfig;
-import org.apache.sling.commons.threads.ThreadPoolManager;
 import org.apache.sling.engine.SlingSettingsService;
+import org.apache.sling.event.ThreadPool;
 import org.apache.sling.jcr.api.SlingRepository;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
@@ -95,15 +94,8 @@
             }
         };
 
-        // we need a thread pool manager
-        this.handler.threadPoolManager = this.getMockery().mock(ThreadPoolManager.class);
-        final ThreadPool pool = new ThreadPoolImpl();
-        this.getMockery().checking(new Expectations() {{
-            allowing(handler.threadPoolManager).get(EventHelper.THREAD_POOL_NAME);
-            will(returnValue(pool));
-            allowing(handler.threadPoolManager).create(with(equal(EventHelper.THREAD_POOL_NAME)),
with(any(ThreadPoolConfig.class)));
-            will(returnValue(null));
-        }});
+        // we need a thread pool
+        this.handler.threadPool = new ThreadPoolImpl();
 
         // lets set up the bundle context
         final BundleContext bundleContext = this.getMockery().mock(BundleContext.class);



Mime
View raw message