You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2009/08/17 11:27:27 UTC
svn commit: r804906 - in
/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl:
BundleTaskCreator.java OsgiInstallerImpl.java OsgiInstallerThread.java
RegisteredResourceList.java
Author: bdelacretaz
Date: Mon Aug 17 09:27:26 2009
New Revision: 804906
URL: http://svn.apache.org/viewvc?rev=804906&view=rev
Log:
SLING-1078 - ready to implement task creators
Added:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java (with props)
Removed:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceList.java
Modified:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
Added: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java?rev=804906&view=auto
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java (added)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java Mon Aug 17 09:27:26 2009
@@ -0,0 +1,33 @@
+/*
+ * 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.osgi.installer.impl;
+
+import java.util.TreeSet;
+
+import org.apache.sling.osgi.installer.impl.tasks.BundleInstallTask;
+
+/** TaskCreator that processes a list of bundle RegisteredResources */
+class BundleTaskCreator implements OsgiInstallerThread.TaskCreator {
+
+ public void createTasks(TreeSet<RegisteredResource> resources, TreeSet<OsgiInstallerTask> tasks) {
+ for(RegisteredResource r : resources) {
+ tasks.add(new BundleInstallTask(r));
+ }
+ }
+}
Propchange: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
------------------------------------------------------------------------------
svn:keywords = Author Date Id Revision Rev URL
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java?rev=804906&r1=804905&r2=804906&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerImpl.java Mon Aug 17 09:27:26 2009
@@ -102,7 +102,7 @@
public void addResource(InstallableResource r) throws IOException {
// TODO do not add if we already have it, based on digest
- installerThread.addResource(new RegisteredResource(bundleContext, r));
+ installerThread.addNewResource(new RegisteredResource(bundleContext, r));
}
public void registerResources(Collection<InstallableResource> data,
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java?rev=804906&r1=804905&r2=804906&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java Mon Aug 17 09:27:26 2009
@@ -18,8 +18,10 @@
*/
package org.apache.sling.osgi.installer.impl;
+import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
+import java.util.Map;
import java.util.TreeSet;
import org.osgi.service.log.LogService;
@@ -35,10 +37,23 @@
class OsgiInstallerThread extends Thread {
private final OsgiInstallerContext ctx;
- private final RegisteredResourceList registeredResources = new RegisteredResourceList();
private final List<RegisteredResource> newResources = new LinkedList<RegisteredResource>();
private final TreeSet<OsgiInstallerTask> tasks = new TreeSet<OsgiInstallerTask>();
+ /** Group our RegisteredResource by OSGi entity */
+ private final Map<String, TreeSet<RegisteredResource>> registeredResources =
+ new HashMap<String, TreeSet<RegisteredResource>>();
+
+ static interface TaskCreator {
+ /** Add the required OsgiInstallerTasks to the tasks collection, so that the resources reach
+ * their desired states.
+ * @param resources ordered set of RegisteredResource which all have the same entityId
+ * @param tasks lists of tasks, to which we'll add the ones computed by this method
+ */
+ void createTasks(TreeSet<RegisteredResource> resources, TreeSet<OsgiInstallerTask> tasks);
+ }
+ private final TaskCreator bundleTaskCreator = new BundleTaskCreator();
+
OsgiInstallerThread(OsgiInstallerContext ctx) {
setName(getClass().getSimpleName());
this.ctx = ctx;
@@ -49,21 +64,9 @@
while(true) {
// TODO do nothing if nothing to process!
try {
- // Add new resources to the list
- synchronized (newResources) {
- for(RegisteredResource r : newResources) {
- registeredResources.add(r);
- }
- newResources.clear();
- }
-
- // Compute OSGi tasks based on the list of resources
- tasks.addAll(registeredResources.getTasks());
-
- // Execute all tasks
+ mergeNewResources();
+ computeTasks();
executeTasks();
-
- // Wait a bit before next cycle
Thread.sleep(250);
} catch(Exception e) {
if(ctx.getLogService() != null) {
@@ -86,6 +89,43 @@
}
}
+ /** Register a new resource, will be processed on the next cycle */
+ void addNewResource(RegisteredResource r) {
+ synchronized (newResources) {
+ newResources.add(r);
+ }
+ }
+
+ private void addRegisteredResource(RegisteredResource r) {
+ TreeSet<RegisteredResource> t = registeredResources.get(r.getEntityId());
+ if(t == null) {
+ t = new TreeSet<RegisteredResource>(new RegisteredResourceComparator());
+ registeredResources.put(r.getEntityId(), t);
+ }
+ t.add(r);
+
+ }
+
+ private void mergeNewResources() {
+ synchronized (newResources) {
+ for(RegisteredResource r : newResources) {
+ addRegisteredResource(r);
+ }
+ newResources.clear();
+ }
+ }
+
+ private void computeTasks() {
+ // Walk the list of entities, and create appropriate OSGi tasks for each group
+ for(TreeSet<RegisteredResource> group : registeredResources.values()) {
+ if(group.first().getResourceType().equals(RegisteredResource.ResourceType.BUNDLE)) {
+ bundleTaskCreator.createTasks(group, tasks);
+ } else {
+ throw new IllegalArgumentException("No TaskCreator for resource type "+ group.first().getResourceType());
+ }
+ }
+ }
+
private void executeTasks() throws Exception {
while(!tasks.isEmpty()) {
OsgiInstallerTask t = null;
@@ -99,9 +139,4 @@
}
}
- void addResource(RegisteredResource r) {
- synchronized (newResources) {
- newResources.add(r);
- }
- }
-}
+}
\ No newline at end of file