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/12/31 19:41:05 UTC
svn commit: r1054158 - in
/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl:
EntityResourceList.java RegisteredResource.java RegisteredResourceImpl.java
tasks/BundleStartTask.java
Author: cziegeler
Date: Fri Dec 31 18:41:05 2010
New Revision: 1054158
URL: http://svn.apache.org/viewvc?rev=1054158&view=rev
Log:
SLING-1910 : Endless recursion if bundle can't be started
SLING-1911 : If the same resource is at different locations they should be treated as the same resource
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/RegisteredResource.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.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=1054158&r1=1054157&r2=1054158&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 Dec 31 18:41:05 2010
@@ -21,6 +21,7 @@ package org.apache.sling.installer.core.
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
@@ -35,12 +36,26 @@ import org.slf4j.LoggerFactory;
*/
public class EntityResourceList implements Serializable {
- private static final long serialVersionUID = 6326554136639675505L;
+ private static final long serialVersionUID = -1733426192525500065L;
private static final Logger LOGGER = LoggerFactory.getLogger(EntityResourceList.class);
- private final SortedSet<RegisteredResource> resources = new TreeSet<RegisteredResource>();
+ private static final class ResourceComparator implements Comparator<RegisteredResource>, Serializable {
+ private static final long serialVersionUID = 3573107717574356088L;
+ public int compare(RegisteredResource o1, RegisteredResource o2) {
+ int result = o1.compareTo(o2);
+ if ( result == 0 ) {
+ result = o1.getURL().compareTo(o2.getURL());
+ }
+ return result;
+ }
+ }
+
+ private final SortedSet<RegisteredResource> resources = new TreeSet<RegisteredResource>(
+ new ResourceComparator());
+
+ /** The resource list is empty if it contains no resources. */
public boolean isEmpty() {
return resources.isEmpty();
}
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResource.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResource.java?rev=1054158&r1=1054157&r2=1054158&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResource.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResource.java Fri Dec 31 18:41:05 2010
@@ -98,7 +98,27 @@ public interface RegisteredResource exte
*/
String getEntityId();
+ /**
+ * Get the current state of the resource.
+ */
State getState();
+ /**
+ * Set the new state of teh resource.
+ */
void setState(final State s);
+
+ /**
+ * Get the value of a temporary attribute.
+ * @param key The name of the attribute
+ * @return The value of the attribute or <code>null</code>
+ */
+ Object getTemporaryAttribute(String key);
+
+ /**
+ * Set the value of a temporary attribute.
+ * @param key The name of the attribute
+ * @param value The attribute value or <code>null</code> to remove it.
+ */
+ void setTemporaryAttributee(String key, Object value);
}
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java?rev=1054158&r1=1054157&r2=1054158&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/RegisteredResourceImpl.java Fri Dec 31 18:41:05 2010
@@ -56,7 +56,7 @@ import org.osgi.service.cm.Configuration
public class RegisteredResourceImpl
implements RegisteredResource, Serializable {
- private static final long serialVersionUID = 5L;
+ private static final long serialVersionUID = 6L;
/** The resource url. */
private final String url;
@@ -80,6 +80,9 @@ public class RegisteredResourceImpl
private State state = State.INSTALL;
+ /** Temporary attributes. */
+ private transient Map<String, Object> temporaryAttributes;
+
/**
* Try to create a registered resource.
*/
@@ -399,7 +402,10 @@ public class RegisteredResourceImpl
if ( ! (obj instanceof RegisteredResource) ) {
return false;
}
- return compareTo((RegisteredResource)obj) == 0;
+ if ( compareTo((RegisteredResource)obj) != 0 ) {
+ return false;
+ }
+ return this.getURL().equals(((RegisteredResource)obj).getURL());
}
/**
@@ -606,4 +612,28 @@ public class RegisteredResourceImpl
return ht;
}
+
+ /**
+ * @see org.apache.sling.installer.core.impl.RegisteredResource#getTemporaryAttribute(java.lang.String)
+ */
+ public Object getTemporaryAttribute(final String key) {
+ if ( this.temporaryAttributes != null ) {
+ return this.temporaryAttributes.get(key);
+ }
+ return null;
+ }
+
+ /**
+ * @see org.apache.sling.installer.core.impl.RegisteredResource#setTemporaryAttributee(java.lang.String, java.lang.Object)
+ */
+ public void setTemporaryAttributee(final String key, final Object value) {
+ if ( this.temporaryAttributes == null ) {
+ this.temporaryAttributes = new HashMap<String, Object>();
+ }
+ if ( value == null ) {
+ this.temporaryAttributes.remove(key);
+ } else {
+ this.temporaryAttributes.put(key, value);
+ }
+ }
}
\ No newline at end of file
Modified: sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java?rev=1054158&r1=1054157&r2=1054158&view=diff
==============================================================================
--- sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java (original)
+++ sling/trunk/installer/core/src/main/java/org/apache/sling/installer/core/impl/tasks/BundleStartTask.java Fri Dec 31 18:41:05 2010
@@ -37,6 +37,9 @@ public class BundleStartTask extends Osg
private static final String BUNDLE_START_ORDER = "70-";
+ private static final String ATTR_RC = "bst:retryCount";
+ private static final String ATTR_EC = "bst:eventsCount";
+
private final long bundleId;
private final String sortKey;
private long eventsCountForRetrying;
@@ -46,9 +49,14 @@ public class BundleStartTask extends Osg
public BundleStartTask(final EntityResourceList r, final long bundleId, final BundleTaskCreator btc) {
super(r);
- this.bundleId = bundleId;
- this.creator = btc;
- this.sortKey = BUNDLE_START_ORDER + new DecimalFormat("00000").format(bundleId);
+ this.bundleId = bundleId;
+ this.creator = btc;
+ this.sortKey = BUNDLE_START_ORDER + new DecimalFormat("00000").format(bundleId);
+ final RegisteredResource rr = this.getResource();
+ if ( rr != null && rr.getTemporaryAttribute(ATTR_RC) != null ) {
+ this.retryCount = (Integer)rr.getTemporaryAttribute(ATTR_RC);
+ this.eventsCountForRetrying = (Long)rr.getTemporaryAttribute(ATTR_EC);
+ }
}
@Override
@@ -113,14 +121,17 @@ public class BundleStartTask extends Osg
// 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
- if (retryCount == 0) {
- eventsCountForRetrying = OsgiInstallerImpl.getTotalEventsCount();
+ if (this.retryCount == 0) {
+ this.eventsCountForRetrying = OsgiInstallerImpl.getTotalEventsCount();
} else {
- eventsCountForRetrying = OsgiInstallerImpl.getTotalEventsCount() + 1;
+ this.eventsCountForRetrying = OsgiInstallerImpl.getTotalEventsCount() + 1;
}
- retryCount++;
+ this.retryCount++;
if ( this.getResource() == null ) {
ctx.addTaskToNextCycle(this);
+ } else {
+ this.getResource().setTemporaryAttributee(ATTR_RC, this.retryCount);
+ this.getResource().setTemporaryAttributee(ATTR_EC, this.eventsCountForRetrying);
}
}
}