incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1164395 - in /sling/trunk/installer/core: ./ src/main/java/org/apache/sling/installer/api/tasks/ src/main/java/org/apache/sling/installer/core/impl/ src/test/java/org/apache/sling/installer/core/impl/ src/test/java/org/apache/sling/install...
Date Fri, 02 Sep 2011 08:25:33 GMT
Author: cziegeler
Date: Fri Sep  2 08:25:32 2011
New Revision: 1164395

URL: http://svn.apache.org/viewvc?rev=1164395&view=rev
Log:
SLING-2201 : Add a listener to the installer

Added:
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallationListener.java
  (with props)
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallListener.java
  (with props)
    sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/MockInstallationListener.java
  (with props)
Modified:
    sling/trunk/installer/core/pom.xml
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
    sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
    sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/TaskOrderingTest.java
    sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/BundleTaskCreatorTest.java

Modified: sling/trunk/installer/core/pom.xml
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/pom.xml?rev=1164395&r1=1164394&r2=1164395&view=diff
==============================================================================
--- sling/trunk/installer/core/pom.xml (original)
+++ sling/trunk/installer/core/pom.xml Fri Sep  2 08:25:32 2011
@@ -59,7 +59,7 @@
                         </Import-Package>
 						<Export-Package>
 							org.apache.sling.installer.api;version=3.1.0,
-                            org.apache.sling.installer.api.tasks;version=1.1.0
+                            org.apache.sling.installer.api.tasks;version=1.2.0
                         </Export-Package>
 						<Private-Package>
 						    org.apache.sling.installer.core.impl.*

Added: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallationListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallationListener.java?rev=1164395&view=auto
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallationListener.java
(added)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallationListener.java
Fri Sep  2 08:25:32 2011
@@ -0,0 +1,49 @@
+/*
+ * 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.installer.api.tasks;
+
+/**
+ * Optional listener which can be used to monitor the activities
+ * of the installer.
+ *
+ * @since 1.2
+ */
+public interface InstallationListener {
+
+    /**
+     * A resource has been processed
+     * The state of the resource can be queried to see whether
+     * the resource has been installed or removed.
+     * @param resource The resource
+     */
+    void processed(final TaskResource resource);
+
+    /**
+     * Indication that the installer starts a new cycle.
+     * Several starting methods might be invoked one after
+     * the other without a processed or suspended inbetween.
+     */
+    void started();
+
+    /**
+     * The installer is suspended and has processed all current
+     * resources.
+     */
+    void suspended();
+}

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallationListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallationListener.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/api/tasks/InstallationListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java?rev=1164395&r1=1164394&r2=1164395&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/EntityResourceList.java
Fri Sep  2 08:25:32 2011
@@ -27,6 +27,7 @@ import java.util.List;
 import java.util.SortedSet;
 import java.util.TreeSet;
 
+import org.apache.sling.installer.api.tasks.InstallationListener;
 import org.apache.sling.installer.api.tasks.RegisteredResource;
 import org.apache.sling.installer.api.tasks.ResourceState;
 import org.apache.sling.installer.api.tasks.TaskResource;
@@ -58,8 +59,12 @@ public class EntityResourceList implemen
     /** The resource id of this group. */
     private String resourceId;
 
-    public EntityResourceList(final String resourceId) {
+    /** The listener. */
+    private transient InstallationListener listener;
+
+    public EntityResourceList(final String resourceId, final InstallationListener listener)
{
         this.resourceId = resourceId;
+        this.listener = listener;
     }
     /**
      * Serialize the object
@@ -180,6 +185,13 @@ public class EntityResourceList implemen
     }
 
     /**
+     * Set the listener
+     */
+    public void setListener(final InstallationListener listener) {
+        this.listener = listener;
+    }
+
+    /**
      * @see org.apache.sling.installer.api.tasks.TaskResourceGroup#setFinishState(org.apache.sling.installer.api.tasks.ResourceState)
      */
     public void setFinishState(ResourceState state) {
@@ -219,6 +231,7 @@ public class EntityResourceList implemen
 
             }
             ((RegisteredResourceImpl)toActivate).setState(state);
+            this.listener.processed(toActivate);
             if ( state == ResourceState.UNINSTALLED ) {
                 this.cleanup(toActivate);
             }

Added: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallListener.java?rev=1164395&view=auto
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallListener.java
(added)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallListener.java
Fri Sep  2 08:25:32 2011
@@ -0,0 +1,68 @@
+/*
+ * 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.installer.core.impl;
+
+import org.apache.sling.installer.api.tasks.InstallationListener;
+import org.apache.sling.installer.api.tasks.TaskResource;
+import org.osgi.framework.BundleContext;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class InstallListener implements InstallationListener {
+
+    private final ServiceTracker tracker;
+
+    public InstallListener(final BundleContext context) {
+        this.tracker = new ServiceTracker(context, InstallationListener.class.getName(),
null);
+        this.tracker.open();
+    }
+
+    public void dispose() {
+        this.tracker.close();
+    }
+
+    /**
+     * @see org.apache.sling.installer.api.tasks.InstallationListener#processed(org.apache.sling.installer.api.tasks.TaskResource)
+     */
+    public void processed(final TaskResource resource) {
+        final InstallationListener l = (InstallationListener) this.tracker.getService();
+        if ( l != null ) {
+            l.processed(resource);
+        }
+    }
+
+    /**
+     * @see org.apache.sling.installer.api.tasks.InstallationListener#started()
+     */
+    public void started() {
+        final InstallationListener l = (InstallationListener) this.tracker.getService();
+        if ( l != null ) {
+            l.started();
+        }
+    }
+
+    /**
+     * @see org.apache.sling.installer.api.tasks.InstallationListener#suspended()
+     */
+    public void suspended() {
+        final InstallationListener l = (InstallationListener) this.tracker.getService();
+        if ( l != null ) {
+            l.suspended();
+        }
+    }
+}

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallListener.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java?rev=1164395&r1=1164394&r2=1164395&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/OsgiInstallerImpl.java
Fri Sep  2 08:25:32 2011
@@ -110,13 +110,16 @@ public class OsgiInstallerImpl
     /** New resources lock. */
     private final Object resourcesLock = new Object();
 
+    private final InstallListener listener;
+
     /** Constructor */
     public OsgiInstallerImpl(final BundleContext ctx) {
         this.ctx = ctx;
         // Initialize file util
         new FileDataStore(ctx);
         final File f = FileDataStore.SHARED.getDataFile("RegisteredResourceList.ser");
-        this.persistentList = new PersistentResourceList(f);
+        this.listener = new InstallListener(ctx);
+        this.persistentList = new PersistentResourceList(f, listener);
     }
 
     /**
@@ -133,6 +136,8 @@ public class OsgiInstallerImpl
         ctx.removeBundleListener(this);
         ctx.removeFrameworkListener(this);
 
+        this.listener.dispose();
+
         // wake up sleeping thread
         this.wakeUp();
         this.logger.debug("Waiting for installer thread to stop");
@@ -171,6 +176,7 @@ public class OsgiInstallerImpl
     public void run() {
         this.init();
         while (active) {
+            listener.started();
             logger.debug("Starting new cycle");
 
             this.mergeNewlyRegisteredResources();
@@ -195,6 +201,7 @@ public class OsgiInstallerImpl
                         // No tasks to execute - wait until new resources are
                         // registered
                         logger.debug("No tasks to process, going idle");
+                        listener.suspended();
                         try {
                             this.resourcesLock.wait();
                         } catch (InterruptedException ignore) {}

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java?rev=1164395&r1=1164394&r2=1164395&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/PersistentResourceList.java
Fri Sep  2 08:25:32 2011
@@ -34,6 +34,7 @@ import java.util.List;
 import java.util.Map;
 
 import org.apache.sling.installer.api.InstallableResource;
+import org.apache.sling.installer.api.tasks.InstallationListener;
 import org.apache.sling.installer.api.tasks.RegisteredResource;
 import org.apache.sling.installer.api.tasks.TaskResource;
 import org.apache.sling.installer.api.tasks.TransformationResult;
@@ -66,9 +67,12 @@ public class PersistentResourceList {
     /** All untransformed resources. */
     private final List<RegisteredResource> untransformedResources;
 
+    private final InstallationListener listener;
+
     @SuppressWarnings("unchecked")
-    public PersistentResourceList(final File dataFile) {
+    public PersistentResourceList(final File dataFile, final InstallationListener listener)
{
         this.dataFile = dataFile;
+        this.listener = listener;
 
         Map<String, EntityResourceList> restoredData = null;
         List<RegisteredResource> unknownList = null;
@@ -107,6 +111,7 @@ public class PersistentResourceList {
         // update resource ids
         for(final Map.Entry<String, EntityResourceList> entry : this.data.entrySet())
{
             entry.getValue().setResourceId(entry.getKey());
+            entry.getValue().setListener(listener);
         }
     }
 
@@ -192,7 +197,7 @@ public class PersistentResourceList {
 
             EntityResourceList t = this.data.get(input.getEntityId());
             if (t == null) {
-                t = new EntityResourceList(input.getEntityId());
+                t = new EntityResourceList(input.getEntityId(), this.listener);
                 this.data.put(input.getEntityId(), t);
             }
 

Modified: sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/TaskOrderingTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/TaskOrderingTest.java?rev=1164395&r1=1164394&r2=1164395&view=diff
==============================================================================
--- sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/TaskOrderingTest.java
(original)
+++ sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/TaskOrderingTest.java
Fri Sep  2 08:25:32 2011
@@ -33,6 +33,7 @@ import org.apache.sling.installer.core.i
 import org.apache.sling.installer.core.impl.tasks.BundleRemoveTask;
 import org.apache.sling.installer.core.impl.tasks.BundleStartTask;
 import org.apache.sling.installer.core.impl.tasks.BundleUpdateTask;
+import org.apache.sling.installer.core.impl.tasks.MockInstallationListener;
 import org.apache.sling.installer.core.impl.tasks.SynchronousRefreshPackagesTask;
 
 /** Test the ordering and duplicates elimination of
@@ -64,7 +65,7 @@ public class TaskOrderingTest {
         }
         rr = (RegisteredResourceImpl)rr.clone(tr[0]);
 
-        final EntityResourceList erl = new EntityResourceList("test");
+        final EntityResourceList erl = new EntityResourceList("test", new MockInstallationListener());
 	    erl.addOrUpdate(rr);
 	    return erl;
 	}

Modified: sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/BundleTaskCreatorTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/BundleTaskCreatorTest.java?rev=1164395&r1=1164394&r2=1164395&view=diff
==============================================================================
--- sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/BundleTaskCreatorTest.java
(original)
+++ sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/BundleTaskCreatorTest.java
Fri Sep  2 08:25:32 2011
@@ -44,7 +44,7 @@ public class BundleTaskCreatorTest {
 	    }
 		final SortedSet<InstallTask> tasks = new TreeSet<InstallTask>();
         for(final TaskResource r : sortedResources) {
-            final EntityResourceList erl = new EntityResourceList(r.getEntityId());
+            final EntityResourceList erl = new EntityResourceList(r.getEntityId(), new MockInstallationListener());
             erl.addOrUpdate(r);
   		    tasks.add(btc.createTask(erl));
         }

Added: sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/MockInstallationListener.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/MockInstallationListener.java?rev=1164395&view=auto
==============================================================================
--- sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/MockInstallationListener.java
(added)
+++ sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/MockInstallationListener.java
Fri Sep  2 08:25:32 2011
@@ -0,0 +1,35 @@
+/*
+ * 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.installer.core.impl.tasks;
+
+import org.apache.sling.installer.api.tasks.InstallationListener;
+import org.apache.sling.installer.api.tasks.TaskResource;
+
+public class MockInstallationListener implements InstallationListener {
+
+    public void processed(TaskResource resource) {
+    }
+
+    public void started() {
+    }
+
+    public void suspended() {
+    }
+
+}

Propchange: sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/MockInstallationListener.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/MockInstallationListener.java
------------------------------------------------------------------------------
    svn:keywords = author date id revision rev url

Propchange: sling/trunk/installer/core/src/test/java/org/apache/sling/installer/core/impl/tasks/MockInstallationListener.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message