sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r1767229 - in /sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl: EntityResourceList.java InstallListener.java OsgiInstallerImpl.java SortingServiceTracker.java
Date Mon, 31 Oct 2016 09:25:02 GMT
Author: cziegeler
Date: Mon Oct 31 09:25:02 2016
New Revision: 1767229

URL: http://svn.apache.org/viewvc?rev=1767229&view=rev
Log:
SLING-5779 : Packaged OSGi config intermittently do not get installed before bundle start

Modified:
    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/InstallListener.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/SortingServiceTracker.java

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=1767229&r1=1767228&r2=1767229&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
Mon Oct 31 09:25:02 2016
@@ -240,7 +240,6 @@ public class EntityResourceList implemen
      * @see org.apache.sling.installer.api.tasks.TaskResourceGroup#setFinishState(org.apache.sling.installer.api.tasks.ResourceState)
      */
     @Override
-    @Deprecated
     public void setFinishState(ResourceState state) {
         setFinishState(state, null);
     }
@@ -332,7 +331,9 @@ public class EntityResourceList implemen
      */
     @Override
     public void setFinishState(final ResourceState state, final String alias, String error)
{
-        this.alias = alias;
+        if ( this.alias == null || alias != null ) {
+            this.alias = alias;
+        }
         this.setFinishState(state, error);
     }
 

Modified: 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=1767229&r1=1767228&r2=1767229&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallListener.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/InstallListener.java
Mon Oct 31 09:25:02 2016
@@ -33,16 +33,20 @@ public class InstallListener implements
     /** Start event. */
     private static final InstallationEvent START_EVENT = new InstallationEvent() {
 
+        @Override
         public TYPE getType() { return TYPE.STARTED; }
 
+        @Override
         public Object getSource() { return null; }
     };
 
     /** Suspend event. */
     private static final InstallationEvent SUSPENDED_EVENT = new InstallationEvent() {
 
+        @Override
         public TYPE getType() { return TYPE.SUSPENDED; }
 
+        @Override
         public Object getSource() { return null; }
     };
 
@@ -74,6 +78,7 @@ public class InstallListener implements
     /**
      * @see org.apache.sling.installer.api.event.InstallationListener#onEvent(org.apache.sling.installer.api.event.InstallationEvent)
      */
+    @Override
     public void onEvent(final InstallationEvent event) {
         if ( this.logger.isDebugEnabled() ) {
             if ( event.getType() == InstallationEvent.TYPE.STARTED ) {
@@ -100,6 +105,7 @@ public class InstallListener implements
      */
     public synchronized void start() {
         if ( ! this.started ) {
+            this.logger.debug("Starting new installer cycle");
             this.started = true;
             this.onEvent(START_EVENT);
         }

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=1767229&r1=1767228&r2=1767229&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
Mon Oct 31 09:25:02 2016
@@ -113,6 +113,9 @@ implements OsgiInstaller, ResourceChange
     /** Update infos to process. */
     private final List<UpdateInfo> updateInfos = new ArrayList<OsgiInstallerImpl.UpdateInfo>();
 
+    /** Are the required services satisfied? */
+    private volatile boolean satisfied = false;
+
     /** Are we still activate? */
     private volatile boolean active = true;
 
@@ -230,6 +233,7 @@ implements OsgiInstaller, ResourceChange
         this.updateHandlerTracker.open();
 
         this.logger.info("Apache Sling OSGi Installer Service started.");
+        this.checkSatisfied();
     }
 
     /**
@@ -252,7 +256,6 @@ implements OsgiInstaller, ResourceChange
             this.init();
 
             while (this.active) {
-                this.logger.debug("Starting new installer cycle");
                 this.listener.start();
 
                 processUpdateInfos();
@@ -261,6 +264,14 @@ implements OsgiInstaller, ResourceChange
                 this.mergeNewlyRegisteredResources();
 
                 synchronized ( this.resourcesLock ) {
+                    if ( !this.satisfied ) {
+                        logger.debug("Required services are not available yet.");
+                        try {
+                            logger.debug("wait() on resourcesLock");
+                            this.resourcesLock.wait();
+                        } catch (final InterruptedException ignore) {}
+                        continue;
+                    }
                     this.retryDuringTaskExecution = false;
                 }
 
@@ -941,6 +952,33 @@ implements OsgiInstaller, ResourceChange
         }
     }
 
+    private void checkSatisfied() {
+        synchronized ( this.resourcesLock ) {
+            if ( !this.satisfied ) {
+                this.satisfied = true;
+                if ( this.ctx.getProperty(PROP_REQUIRED_SERVICES) != null ) {
+                    final String[] reqs = this.ctx.getProperty(PROP_REQUIRED_SERVICES).split(",");
+                    this.satisfied = true;
+                    for(final String val : reqs) {
+                        if ( val.startsWith("resourcetransformer:") ) {
+                            final String name = val.substring(20);
+
+                            this.satisfied = this.transformerTracker.check(ResourceTransformer.NAME,
name);
+
+                        } else if ( val.startsWith("installtaskfactory:") ) {
+                            final String name = val.substring(19);
+
+                            this.satisfied = this.factoryTracker.check(InstallTaskFactory.NAME,
name);
+
+                        } else {
+                            logger.warn("Invalid requirements for installer: {}", val);
+                        }
+                    }
+                }
+            }
+        }
+    }
+
     /**
      * @see org.apache.sling.installer.api.tasks.RetryHandler#scheduleRetry()
      */
@@ -950,6 +988,7 @@ implements OsgiInstaller, ResourceChange
         this.listener.start();
         synchronized ( this.resourcesLock ) {
             this.retryDuringTaskExecution = true;
+            this.checkSatisfied();
         }
         this.wakeUp();
     }

Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java?rev=1767229&r1=1767228&r2=1767229&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java
(original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/SortingServiceTracker.java
Mon Oct 31 09:25:02 2016
@@ -36,7 +36,7 @@ public class SortingServiceTracker<T> ex
         super(context, clazz);
         this.listener = listener;
     }
-    
+
     /**
      * @see org.osgi.util.tracker.ServiceTrackerCustomizer#addingService(org.osgi.framework.ServiceReference)
      */
@@ -50,5 +50,23 @@ public class SortingServiceTracker<T> ex
         return returnValue;
     }
 
-    
+    /**
+     * Check if a service with the given name is registered.
+     * @param name Name
+     * @return {@code true} if it exists, {@code false} otherwise.
+     */
+    public boolean check(final String key, final String name) {
+        final ServiceReference[] refs = this.getServiceReferences();
+        if ( refs != null ) {
+            for(final ServiceReference ref : refs) {
+                final Object val = ref.getProperty(key);
+                if ( name.equals(val) ) {
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+
 }



Mime
View raw message