You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by cz...@apache.org on 2010/06/17 19:40:38 UTC
svn commit: r955684 - in /sling/trunk/installer/osgi/installer/src:
main/java/org/apache/sling/osgi/installer/impl/
main/java/org/apache/sling/osgi/installer/impl/tasks/
test/java/org/apache/sling/osgi/installer/impl/
Author: cziegeler
Date: Thu Jun 17 17:40:37 2010
New Revision: 955684
URL: http://svn.apache.org/viewvc?rev=955684&view=rev
Log:
SLING-1559 : Potential NPE when logging
SLING-1558 : Too much synchronization
Modified:
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
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/OsgiInstallerTask.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerThread.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigRemoveTask.java
sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryConversionTest.java
sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
Modified: 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=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/BundleTaskCreator.java Thu Jun 17 17:40:37 2010
@@ -29,7 +29,6 @@ import org.apache.sling.osgi.installer.i
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
-import org.osgi.service.log.LogService;
/** TaskCreator that processes a list of bundle RegisteredResources */
class BundleTaskCreator {
@@ -88,11 +87,8 @@ class BundleTaskCreator {
// and if we installed it
if(getBundleInfo(ctx, resources.first()) != null) {
if(ctx.getInstalledBundleVersion(symbolicName) == null) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO,
- "Bundle " + symbolicName
+ ctx.logInfo("Bundle " + symbolicName
+ " was not installed by this module, not removed");
- }
} else {
tasks.add(new BundleRemoveTask(resources.first()));
}
@@ -117,17 +113,11 @@ class BundleTaskCreator {
final String installedVersion = ctx.getInstalledBundleVersion(info.symbolicName);
if(info.version.toString().equals(installedVersion)) {
toUpdate = toActivate;
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO,
- "Bundle " + info.symbolicName + " " + installedVersion
+ ctx.logInfo("Bundle " + info.symbolicName + " " + installedVersion
+ " was installed by this module, downgrading to " + newVersion);
- }
} else {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO,
- "Bundle " + info.symbolicName + " " + installedVersion
+ ctx.logInfo("Bundle " + info.symbolicName + " " + installedVersion
+ " was not installed by this module, not downgraded");
- }
}
} else if(compare == 0 && ctx.isSnapshot(newVersion)){
// installed, same version but SNAPSHOT
@@ -140,16 +130,10 @@ class BundleTaskCreator {
if(toUpdate != null) {
final String previousDigest = digests.get(symbolicName);
if(toUpdate.getDigest().equals(previousDigest)) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "Ignoring update of " + toUpdate + ", digest didn't change");
- }
+ ctx.logDebug("Ignoring update of " + toUpdate + ", digest didn't change");
digestToSave = previousDigest;
} else {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "Scheduling update of " + toUpdate + ", digest has changed");
- }
+ ctx.logDebug("Scheduling update of " + toUpdate + ", digest has changed");
tasks.add(new BundleUpdateTask(toUpdate));
digestToSave = toUpdate.getDigest();
}
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/ConfigTaskCreator.java Thu Jun 17 17:40:37 2010
@@ -24,7 +24,6 @@ import java.util.SortedSet;
import org.apache.sling.osgi.installer.impl.tasks.ConfigInstallTask;
import org.apache.sling.osgi.installer.impl.tasks.ConfigRemoveTask;
-import org.osgi.service.log.LogService;
/** TaskCreator that processes a list of config RegisteredResources */
class ConfigTaskCreator {
@@ -56,16 +55,11 @@ class ConfigTaskCreator {
final String key = getDigestKey(toActivate);
final String previousDigest = digests.get(key);
if(toActivate.getDigest().equals(previousDigest)) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Configuration (" + key+ ") already installed, ignored: " + toActivate);
- }
+ ctx.logDebug("Configuration (" + key+ ") already installed, ignored: " + toActivate);
} else {
tasks.add(new ConfigInstallTask(toActivate));
digests.put(key, toActivate.getDigest());
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "Scheduling update/install of config " + toActivate + ", digest has changed or was absent");
- }
+ ctx.logDebug("Scheduling update/install of config " + toActivate + ", digest has changed or was absent");
}
}
}
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerContext.java Thu Jun 17 17:40:37 2010
@@ -24,38 +24,50 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Version;
import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.log.LogService;
import org.osgi.service.packageadmin.PackageAdmin;
/** Installer context, gives access to selected methods of the {@link OsgiInstallerImpl} */
public interface OsgiInstallerContext {
- BundleContext getBundleContext();
+
+ BundleContext getBundleContext();
PackageAdmin getPackageAdmin();
ConfigurationAdmin getConfigurationAdmin();
- LogService getLogService();
void incrementCounter(int index);
void setCounter(int index, long value);
Bundle getMatchingBundle(String bundleSymbolicName);
boolean isSnapshot(Version v);
-
+
/** Schedule a task for execution in the current OsgiController cycle */
void addTaskToCurrentCycle(OsgiInstallerTask t);
-
- /** Schedule a task for execution in the next OsgiController cycle,
- * usually to indicate that a task must be retried
+
+ /** Schedule a task for execution in the next OsgiController cycle,
+ * usually to indicate that a task must be retried
*/
void addTaskToNextCycle(OsgiInstallerTask t);
-
+
/** Store a bundle's digest and installed version, keyed by symbolic ID */
void saveInstalledBundleInfo(Bundle b, String digest, String version) throws IOException;
-
- /** Retrieve a bundle's digest that was stored by saveInstalledBundleInfo
- * @return null if no digest was stored
+
+ /** Retrieve a bundle's digest that was stored by saveInstalledBundleInfo
+ * @return null if no digest was stored
* */
String getInstalledBundleDigest(Bundle b) throws IOException;
-
- /** Retrieve a bundle's version that was stored by saveInstalledBundleInfo
- * @return null if no version was stored
+
+ /** Retrieve a bundle's version that was stored by saveInstalledBundleInfo
+ * @return null if no version was stored
* */
String getInstalledBundleVersion(String symbolicName) throws IOException;
+
+
+ void logDebug(final String message);
+
+ void logDebug(final String message, final Throwable t);
+
+ void logInfo(final String message);
+
+ void logInfo(final String message, final Throwable t);
+
+ void logWarn(final String message);
+
+ void logWarn(final String message, final Throwable t);
}
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=955684&r1=955683&r2=955684&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 Thu Jun 17 17:40:37 2010
@@ -37,14 +37,14 @@ import org.osgi.util.tracker.ServiceTrac
public class OsgiInstallerImpl implements OsgiInstaller, OsgiInstallerContext {
public static final String MAVEN_SNAPSHOT_MARKER = "SNAPSHOT";
-
+
private final BundleContext bundleContext;
private final PackageAdmin packageAdmin;
private final ServiceTracker logServiceTracker;
private final OsgiInstallerThread installerThread;
private long [] counters = new long[COUNTERS_SIZE];
- private PersistentBundleInfo bundleDigestsStorage;
-
+ private PersistentBundleInfo bundleDigestsStorage;
+
public OsgiInstallerImpl(final BundleContext bc,
final PackageAdmin pa,
final ServiceTracker logServiceTracker)
@@ -53,7 +53,7 @@ public class OsgiInstallerImpl implement
this.packageAdmin = pa;
this.logServiceTracker = logServiceTracker;
bundleDigestsStorage = new PersistentBundleInfo(this, bc.getDataFile("bundle-digests.properties"));
-
+
installerThread = new OsgiInstallerThread(this);
installerThread.setDaemon(true);
installerThread.start();
@@ -61,23 +61,18 @@ public class OsgiInstallerImpl implement
public void deactivate() throws InterruptedException, IOException {
installerThread.deactivate();
-
+
final TreeSet<String> installedBundlesSymbolicNames = new TreeSet<String>();
for(Bundle b : bundleContext.getBundles()) {
installedBundlesSymbolicNames.add(b.getSymbolicName());
}
bundleDigestsStorage.purgeAndSave(installedBundlesSymbolicNames);
-
- if(getLogService() != null) {
- getLogService().log(LogService.LOG_INFO, "Waiting for installer thread to stop");
- }
+
+ this.logInfo("Waiting for installer thread to stop");
installerThread.join();
-
- if(getLogService() != null) {
- getLogService().log(LogService.LOG_WARNING,
- OsgiInstaller.class.getName()
+
+ this.logWarn(OsgiInstaller.class.getName()
+ " service deactivated - this warning can be ignored if system is shutting down");
- }
}
public ConfigurationAdmin getConfigurationAdmin() {
@@ -90,59 +85,46 @@ public class OsgiInstallerImpl implement
return null;
}
- public LogService getLogService() {
- return (LogService)logServiceTracker.getService();
- }
-
public void addTaskToCurrentCycle(OsgiInstallerTask t) {
installerThread.addTaskToCurrentCycle(t);
}
public void addTaskToNextCycle(OsgiInstallerTask t) {
- if(getLogService() != null) {
- getLogService().log(LogService.LOG_DEBUG, "adding task to next cycle:" + t);
- }
+ this.logDebug("adding task to next cycle:" + t);
installerThread.addTaskToNextCycle(t);
}
public BundleContext getBundleContext() {
return bundleContext;
}
-
+
public PackageAdmin getPackageAdmin() {
return packageAdmin;
}
-
+
public long [] getCounters() {
return counters;
}
+ /**
+ * @see org.apache.sling.osgi.installer.OsgiInstaller#addResource(org.apache.sling.osgi.installer.InstallableResource)
+ */
public void addResource(InstallableResource r) {
- RegisteredResource rr = null;
- try {
- rr = new RegisteredResourceImpl(this, r);
- } catch(IOException ioe) {
- if(getLogService() != null) {
- getLogService().log(
- LogService.LOG_WARNING,
- "Cannot create RegisteredResource (resource will be ignored):" + r, ioe);
- }
- return;
- }
-
- synchronized (installerThread) {
- installerThread.addNewResource(rr);
- }
+ installerThread.addNewResource(r);
}
+ /**
+ * @see org.apache.sling.osgi.installer.OsgiInstaller#registerResources(java.util.Collection, java.lang.String)
+ */
public void registerResources(Collection<InstallableResource> data, String urlScheme) {
installerThread.addNewResources(data, urlScheme, bundleContext);
}
+ /**
+ * @see org.apache.sling.osgi.installer.OsgiInstaller#removeResource(org.apache.sling.osgi.installer.InstallableResource)
+ */
public void removeResource(InstallableResource r) {
- synchronized (installerThread) {
- installerThread.removeResource(r);
- }
+ installerThread.removeResource(r);
}
public void incrementCounter(int index) {
@@ -152,7 +134,7 @@ public class OsgiInstallerImpl implement
public void setCounter(int index, long value) {
counters[index] = value;
}
-
+
/**
* Finds the bundle with given symbolic name in our BundleContext.
*/
@@ -167,7 +149,7 @@ public class OsgiInstallerImpl implement
}
return null;
}
-
+
public boolean isSnapshot(Version v) {
return v.toString().indexOf(MAVEN_SNAPSHOT_MARKER) >= 0;
}
@@ -189,4 +171,61 @@ public class OsgiInstallerImpl implement
public void saveInstalledBundleInfo(Bundle b, String digest, String version) throws IOException {
bundleDigestsStorage.putInfo(b.getSymbolicName(), digest, version);
}
- }
\ No newline at end of file
+
+ /**
+ * Internal method for logging.
+ * This method checks if the LogService is available and only then logs
+ */
+ private void log(final int level, final String message, final Throwable t) {
+ final LogService ls = (LogService) this.logServiceTracker.getService();
+ if ( ls != null ) {
+ if ( t != null ) {
+ ls.log(level, message, t);
+ } else {
+ ls.log(level, message);
+ }
+ }
+ }
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logDebug(java.lang.String, java.lang.Throwable)
+ */
+ public void logDebug(String message, Throwable t) {
+ log(LogService.LOG_DEBUG, message, t);
+ }
+
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logDebug(java.lang.String)
+ */
+ public void logDebug(String message) {
+ log(LogService.LOG_DEBUG, message, null);
+ }
+
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logInfo(java.lang.String, java.lang.Throwable)
+ */
+ public void logInfo(String message, Throwable t) {
+ log(LogService.LOG_INFO, message, t);
+ }
+
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logInfo(java.lang.String)
+ */
+ public void logInfo(String message) {
+ log(LogService.LOG_INFO, message, null);
+ }
+
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logWarn(java.lang.String, java.lang.Throwable)
+ */
+ public void logWarn(String message, Throwable t) {
+ log(LogService.LOG_WARNING, message, t);
+ }
+
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logWarn(java.lang.String)
+ */
+ public void logWarn(String message) {
+ log(LogService.LOG_WARNING, message, null);
+ }
+
+}
\ No newline at end of file
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/OsgiInstallerTask.java Thu Jun 17 17:40:37 2010
@@ -18,18 +18,15 @@
*/
package org.apache.sling.osgi.installer.impl;
-import org.osgi.service.log.LogService;
-/** Base class for tasks that can be executed by the {@link OsgiInstallerImpl} */
+/** Base class for tasks that can be executed by the {@link OsgiInstallerImpl} */
public abstract class OsgiInstallerTask implements Comparable<OsgiInstallerTask> {
public abstract void execute(OsgiInstallerContext ctx) throws Exception;
protected void logExecution(OsgiInstallerContext ctx) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO, "OsgiInstallerTask: executing " + this);
- }
+ ctx.logInfo("OsgiInstallerTask: executing " + this);
}
-
+
/** Tasks are sorted according to this key */
public abstract String getSortKey();
@@ -37,12 +34,12 @@ public abstract class OsgiInstallerTask
public final int compareTo(OsgiInstallerTask o) {
return getSortKey().compareTo(o.getSortKey());
}
-
+
/** Is it worth executing this task now? */
public boolean isExecutable(OsgiInstallerContext ctx) throws Exception {
return true;
}
-
+
/** Can the task be retried after {@link execute} failed? */
public boolean canRetry(OsgiInstallerContext ctx) {
return true;
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=955684&r1=955683&r2=955684&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 Thu Jun 17 17:40:37 2010
@@ -35,18 +35,17 @@ import org.apache.sling.osgi.installer.O
import org.osgi.framework.BundleContext;
import org.osgi.framework.BundleEvent;
import org.osgi.framework.BundleListener;
-import org.osgi.service.log.LogService;
/** Worker thread where all OSGi tasks are executed.
* Runs cycles where the list of RegisteredResources is examined,
* OsgiTasks are created accordingly and executed.
- *
+ *
* A separate list of RegisteredResources is kept for resources
* that are updated or removed during a cycle, and merged with
* the main list at the end of the cycle.
*/
class OsgiInstallerThread extends Thread implements BundleListener {
-
+
private final OsgiInstallerContext ctx;
private final List<RegisteredResource> newResources = new LinkedList<RegisteredResource>();
private final SortedSet<OsgiInstallerTask> tasks = new TreeSet<OsgiInstallerTask>();
@@ -56,14 +55,14 @@ class OsgiInstallerThread extends Thread
private final Set<String> urlsToRemove = new HashSet<String>();
private boolean active = true;
private boolean retriesScheduled;
-
- /** Group our RegisteredResource by OSGi entity */
+
+ /** Group our RegisteredResource by OSGi entity */
private final HashMap<String, SortedSet<RegisteredResource>> registeredResources;
private final PersistentResourceList persistentList;
-
+
private final BundleTaskCreator bundleTaskCreator = new BundleTaskCreator();
private final ConfigTaskCreator configTaskCreator = new ConfigTaskCreator();
-
+
OsgiInstallerThread(OsgiInstallerContext ctx) {
setName(getClass().getSimpleName());
this.ctx = ctx;
@@ -79,99 +78,92 @@ class OsgiInstallerThread extends Thread
newResources.notify();
}
}
-
+
@Override
public void run() {
ctx.getBundleContext().addBundleListener(this);
-
+
while(active) {
try {
mergeNewResources();
computeTasks();
-
+
if(tasks.isEmpty() && !retriesScheduled) {
// No tasks to execute - wait until new resources are
// registered
cleanupInstallableResources();
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "No tasks to process, going idle");
- }
- ctx.setCounter(OsgiInstaller.WORKER_THREAD_IS_IDLE_COUNTER, 1);
+ ctx.logDebug("No tasks to process, going idle");
+
+ ctx.setCounter(OsgiInstaller.WORKER_THREAD_IS_IDLE_COUNTER, 1);
ctx.incrementCounter(OsgiInstaller.WORKER_THREAD_BECOMES_IDLE_COUNTER);
synchronized (newResources) {
newResources.wait();
}
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Notified of new resources, back to work");
- }
+ ctx.logDebug("Notified of new resources, back to work");
ctx.setCounter(OsgiInstaller.WORKER_THREAD_IS_IDLE_COUNTER, 0);
continue;
}
-
+
retriesScheduled = false;
if(executeTasks() > 0) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Tasks have been executed, saving persistentList");
- }
+ ctx.logDebug("Tasks have been executed, saving persistentList");
persistentList.save();
}
-
+
// Some integration tests depend on this delay, make sure to
// rerun/adapt them if changing this value
Thread.sleep(250);
cleanupInstallableResources();
} catch(Exception e) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_WARNING, e.toString(), e);
- }
+ ctx.logWarn(e.toString(), e);
try {
Thread.sleep(1000);
} catch(InterruptedException ignored) {
}
}
}
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO, "Deactivated, exiting");
- }
+ ctx.logInfo("Deactivated, exiting");
}
-
+
void addTaskToCurrentCycle(OsgiInstallerTask t) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "adding task to current cycle:" + t);
- }
+ ctx.logDebug("adding task to current cycle:" + t);
synchronized (tasks) {
tasks.add(t);
}
}
-
+
/** Register a resource for removal, or ignore if we don't have that URL */
void removeResource(InstallableResource r) {
if(!r.isEmpty()) {
throw new IllegalArgumentException("removeResource() got non-empty InstallableResource: " + r);
}
-
+
// Will mark all resources which have r's URL as uninstallable
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Adding URL " + r.getUrl() + " to urlsToRemove");
- }
-
+ ctx.logDebug("Adding URL " + r.getUrl() + " to urlsToRemove");
+
synchronized (newResources) {
urlsToRemove.add(r.getUrl());
newResources.notify();
}
}
-
+
/** Register a single new resource, will be processed on the next cycle */
- void addNewResource(RegisteredResource r) {
+ void addNewResource(final InstallableResource r) {
+ RegisteredResource rr = null;
+ try {
+ rr = new RegisteredResourceImpl(ctx, r);
+ } catch(IOException ioe) {
+ ctx.logWarn("Cannot create RegisteredResource (resource will be ignored):" + r, ioe);
+ return;
+ }
+
synchronized (newResources) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Adding new resource " + r);
- }
- newResources.add(r);
+ ctx.logDebug("Adding new resource " + r);
+ newResources.add(rr);
newResources.notify();
}
}
-
+
/** Register a number of new resources, and mark others having the same scheme as not installable.
* Used with {@link OsgiInstaller.registerResources}
*/
@@ -183,39 +175,31 @@ class OsgiInstallerThread extends Thread
try {
rr = new RegisteredResourceImpl(ctx, r);
} catch(IOException ioe) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(
- LogService.LOG_WARNING,
- "Cannot create RegisteredResource (resource will be ignored):" + r, ioe);
- }
+ ctx.logWarn("Cannot create RegisteredResource (resource will be ignored):" + r, ioe);
continue;
}
-
+
if(!rr.getUrlScheme().equals(urlScheme)) {
throw new IllegalArgumentException(
"URL of all supplied InstallableResource must start with supplied scheme"
+ ", scheme is not '" + urlScheme + "' for URL " + r.getUrl());
}
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Adding new resource " + r);
- }
+ ctx.logDebug("Adding new resource " + r);
toAdd.add(rr);
}
-
+
synchronized (newResources) {
if(!toAdd.isEmpty()) {
newResourcesSets.add(toAdd);
}
// Need to manage schemes separately: in case toAdd is empty we
// want to mark all such resources as non-installable
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Adding to newResourcesSchemes: " + urlScheme);
- }
+ ctx.logDebug("Adding to newResourcesSchemes: " + urlScheme);
newResourcesSchemes.add(urlScheme);
newResources.notify();
}
}
-
+
private void mergeNewResources() {
synchronized (newResources) {
// If we have sets of new resources, each of them represents the complete list
@@ -223,54 +207,43 @@ class OsgiInstallerThread extends Thread
// all resources with the same scheme in newResources, and existing
// registeredResources, as not installable
for(String scheme : newResourcesSchemes) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Processing set of new resources with scheme " + scheme);
- }
+ ctx.logDebug("Processing set of new resources with scheme " + scheme);
for(RegisteredResource r : newResources) {
if(r.getUrlScheme().equals(scheme)) {
r.setInstallable(false);
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "New resource set to non-installable: " + r);
- }
+ ctx.logDebug("New resource set to non-installable: " + r);
}
}
for(SortedSet<RegisteredResource> ss : registeredResources.values()) {
for(RegisteredResource r : ss) {
if(r.getUrlScheme().equals(scheme)) {
r.setInstallable(false);
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Existing resource set to non-installable: " + r);
- }
+ ctx.logDebug("Existing resource set to non-installable: " + r);
}
}
}
}
for(SortedSet<RegisteredResource> s : newResourcesSets) {
newResources.addAll(s);
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "Added set of " + s.size() + " new resources with scheme "
+ ctx.logDebug("Added set of " + s.size() + " new resources with scheme "
+ s.first().getUrlScheme() + ": " + s);
- }
}
newResourcesSets.clear();
newResourcesSchemes.clear();
-
+
for(RegisteredResource r : newResources) {
SortedSet<RegisteredResource> t = registeredResources.get(r.getEntityId());
if(t == null) {
t = createRegisteredResourcesEntry();
registeredResources.put(r.getEntityId(), t);
}
-
+
// If an object with same sort key is already present, replace with the
// new one which might have different attributes
if(t.contains(r)) {
for(RegisteredResource rr : t) {
if(t.comparator().compare(rr, r) == 0) {
- if(ctx.getLogService()!= null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Cleanup obsolete " + rr);
- }
+ ctx.logDebug("Cleanup obsolete " + rr);
rr.cleanup(ctx);
}
}
@@ -279,17 +252,13 @@ class OsgiInstallerThread extends Thread
t.add(r);
}
newResources.clear();
-
+
// Mark resources for removal according to urlsToRemove
if(!urlsToRemove.isEmpty()) {
for(SortedSet<RegisteredResource> group : registeredResources.values()) {
for(RegisteredResource r : group) {
if(urlsToRemove.contains(r.getUrl())) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "Marking " + r + " uninistallable, URL is included in urlsToRemove"
- );
- }
+ ctx.logDebug("Marking " + r + " uninistallable, URL is included in urlsToRemove");
r.setInstallable(false);
}
}
@@ -298,7 +267,7 @@ class OsgiInstallerThread extends Thread
urlsToRemove.clear();
}
}
-
+
void addTaskToNextCycle(OsgiInstallerTask t) {
synchronized (tasksForNextCycle) {
tasksForNextCycle.add(t);
@@ -309,9 +278,9 @@ class OsgiInstallerThread extends Thread
static SortedSet<RegisteredResource> createRegisteredResourcesEntry() {
return new TreeSet<RegisteredResource>(new RegisteredResourceComparator());
}
-
-
- /** Compute OSGi tasks based on our resources, and add to supplied list of tasks */
+
+
+ /** Compute OSGi tasks based on our resources, and add to supplied list of tasks */
void computeTasks() throws Exception {
// Add tasks that were scheduled for next cycle and are executable now
final List<OsgiInstallerTask> toKeep = new ArrayList<OsgiInstallerTask>();
@@ -326,7 +295,7 @@ class OsgiInstallerThread extends Thread
tasksForNextCycle.clear();
tasksForNextCycle.addAll(toKeep);
}
-
+
// Walk the list of entities, and create appropriate OSGi tasks for each group
// TODO do nothing for a group that's "stable" - i.e. one where no tasks were
// created in the last cycle??
@@ -334,17 +303,17 @@ class OsgiInstallerThread extends Thread
if(group.isEmpty()) {
continue;
}
- final RegisteredResource.ResourceType rt = group.first().getResourceType();
+ final RegisteredResource.ResourceType rt = group.first().getResourceType();
if(rt.equals(RegisteredResource.ResourceType.BUNDLE)) {
bundleTaskCreator.createTasks(ctx, group, tasks);
} else if(rt.equals(RegisteredResource.ResourceType.CONFIG)) {
configTaskCreator.createTasks(ctx, group, tasks);
} else {
throw new IllegalArgumentException("No TaskCreator for resource type "+ group.first().getResourceType());
- }
+ }
}
}
-
+
private int executeTasks() throws Exception {
int counter = 0;
while(!tasks.isEmpty()) {
@@ -358,10 +327,7 @@ class OsgiInstallerThread extends Thread
counter++;
} catch(Exception e) {
if(!t.canRetry(ctx)) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO,
- "Task cannot be retried, removing from list:" + t);
- }
+ ctx.logInfo("Task cannot be retried, removing from list:" + t);
removeTask(t);
}
throw e;
@@ -369,13 +335,13 @@ class OsgiInstallerThread extends Thread
}
return counter;
}
-
+
private void removeTask(OsgiInstallerTask t) {
synchronized (tasks) {
tasks.remove(t);
}
}
-
+
private void cleanupInstallableResources() throws IOException {
// Cleanup resources that are not marked installable,
// they have been processed by now
@@ -395,49 +361,41 @@ class OsgiInstallerThread extends Thread
for(RegisteredResource r : toDelete) {
group.remove(r);
r.cleanup(ctx);
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "Removing RegisteredResource from list, not installable and has been processed: " + r);
- }
+ ctx.logDebug("Removing RegisteredResource from list, not installable and has been processed: " + r);
}
if(group.isEmpty() && key != null) {
groupKeysToRemove.add(key);
}
}
-
+
for(String key : groupKeysToRemove) {
registeredResources.remove(key);
}
-
+
ctx.setCounter(OsgiInstaller.REGISTERED_RESOURCES_COUNTER, resourceCount);
ctx.setCounter(OsgiInstaller.REGISTERED_GROUPS_COUNTER, registeredResources.size());
ctx.incrementCounter(OsgiInstaller.INSTALLER_CYCLES_COUNTER);
-
+
// List of resources might have changed
persistentList.save();
}
-
+
/** If we have any tasks waiting to be retried, schedule their execution */
private void scheduleRetries() {
- final int toRetry = tasksForNextCycle.size();
+ final int toRetry = tasksForNextCycle.size();
if(toRetry > 0) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, toRetry + " tasks scheduled for retrying");
- }
+ ctx.logDebug(toRetry + " tasks scheduled for retrying");
synchronized (newResources) {
newResources.notify();
retriesScheduled = true;
}
}
}
-
+
public void bundleChanged(BundleEvent e) {
final int t = e.getType();
if(t == BundleEvent.INSTALLED || t == BundleEvent.RESOLVED || t == BundleEvent.STARTED || t == BundleEvent.UPDATED) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "Received BundleEvent that might allow installed bundles to start, scheduling retries if any");
- }
+ ctx.logDebug("Received BundleEvent that might allow installed bundles to start, scheduling retries if any");
scheduleRetries();
}
}
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentBundleInfo.java Thu Jun 17 17:40:37 2010
@@ -29,8 +29,6 @@ import java.util.List;
import java.util.Properties;
import java.util.TreeSet;
-import org.osgi.service.log.LogService;
-
/** Store the digests and version numbers of installed bundles
* in a file, to keep track of what we installed.
*/
@@ -39,7 +37,7 @@ class PersistentBundleInfo {
private final File dataFile;
private final OsgiInstallerContext ctx;
private static final String VERSION_PREFIX = "V:";
-
+
/** Load the list from supplied file, which is also
* used by purgeAndSave to save our data
*/
@@ -50,21 +48,16 @@ class PersistentBundleInfo {
try {
is = new FileInputStream(dataFile);
digests.load(is);
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO, "Digests restored from data file " + dataFile.getName());
- }
+ ctx.logInfo("Digests restored from data file " + dataFile.getName());
} catch(IOException ioe) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO,
- "No digests retrieved, cannot read properties file " + dataFile.getName());
- }
+ ctx.logInfo("No digests retrieved, cannot read properties file " + dataFile.getName());
} finally {
if(is != null) {
is.close();
}
}
}
-
+
/** Remove data which do not belongs to installed bundles,
* and save our data
*/
@@ -72,7 +65,7 @@ class PersistentBundleInfo {
final List<String> toRemove = new ArrayList<String>();
for(Object o : digests.keySet()) {
final String key = (String)o;
- if(!installedBundlesSymbolicNames.contains(key)
+ if(!installedBundlesSymbolicNames.contains(key)
&& !installedBundlesSymbolicNames.contains(key.substring(VERSION_PREFIX.length()))) {
toRemove.add(key);
}
@@ -80,7 +73,7 @@ class PersistentBundleInfo {
for(String key : toRemove) {
digests.remove(key);
}
-
+
OutputStream os = null;
try {
os = new FileOutputStream(dataFile);
@@ -91,23 +84,20 @@ class PersistentBundleInfo {
os.close();
}
}
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO,
- "Stored digests of " + digests.size() + " bundles in data file " + dataFile.getName());
- }
+ ctx.logInfo("Stored digests of " + digests.size() + " bundles in data file " + dataFile.getName());
}
-
+
/** Store a bundle digest - not persisted until purgeAndSave is called */
void putInfo(String bundleSymbolicName, String digest, String installedVersion) {
digests.setProperty(bundleSymbolicName, digest);
digests.setProperty(VERSION_PREFIX + bundleSymbolicName, installedVersion);
}
-
+
/** Retrieve digest, null if not found */
String getDigest(String bundleSymbolicName) {
return digests.getProperty(bundleSymbolicName);
}
-
+
/** Retrieve installed version, null if not found */
String getInstalledVersion(String bundleSymbolicName) {
return digests.getProperty(VERSION_PREFIX + bundleSymbolicName);
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/PersistentResourceList.java Thu Jun 17 17:40:37 2010
@@ -27,29 +27,24 @@ import java.io.ObjectOutputStream;
import java.util.HashMap;
import java.util.SortedSet;
-import org.osgi.service.log.LogService;
-
/** Persistent list of RegisteredResource, used by installer to
* keep track of all registered resources
*/
class PersistentResourceList {
private final HashMap<String, SortedSet<RegisteredResource>> data;
private final File dataFile;
-
+
@SuppressWarnings("unchecked")
PersistentResourceList(OsgiInstallerContext ctx, File dataFile) {
this.dataFile = dataFile;
-
+
ObjectInputStream ois = null;
HashMap<String, SortedSet<RegisteredResource>> restoredData = null;
try {
ois = new ObjectInputStream(new FileInputStream(dataFile));
restoredData = (HashMap<String, SortedSet<RegisteredResource>>)ois.readObject();
} catch(Exception e) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO,
- "Unable to restore data, starting with empty list (" + e.toString());
- }
+ ctx.logInfo("Unable to restore data, starting with empty list (" + e.toString());
} finally {
if(ois != null) {
try {
@@ -59,10 +54,10 @@ class PersistentResourceList {
}
}
}
-
+
data = restoredData != null ? restoredData : new HashMap<String, SortedSet<RegisteredResource>>();
}
-
+
HashMap<String, SortedSet<RegisteredResource>> getData() {
return data;
}
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/RegisteredResourceImpl.java Thu Jun 17 17:40:37 2010
@@ -44,7 +44,6 @@ import org.apache.sling.osgi.installer.i
import org.apache.sling.osgi.installer.impl.propertyconverter.PropertyValue;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
-import org.osgi.service.log.LogService;
/** A resource that's been registered in the OSGi controller.
* Data can be either an InputStream or a Dictionary, and we store
@@ -100,10 +99,7 @@ public class RegisteredResourceImpl impl
}
dictionary = null;
final File f = getDataFile(ctx);
- if(osgiCtx.getLogService() != null) {
- osgiCtx.getLogService().log(LogService.LOG_DEBUG,
- "Copying data to local storage " + f.getAbsolutePath());
- }
+ osgiCtx.logDebug("Copying data to local storage " + f.getAbsolutePath());
copyToLocalStorage(input.getInputStream(), f);
hasDataFile = true;
digest = input.getDigest();
@@ -154,10 +150,8 @@ public class RegisteredResourceImpl impl
public void cleanup(OsgiInstallerContext ctx) {
final File dataFile = getDataFile(ctx.getBundleContext());
if(dataFile.exists()) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Deleting local storage file "
+ ctx.logDebug("Deleting local storage file "
+ dataFile.getAbsolutePath());
- }
dataFile.delete();
}
}
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleStartTask.java Thu Jun 17 17:40:37 2010
@@ -22,11 +22,10 @@ import java.text.DecimalFormat;
import org.apache.sling.osgi.installer.OsgiInstaller;
import org.apache.sling.osgi.installer.impl.Activator;
-import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
import org.apache.sling.osgi.installer.impl.OsgiInstallerContext;
+import org.apache.sling.osgi.installer.impl.OsgiInstallerTask;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
-import org.osgi.service.log.LogService;
/** Start a bundle given its bundle ID
* Restarts if the bundle does not start on the first try,
@@ -39,15 +38,15 @@ public class BundleStartTask extends Osg
private final String sortKey;
private long eventsCountForRetrying;
private int retryCount = 0;
-
+
public BundleStartTask(long bundleId) {
this.bundleId = bundleId;
- sortKey = TaskOrder.BUNDLE_START_ORDER + new DecimalFormat("00000").format(bundleId);
+ sortKey = TaskOrder.BUNDLE_START_ORDER + new DecimalFormat("00000").format(bundleId);
}
-
+
@Override
public String getSortKey() {
- return sortKey;
+ return sortKey;
}
@Override
@@ -57,50 +56,37 @@ public class BundleStartTask extends Osg
public void execute(OsgiInstallerContext ctx) throws Exception {
final Bundle b = ctx.getBundleContext().getBundle(bundleId);
- final LogService log = ctx.getLogService();
boolean needToRetry = false;
-
+
if(bundleId == 0) {
- if(log != null) {
- log.log(LogService.LOG_DEBUG, "Bundle 0 is the framework bundle, ignoring request to start it");
- }
+ ctx.logDebug("Bundle 0 is the framework bundle, ignoring request to start it");
return;
}
-
+
if(b == null) {
- if(log != null) {
- log.log(LogService.LOG_INFO, "Cannot start bundle, id not found:" + bundleId);
- }
+ ctx.logInfo("Cannot start bundle, id not found:" + bundleId);
return;
}
-
+
try {
if(b.getState() == Bundle.ACTIVE) {
- if(log != null) {
- log.log(LogService.LOG_DEBUG, "Bundle already started, no action taken:" + bundleId + "/" + b.getSymbolicName());
- }
+ ctx.logDebug("Bundle already started, no action taken:" + bundleId + "/" + b.getSymbolicName());
} else {
// Try to start bundle, and if that doesn't work we'll need to retry
logExecution(ctx);
try {
b.start();
- if(log != null) {
- log.log(LogService.LOG_INFO,
- "Bundle started (retry count=" + retryCount + ", bundle ID=" + bundleId + ") " + b.getSymbolicName());
- }
+ ctx.logInfo("Bundle started (retry count=" + retryCount + ", bundle ID=" + bundleId + ") " + b.getSymbolicName());
} catch(BundleException e) {
- if(log != null) {
- log.log(LogService.LOG_INFO,
- "Could not start bundle (retry count=" + retryCount + ", " + e
+ ctx.logInfo("Could not start bundle (retry count=" + retryCount + ", " + e
+ "), will retry: " + bundleId + "/" + b.getSymbolicName());
- }
needToRetry = true;
}
-
+
}
} finally {
if(needToRetry) {
-
+
// Do the first retry immediately (in case "something" happenened right now
// that warrants a retry), but for the next ones wait for at least one bundle
// event or framework event
@@ -109,23 +95,20 @@ public class BundleStartTask extends Osg
} else {
eventsCountForRetrying = Activator.getTotalEventsCount() + 1;
}
-
+
ctx.addTaskToNextCycle(this);
}
}
retryCount++;
ctx.incrementCounter(OsgiInstaller.OSGI_TASKS_COUNTER);
}
-
+
/** Do not execute this task if waiting for events */
public boolean isExecutable(OsgiInstallerContext tctx) {
- final long eventsCount = Activator.getTotalEventsCount();
- final boolean result = eventsCount >= eventsCountForRetrying;
+ final long eventsCount = Activator.getTotalEventsCount();
+ final boolean result = eventsCount >= eventsCountForRetrying;
if(!result) {
- if(tctx.getLogService() != null) {
- tctx.getLogService().log(LogService.LOG_DEBUG,
- this + " is not executable at this time, counters=" + eventsCountForRetrying + "/" + eventsCount);
- }
+ tctx.logDebug(this + " is not executable at this time, counters=" + eventsCountForRetrying + "/" + eventsCount);
}
return result;
}
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/BundleUpdateTask.java Thu Jun 17 17:40:37 2010
@@ -27,7 +27,6 @@ import org.apache.sling.osgi.installer.i
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.Version;
-import org.osgi.service.log.LogService;
/** Update a bundle from a RegisteredResource. Creates
* a bundleStartTask to restart the bundle if it was
@@ -37,20 +36,20 @@ public class BundleUpdateTask extends Os
private final RegisteredResource resource;
private boolean canRetry = true;
-
+
public BundleUpdateTask(RegisteredResource r) {
this.resource = r;
}
-
+
public RegisteredResource getResource() {
return resource;
}
-
- @Override
+
+ @Override
public String toString() {
return getClass().getSimpleName() + ": " + resource;
}
-
+
@Override
public void execute(OsgiInstallerContext ctx) throws Exception {
final String symbolicName = (String)resource.getAttributes().get(Constants.BUNDLE_SYMBOLICNAME);
@@ -58,36 +57,28 @@ public class BundleUpdateTask extends Os
if(b == null) {
throw new IllegalStateException("Bundle to update (" + symbolicName + ") not found");
}
-
+
// Do not update if same version, unless snapshot
boolean snapshot = false;
final Version currentVersion = new Version((String)b.getHeaders().get(Constants.BUNDLE_VERSION));
final Version newVersion = new Version((String)resource.getAttributes().get(Constants.BUNDLE_VERSION));
snapshot = ctx.isSnapshot(newVersion);
if(currentVersion.equals(newVersion) && !snapshot) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(
- LogService.LOG_DEBUG,
- "Same version is already installed, and not a snapshot, ignoring update:" + resource);
- }
+ ctx.logDebug("Same version is already installed, and not a snapshot, ignoring update:" + resource);
return;
}
-
+
// If snapshot and ready to update, cancel if digest didn't change - as the list
// of RegisteredResources is not saved, this might not have been detected earlier,
// if the snapshot was installed and the installer was later restarted
if(snapshot) {
final String oldDigest = ctx.getInstalledBundleDigest(b);
if(resource.getDigest().equals(oldDigest)) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(
- LogService.LOG_DEBUG,
- "Snapshot digest did not change, ignoring update:" + resource);
- }
+ ctx.logDebug("Snapshot digest did not change, ignoring update:" + resource);
return;
}
}
-
+
logExecution(ctx);
if(b.getState() == Bundle.ACTIVE) {
// bundle was active before the update - restart it once updated, but
@@ -105,12 +96,10 @@ public class BundleUpdateTask extends Os
b.update(is);
ctx.saveInstalledBundleInfo(b, resource.getDigest(), newVersion.toString());
ctx.addTaskToCurrentCycle(new SynchronousRefreshPackagesTask());
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG, "Bundle updated: " + b.getBundleId() + "/" + b.getSymbolicName());
- }
+ ctx.logDebug("Bundle updated: " + b.getBundleId() + "/" + b.getSymbolicName());
ctx.incrementCounter(OsgiInstaller.OSGI_TASKS_COUNTER);
}
-
+
@Override
public boolean canRetry(OsgiInstallerContext ctx) {
return canRetry;
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallTask.java Thu Jun 17 17:40:37 2010
@@ -29,45 +29,41 @@ import org.apache.sling.osgi.installer.i
import org.apache.sling.osgi.installer.impl.RegisteredResource;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.log.LogService;
-/** Install/remove task for configurations */
+/** Install/remove task for configurations */
public class ConfigInstallTask extends AbstractConfigTask {
static final String ALIAS_KEY = "_alias_factory_pid";
static final String CONFIG_PATH_KEY = "_jcr_config_path";
public static final String [] CONFIG_EXTENSIONS = { ".cfg", ".properties" };
-
+
/** Configuration properties to ignore when comparing configs */
public static Set<String> ignoredProperties = new HashSet<String>();
static {
ignoredProperties.add("service.pid");
ignoredProperties.add(CONFIG_PATH_KEY);
}
-
+
public ConfigInstallTask(RegisteredResource r) {
super(r);
}
-
+
@Override
public String getSortKey() {
return TaskOrder.CONFIG_INSTALL_ORDER + pid.getCompositePid();
}
-
+
@SuppressWarnings("unchecked")
@Override
public void execute(OsgiInstallerContext ctx) throws Exception {
-
+
final ConfigurationAdmin ca = ctx.getConfigurationAdmin();
if(ca == null) {
ctx.addTaskToNextCycle(this);
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "ConfigurationAdmin not available, task will be retried later: " + this);
- }
+ ctx.logDebug("ConfigurationAdmin not available, task will be retried later: " + this);
return;
}
-
+
// Convert data to a configuration Dictionary
Dictionary<String, Object> dict = resource.getDictionary();
@@ -92,28 +88,22 @@ public class ConfigInstallTask extends A
config = getConfiguration(ca, pid, true, ctx);
} else {
if(isSameData(config.getProperties(), resource.getDictionary())) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "Configuration " + config.getPid()
- + " already installed with same data, update request ignored: "
+ ctx.logDebug("Configuration " + config.getPid()
+ + " already installed with same data, update request ignored: "
+ resource);
- }
config = null;
}
}
-
+
if(config != null) {
logExecution(ctx);
if (config.getBundleLocation() != null) {
config.setBundleLocation(null);
}
config.update(dict);
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO,
- "Configuration " + config.getPid()
- + " " + (created ? "created" : "updated")
+ ctx.logInfo("Configuration " + config.getPid()
+ + " " + (created ? "created" : "updated")
+ " from " + resource);
- }
}
}
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigRemoveTask.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigRemoveTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigRemoveTask.java Thu Jun 17 17:40:37 2010
@@ -22,7 +22,6 @@ import org.apache.sling.osgi.installer.i
import org.apache.sling.osgi.installer.impl.RegisteredResource;
import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.log.LogService;
/** Remove a Configuration */
public class ConfigRemoveTask extends AbstractConfigTask {
@@ -30,40 +29,31 @@ import org.osgi.service.log.LogService;
static final String ALIAS_KEY = "_alias_factory_pid";
static final String CONFIG_PATH_KEY = "_jcr_config_path";
public static final String [] CONFIG_EXTENSIONS = { ".cfg", ".properties" };
-
+
public ConfigRemoveTask(RegisteredResource r) {
super(r);
}
-
+
@Override
public String getSortKey() {
return TaskOrder.CONFIG_REMOVE_ORDER + pid.getCompositePid();
}
-
+
public void execute(OsgiInstallerContext ctx) throws Exception {
-
+
final ConfigurationAdmin ca = ctx.getConfigurationAdmin();
if(ca == null) {
ctx.addTaskToNextCycle(this);
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "ConfigurationAdmin not available, task will be retried later: " + this);
- }
+ ctx.logDebug("ConfigurationAdmin not available, task will be retried later: " + this);
return;
}
-
+
logExecution(ctx);
final Configuration cfg = getConfiguration(ca, pid, false, ctx);
if(cfg == null) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "Cannot delete config , pid=" + pid + " not found, ignored (" + resource + ")");
- }
+ ctx.logDebug("Cannot delete config , pid=" + pid + " not found, ignored (" + resource + ")");
} else {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_INFO,
- "Deleting config " + pid + " (" + resource + ")");
- }
+ ctx.logInfo("Deleting config " + pid + " (" + resource + ")");
cfg.delete();
}
}
Modified: sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java (original)
+++ sling/trunk/installer/osgi/installer/src/main/java/org/apache/sling/osgi/installer/impl/tasks/SynchronousRefreshPackagesTask.java Thu Jun 17 17:40:37 2010
@@ -23,7 +23,6 @@ import org.apache.sling.osgi.installer.i
import org.osgi.framework.Bundle;
import org.osgi.framework.FrameworkEvent;
import org.osgi.framework.FrameworkListener;
-import org.osgi.service.log.LogService;
/** Execute an OSGi "refresh packages" operation, synchronously */
public class SynchronousRefreshPackagesTask extends OsgiInstallerTask implements FrameworkListener {
@@ -43,14 +42,13 @@ public class SynchronousRefreshPackagesT
*/
public void frameworkEvent(FrameworkEvent event) {
if (event.getType() == FrameworkEvent.PACKAGES_REFRESHED) {
- if(ctx!= null && ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "FrameworkEvent.PACKAGES_REFRESHED");
+ if (ctx!= null) {
+ ctx.logDebug("FrameworkEvent.PACKAGES_REFRESHED");
}
packageRefreshEventsCount++;
}
}
-
+
@Override
public String getSortKey() {
return TaskOrder.REFRESH_PACKAGES_ORDER;
@@ -75,10 +73,7 @@ public class SynchronousRefreshPackagesT
if(b.getState() == Bundle.ACTIVE) {
final OsgiInstallerTask t = new BundleStartTask(b.getBundleId());
ctx.addTaskToCurrentCycle(t);
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "Added " + t + " to restart bundle if needed after refreshing packages");
- }
+ ctx.logDebug("Added " + t + " to restart bundle if needed after refreshing packages");
}
}
@@ -89,22 +84,16 @@ public class SynchronousRefreshPackagesT
ctx.getPackageAdmin().refreshPackages(null);
while(true) {
if(System.currentTimeMillis() > timeout) {
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_WARNING,
- "No FrameworkEvent.PACKAGES_REFRESHED event received within "
+ ctx.logWarn("No FrameworkEvent.PACKAGES_REFRESHED event received within "
+ MAX_REFRESH_PACKAGES_WAIT_SECONDS
+ " seconds after refresh");
- }
break;
}
if(packageRefreshEventsCount >= targetEventCount) {
final long delta = System.currentTimeMillis() - start;
- if(ctx.getLogService() != null) {
- ctx.getLogService().log(LogService.LOG_DEBUG,
- "FrameworkEvent.PACKAGES_REFRESHED received "
+ ctx.logDebug("FrameworkEvent.PACKAGES_REFRESHED received "
+ delta
+ " msec after refreshPackages call");
- }
break;
}
try {
Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryConversionTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryConversionTest.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryConversionTest.java (original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/DictionaryConversionTest.java Thu Jun 17 17:40:37 2010
@@ -29,30 +29,30 @@ import org.apache.sling.osgi.installer.i
import org.apache.sling.osgi.installer.impl.propertyconverter.ValueConverterException;
public class DictionaryConversionTest {
-
+
private void assertArray(String info, String [] expected, Object obj) {
assertTrue(info + ":obj (" + obj.getClass().getName() + ") must be a String[]", obj instanceof String[]);
final String [] actual = (String[])obj;
assertEquals(info + ": array sizes must match", expected.length, actual.length);
-
+
for(int i=0; i < expected.length; i++) {
assertEquals(info + " at index " + i, expected[i], actual[i]);
}
}
-
+
@org.junit.Test public void testConvertValue() throws ValueConverterException {
final PropertyConverter c = new PropertyConverter();
assertArray("one two", new String[] { "one", "two" }, c.convert("x[]", "one, two\t").getValue());
assertArray("one", new String[] { "one" }, c.convert("x[]", "\t one ").getValue());
assertArray("empty array", new String[] { }, c.convert("x []", "\t \n").getValue());
}
-
+
@org.junit.Test public void testConvertValueWithEscapes() throws ValueConverterException {
final PropertyConverter c = new PropertyConverter();
assertArray("one two", new String[] { "one", "two,three" }, c.convert("x[]", "one, two\\,three").getValue());
assertArray("one", new String[] { "one,two,three" }, c.convert("x[]", "one\\,two\\,three").getValue());
}
-
+
@org.junit.Test public void testSplitWithEscapes() throws ValueConverterException {
final PropertyConverter c = new PropertyConverter();
assertArray("empty", new String[0], c.convert("x[]", "").getValue());
@@ -62,7 +62,7 @@ public class DictionaryConversionTest {
assertArray("a,b,c", new String[] { "a", "b, c" }, c.convert("x[]", "a, b\\, c\t").getValue());
assertArray("a,b,c,d", new String[] { "a", "b, c ,", "d" }, c.convert("x[]", "a, b\\, c \\,,d ").getValue());
}
-
+
@org.junit.Test public void testFromStream() throws IOException {
final String data =
"a = 1\n"
@@ -72,19 +72,19 @@ public class DictionaryConversionTest {
+ "c[] = 1,2\\\\,A , 3 \n"
+ "d=12\n"
;
-
+
final ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
final Dictionary<?, ?> d = RegisteredResourceImpl.readDictionary(is);
is.close();
-
+
assertEquals("Number of entries must match", 4, d.size());
assertEquals("a", d.get("a"), "1");
assertEquals("b", d.get("b"), "this is B");
-
+
assertArray("c", new String[] { "1", "2,A", "3" }, d.get("c"));
assertEquals("d", d.get("d"), "12");
}
-
+
@org.junit.Test public void testDataTypes() throws IOException {
final String data =
"a = 1\n"
@@ -94,16 +94,16 @@ public class DictionaryConversionTest {
+ "d(double) = 14.23\n"
+ "e = My Value\n"
;
-
+
final ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
final Dictionary<?, ?> d = RegisteredResourceImpl.readDictionary(is);
is.close();
-
+
assertEquals("Number of entries must match", 5, d.size());
assertEquals("String value matches", "1", d.get("a"));
assertEquals("Integer value matches", new Integer(242), d.get("b"));
assertEquals("Boolean value matches", new Boolean(true), d.get("c"));
- assertEquals("Double value matches", new Double(14.24), d.get("d"));
+ assertEquals("Double value matches", new Double(14.23), d.get("d"));
assertEquals("String value matches", "My Value", d.get("e"));
}
}
\ No newline at end of file
Modified: sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java?rev=955684&r1=955683&r2=955684&view=diff
==============================================================================
--- sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java (original)
+++ sling/trunk/installer/osgi/installer/src/test/java/org/apache/sling/osgi/installer/impl/MockOsgiInstallerContext.java Thu Jun 17 17:40:37 2010
@@ -25,19 +25,18 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Version;
import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.log.LogService;
import org.osgi.service.packageadmin.PackageAdmin;
public class MockOsgiInstallerContext implements OsgiInstallerContext {
private final PersistentBundleInfo persistentBundleInfo;
-
+
public MockOsgiInstallerContext() throws IOException {
final File f = File.createTempFile(MockOsgiInstallerContext.class.getSimpleName(), ".data");
f.deleteOnExit();
persistentBundleInfo = new PersistentBundleInfo(this, f);
}
-
+
public void addTaskToCurrentCycle(OsgiInstallerTask t) {
}
@@ -52,24 +51,20 @@ public class MockOsgiInstallerContext im
return null;
}
- public LogService getLogService() {
- return null;
- }
-
public PackageAdmin getPackageAdmin() {
return null;
}
public void incrementCounter(int index) {
}
-
+
public void setCounter(int index, long value) {
}
public Bundle getMatchingBundle(String bundleSymbolicName) {
return null;
}
-
+
public boolean isSnapshot(Version v) {
return v.toString().indexOf(OsgiInstallerImpl.MAVEN_SNAPSHOT_MARKER) >= 0;
}
@@ -85,8 +80,50 @@ public class MockOsgiInstallerContext im
public void saveInstalledBundleInfo(Bundle b, String digest, String version) throws IOException {
saveInstalledBundleInfo(b.getSymbolicName(), digest, version);
}
-
+
public void saveInstalledBundleInfo(String symbolicName, String digest, String version) throws IOException {
persistentBundleInfo.putInfo(symbolicName, digest, version);
}
+
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logDebug(java.lang.String, java.lang.Throwable)
+ */
+ public void logDebug(String message, Throwable t) {
+ // nothing to do - no logging
+ }
+
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logDebug(java.lang.String)
+ */
+ public void logDebug(String message) {
+ // nothing to do - no logging
+ }
+
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logInfo(java.lang.String, java.lang.Throwable)
+ */
+ public void logInfo(String message, Throwable t) {
+ // nothing to do - no logging
+ }
+
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logInfo(java.lang.String)
+ */
+ public void logInfo(String message) {
+ // nothing to do - no logging
+ }
+
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logWarn(java.lang.String, java.lang.Throwable)
+ */
+ public void logWarn(String message, Throwable t) {
+ // nothing to do - no logging
+ }
+
+ /**
+ * @see org.apache.sling.osgi.installer.impl.OsgiInstallerContext#logWarn(java.lang.String)
+ */
+ public void logWarn(String message) {
+ // nothing to do - no logging
+ }
}