Author: cziegeler
Date: Wed Feb 8 22:02:25 2012
New Revision: 1242130
URL: http://svn.apache.org/viewvc?rev=1242130&view=rev
Log:
SLING-2406 : Installer start event should already be sent when resources are
provisioned
Modified:
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
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=1242130&r1=1242129&r2=1242130&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
Wed Feb 8 22:02:25 2012
@@ -20,18 +20,53 @@ package org.apache.sling.installer.core.
import org.apache.sling.installer.api.event.InstallationEvent;
import org.apache.sling.installer.api.event.InstallationListener;
+import org.apache.sling.installer.api.tasks.TaskResource;
import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
+import org.slf4j.Logger;
+/**
+ * Proxy component for notifying all registered {@link InstallationListener}s.
+ */
public class InstallListener implements InstallationListener {
+ /** Start event. */
+ private static final InstallationEvent START_EVENT = new
InstallationEvent() {
+
+ public TYPE getType() { return TYPE.STARTED; }
+
+ public Object getSource() { return null; }
+ };
+
+ /** Suspend event. */
+ private static final InstallationEvent SUSPENDED_EVENT = new
InstallationEvent() {
+
+ public TYPE getType() { return TYPE.SUSPENDED; }
+
+ public Object getSource() { return null; }
+ };
+
+ /** Service tracker for the listeners. */
private final ServiceTracker tracker;
- public InstallListener(final BundleContext context) {
+ /** Flag avoiding sending duplicate events. */
+ private volatile boolean started = false;
+
+ /** Logger. */
+ private final Logger logger;
+
+ /**
+ * Start service tracker.
+ */
+ public InstallListener(final BundleContext context, final Logger logger) {
+ this.logger = logger;
this.tracker = new ServiceTracker(context,
InstallationListener.class.getName(), null);
this.tracker.open();
}
+ /**
+ * Stop service tracker.
+ */
public void dispose() {
this.tracker.close();
}
@@ -40,6 +75,16 @@ public class InstallListener implements
* @see
org.apache.sling.installer.api.event.InstallationListener#onEvent(org.apache.sling.installer.api.event.InstallationEvent)
*/
public void onEvent(final InstallationEvent event) {
+ if ( this.logger.isDebugEnabled() ) {
+ if ( event.getType() == InstallationEvent.TYPE.STARTED ) {
+ logger.debug("Notify installer started.");
+ } else if ( event.getType() == InstallationEvent.TYPE.SUSPENDED ) {
+ logger.debug("Notify installer suspended.");
+ } else {
+ final TaskResource src = (TaskResource)event.getSource();
+ logger.debug("Notify processed {}", src);
+ }
+ }
final Object[] listeners = this.tracker.getServices();
if ( listeners != null ) {
for(final Object l : listeners) {
@@ -49,4 +94,24 @@ public class InstallListener implements
}
}
}
+
+ /**
+ * Send started event.
+ */
+ public synchronized void start() {
+ if ( ! this.started ) {
+ this.started = true;
+ this.onEvent(START_EVENT);
+ }
+ }
+
+ /**
+ * Send suspended event.
+ */
+ public void suspend() {
+ if ( this.started ) {
+ this.started = false;
+ this.onEvent(SUSPENDED_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=1242130&r1=1242129&r2=1242130&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
Wed Feb 8 22:02:25 2012
@@ -39,7 +39,6 @@ import org.apache.sling.installer.api.Os
import org.apache.sling.installer.api.ResourceChangeListener;
import org.apache.sling.installer.api.UpdateHandler;
import org.apache.sling.installer.api.UpdateResult;
-import org.apache.sling.installer.api.event.InstallationEvent;
import org.apache.sling.installer.api.tasks.InstallTask;
import org.apache.sling.installer.api.tasks.InstallTaskFactory;
import org.apache.sling.installer.api.tasks.InstallationContext;
@@ -120,7 +119,7 @@ public class OsgiInstallerImpl
// Initialize file util
new FileDataStore(ctx);
final File f =
FileDataStore.SHARED.getDataFile("RegisteredResourceList.ser");
- this.listener = new InstallListener(ctx);
+ this.listener = new InstallListener(ctx, logger);
this.persistentList = new PersistentResourceList(f, listener);
}
@@ -173,31 +172,14 @@ public class OsgiInstallerImpl
this.logger.info("Apache Sling OSGi Installer Service started.");
}
- private static final InstallationEvent START_EVENT = new
InstallationEvent() {
-
- public TYPE getType() { return TYPE.STARTED; }
-
- public Object getSource() { return null; }
- };
-
- private static final InstallationEvent SUSPENDED_EVENT = new
InstallationEvent() {
-
- public TYPE getType() { return TYPE.SUSPENDED; }
-
- public Object getSource() { return null; }
- };
-
@Override
public void run() {
this.backgroundThreadIsRunning = true;
try {
this.init();
- if ( this.active ) {
- this.logger.debug("Starting installer");
- this.listener.onEvent(START_EVENT);
- }
while (this.active) {
+ this.listener.start();
// merge potential new resources
this.mergeNewlyRegisteredResources();
@@ -219,12 +201,12 @@ public class OsgiInstallerImpl
// No tasks to execute - wait until new resources
are
// registered
logger.debug("No tasks to process, going idle");
- listener.onEvent(SUSPENDED_EVENT);
+ this.listener.suspend();
try {
this.resourcesLock.wait();
} catch (final InterruptedException ignore) {}
if ( active ) {
- listener.onEvent(START_EVENT);
+ this.listener.start();
this.logger.debug("Running new installer
cycle");
}
}
@@ -327,10 +309,12 @@ public class OsgiInstallerImpl
public void updateResources(final String scheme,
final InstallableResource[] resources,
final String[] ids) {
+ synchronized ( this.resourcesLock ) {
+ this.listener.start();
+ }
try {
final List<InternalResource> updatedResources =
this.createResources(scheme, resources);
- boolean doProcess = false;
synchronized ( this.resourcesLock ) {
if ( updatedResources != null && updatedResources.size() > 0 )
{
this.newResources.addAll(updatedResources);
@@ -346,7 +330,6 @@ public class OsgiInstallerImpl
urlIter.remove();
}
}
- doProcess = true;
}
if ( ids != null && ids.length > 0 ) {
final Set<String> removedUrls = new HashSet<String>();
@@ -367,12 +350,9 @@ public class OsgiInstallerImpl
rsrcIter.remove();
}
}
- doProcess = true;
}
}
- if ( doProcess ) {
- this.wakeUp();
- }
+ this.wakeUp();
} finally {
// we simply close all input streams now
this.closeInputStreams(resources);
@@ -382,6 +362,9 @@ public class OsgiInstallerImpl
* @see
org.apache.sling.installer.api.OsgiInstaller#registerResources(java.lang.String,
org.apache.sling.installer.api.InstallableResource[])
*/
public void registerResources(final String scheme, final
InstallableResource[] resources) {
+ synchronized ( this.resourcesLock ) {
+ this.listener.start();
+ }
try {
List<InternalResource> registeredResources =
this.createResources(scheme, resources);
if ( registeredResources == null ) {