incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r771304 - in /incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl: OsgiControllerImpl.java OsgiControllerTask.java OsgiControllerTaskExecutor.java ResourceQueueTask.java
Date Mon, 04 May 2009 13:47:51 GMT
Author: bdelacretaz
Date: Mon May  4 13:47:50 2009
New Revision: 771304

URL: http://svn.apache.org/viewvc?rev=771304&view=rev
Log:
SLING-904 - OsgiControllerTaskExecutor added, executes install/update/uninstall tasks in a
separate thread

Added:
    incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTaskExecutor.java
  (with props)
    incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ResourceQueueTask.java
  (with props)
Modified:
    incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
    incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java?rev=771304&r1=771303&r2=771304&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
(original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerImpl.java
Mon May  4 13:47:50 2009
@@ -23,6 +23,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.concurrent.Callable;
 
 import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
 import org.apache.sling.jcr.jcrinstall.osgi.JcrInstallException;
@@ -57,7 +58,8 @@
     private OsgiResourceProcessorList processors;
     private final Logger log = LoggerFactory.getLogger(this.getClass());
     private ResourceOverrideRules roRules;
-    private final List<OsgiControllerTask> tasks = new LinkedList<OsgiControllerTask>();
+    private final List<Callable<Object>> tasks = new LinkedList<Callable<Object>>();
+    private final OsgiControllerTaskExecutor executor = new OsgiControllerTaskExecutor();
 
     public static final String STORAGE_FILENAME = "controller.storage";
 
@@ -140,21 +142,31 @@
 
     /** {@inheritDoc} */
     public void executeScheduledOperations() throws Exception {
+    	
+    	// Ready to work?
         if(processors == null) {
             log.info("Not activated yet, cannot executeScheduledOperations");
             return;
         }
         
-        // Execute all our tasks, and then let processors execute
-        // their own queued operations
+        // Anything to do?
+        if(tasks.isEmpty()) {
+        	return;
+        }
+        
         synchronized (tasks) {
-        	while(tasks.size() > 0) {
-    			tasks.remove(0).execute();
-        	}
+            // Add tasks for our processors to execute their own operations,
+            // after our own tasks are executed
+            for(OsgiResourceProcessor p : processors) {
+            	tasks.add(new ResourceQueueTask(p));
+            }
+            
+            // Now execute all our tasks in a separate thread
+            log.debug("Executing {} queued tasks", tasks.size());
+            final long start = System.currentTimeMillis();
+            executor.execute(tasks);
+            log.debug("Done executing queued tasks ({} msec)", System.currentTimeMillis()
- start);
 		}
-        for(OsgiResourceProcessor p : processors) {
-            p.processResourceQueue();
-        }
 	}
 
 	public void setResourceOverrideRules(ResourceOverrideRules r) {

Modified: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java?rev=771304&r1=771303&r2=771304&view=diff
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java
(original)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTask.java
Mon May  4 13:47:50 2009
@@ -21,8 +21,8 @@
 import static org.apache.sling.jcr.jcrinstall.osgi.InstallResultCode.IGNORED;
 
 import java.io.IOException;
-import java.util.Collection;
 import java.util.Map;
+import java.util.concurrent.Callable;
 
 import org.apache.sling.jcr.jcrinstall.osgi.InstallableData;
 import org.apache.sling.jcr.jcrinstall.osgi.JcrInstallException;
@@ -34,7 +34,7 @@
 /** An install/upgrade/uninistall task, meant to be executed
  * 	by the OsgiController worker thread.
  */
-class OsgiControllerTask {
+class OsgiControllerTask implements Callable<Object> {
 	
 	private final String uri;
 	private final InstallableData data;
@@ -61,12 +61,28 @@
 		this.data = data;
 	}
 	
-	void execute() throws JcrInstallException, IOException {
-		if(data != null) {
+	@Override
+	public String toString() {
+		return 
+			getClass().getSimpleName()
+			+ ", "
+			+ (isInstallOrUpdate() ? "install/update" : "uninstall")
+			+ ", "
+			+ uri
+		;
+	}
+	
+	public Object call() throws JcrInstallException, IOException {
+		if(isInstallOrUpdate()) {
 			executeInstallOrUpdate();
 		} else {
 			executeUninstall();
 		}
+		return null;
+	}
+	
+	boolean isInstallOrUpdate() {
+		return data != null;
 	}
 
 	private void executeUninstall() throws JcrInstallException {

Added: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTaskExecutor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTaskExecutor.java?rev=771304&view=auto
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTaskExecutor.java
(added)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTaskExecutor.java
Mon May  4 13:47:50 2009
@@ -0,0 +1,54 @@
+/*
+ * 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.jcrinstall.osgi.impl;
+
+import java.util.List;
+import java.util.concurrent.Callable;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/** Executes a list of OsgiController tasks in their own thread.
+ */
+class OsgiControllerTaskExecutor {
+    private final Logger log = LoggerFactory.getLogger(this.getClass());
+    static int counter;
+
+	/** Execute the given tasks in a new thread, return when done */
+	void execute(final List<Callable<Object>> tasks) throws InterruptedException
{
+		final String threadName = getClass().getSimpleName() + " #" + (++counter);
+		final Thread t = new Thread(threadName) {
+			@Override
+			public void run() {
+				while(!tasks.isEmpty()) {
+					final Callable<Object> c = tasks.remove(0);
+					try {
+						c.call();
+						log.debug("Task execution successful: " + c);
+					} catch(Exception e) {
+						log.warn("Task execution failed: " + c, e);
+					}
+				}
+			}
+		};
+		t.setDaemon(true);
+		t.start();
+		t.join();
+	}
+}

Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTaskExecutor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/OsgiControllerTaskExecutor.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ResourceQueueTask.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ResourceQueueTask.java?rev=771304&view=auto
==============================================================================
--- incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ResourceQueueTask.java
(added)
+++ incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ResourceQueueTask.java
Mon May  4 13:47:50 2009
@@ -0,0 +1,42 @@
+/*
+ * 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.jcrinstall.osgi.impl;
+
+import java.util.concurrent.Callable;
+
+import org.apache.sling.jcr.jcrinstall.osgi.OsgiResourceProcessor;
+
+/** Callable that processes the resource queue of an OsgiResourceProcessor */
+class ResourceQueueTask implements Callable<Object> {
+	private final OsgiResourceProcessor p;
+	
+	ResourceQueueTask(OsgiResourceProcessor p) {
+		this.p = p;
+	}
+	
+	public String toString() {
+		return getClass().getSimpleName() + ": " + p.getClass().getSimpleName()+ ".processResourceQueue()";
+	}
+	
+	public Object call() throws Exception {
+		p.processResourceQueue();
+		return null;
+	}
+
+}

Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ResourceQueueTask.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ResourceQueueTask.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message