Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Hallgren2010-02-05 17:07:01 -0500
committerThomas Hallgren2010-02-05 17:07:01 -0500
commit9faaed06625f31f3e4f26f65c3cffe4e947604fd (patch)
tree162a1267d4429ff85e188de84970455c138abfa6 /bundles/org.eclipse.equinox.p2.artifact.repository
parente640f35a91169ce4ad67d674ba7b150b42450478 (diff)
downloadrt.equinox.p2-9faaed06625f31f3e4f26f65c3cffe4e947604fd.tar.gz
rt.equinox.p2-9faaed06625f31f3e4f26f65c3cffe4e947604fd.tar.xz
rt.equinox.p2-9faaed06625f31f3e4f26f65c3cffe4e947604fd.zip
299987 : Removal of p2 services in favor of always using an agent.
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.artifact.repository')
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5Verifier.java8
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep.java8
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java58
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java9
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java4
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java157
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java16
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java10
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java23
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep.java6
-rw-r--r--bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java16
12 files changed, 175 insertions, 150 deletions
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5Verifier.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5Verifier.java
index d79f88394..49aa609a2 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5Verifier.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/md5/MD5Verifier.java
@@ -11,8 +11,6 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.processors.md5;
-import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
-
import java.io.IOException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -20,7 +18,9 @@ import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.ProcessingStep;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
+import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
import org.eclipse.osgi.util.NLS;
public class MD5Verifier extends ProcessingStep {
@@ -39,8 +39,8 @@ public class MD5Verifier extends ProcessingStep {
}
//This handle the case where the MD5 verification is initiated by a processing step
- public void initialize(IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
- super.initialize(descriptor, context);
+ public void initialize(IProvisioningAgent agent, IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
+ super.initialize(agent, descriptor, context);
String data = descriptor.getData();
if (IArtifactDescriptor.DOWNLOAD_MD5.equals(data))
expectedMD5 = context.getProperty(IArtifactDescriptor.DOWNLOAD_MD5);
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep.java
index cf5778e67..8bf32b705 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/processors/pack200/Pack200ProcessorStep.java
@@ -11,8 +11,6 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.processors.pack200;
-import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
-
import java.io.*;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
@@ -20,7 +18,9 @@ import org.eclipse.equinox.internal.p2.artifact.processing.AbstractBufferingStep
import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
import org.eclipse.equinox.internal.p2.jarprocessor.UnpackStep;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
+import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor;
import org.eclipse.internal.provisional.equinox.p2.jarprocessor.JarProcessorExecutor.Options;
@@ -37,8 +37,8 @@ public class Pack200ProcessorStep extends AbstractBufferingStep {
return new BufferedOutputStream(new FileOutputStream(incoming));
}
- public void initialize(IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
- super.initialize(descriptor, context);
+ public void initialize(IProvisioningAgent agent, IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
+ super.initialize(agent, descriptor, context);
if (!UnpackStep.canUnpack())
setStatus(new Status(IStatus.ERROR, Activator.ID, "Unpack facility not configured")); //$NON-NLS-1$
}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java
index 6a41d2d38..043ba761d 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Activator.java
@@ -10,76 +10,24 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.repository;
-import java.util.HashMap;
-import java.util.Map;
-import org.eclipse.equinox.p2.core.IProvisioningAgent;
-import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
-import org.osgi.framework.*;
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.util.tracker.ServiceTrackerCustomizer;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
-public class Activator implements BundleActivator, ServiceTrackerCustomizer {
+public class Activator implements BundleActivator {
public static final String ID = "org.eclipse.equinox.p2.artifact.repository"; //$NON-NLS-1$
public static final String REPO_PROVIDER_XPT = ID + '.' + "artifactRepositories"; //$NON-NLS-1$
private static BundleContext context;
- private ServiceRegistration repositoryManagerRegistration;
- private static final Map<ArtifactRepositoryManager, IProvisioningAgent> createdManagers = new HashMap<ArtifactRepositoryManager, IProvisioningAgent>();
- private ServiceTracker agentTracker;
public static BundleContext getContext() {
return Activator.context;
}
- /**
- * Remember an artifact repository manager so we can shut it down when the bundle stops
- */
- static void addManager(ArtifactRepositoryManager manager, IProvisioningAgent agent) {
- synchronized (createdManagers) {
- createdManagers.put(manager, agent);
- }
- }
-
public void start(BundleContext aContext) throws Exception {
Activator.context = aContext;
- // need to track agent so we can register global artifact repository manager
- String filter = "(&(objectClass=" + IProvisioningAgent.SERVICE_NAME + ")(agent.current=true))"; //$NON-NLS-1$ //$NON-NLS-2$
- agentTracker = new ServiceTracker(context, aContext.createFilter(filter), this);
- agentTracker.open();
}
public void stop(BundleContext aContext) throws Exception {
Activator.context = null;
- if (repositoryManagerRegistration != null)
- repositoryManagerRegistration.unregister();
- repositoryManagerRegistration = null;
- synchronized (createdManagers) {
- for (ArtifactRepositoryManager manager : createdManagers.keySet()) {
- manager.shutdown();
- IProvisioningAgent agent = createdManagers.get(manager);
- agent.unregisterService(IArtifactRepositoryManager.SERVICE_NAME, manager);
- }
- createdManagers.clear();
- }
- agentTracker.close();
- }
-
- public Object addingService(ServiceReference reference) {
- //when someone registers the agent service, register a repository manager service
- IProvisioningAgent agent = (IProvisioningAgent) context.getService(reference);
- repositoryManagerRegistration = context.registerService(IArtifactRepositoryManager.SERVICE_NAME, agent.getService(IArtifactRepositoryManager.SERVICE_NAME), null);
- return agent;
- }
-
- public void modifiedService(ServiceReference reference, Object service) {
- // ignored
- }
-
- public void removedService(ServiceReference reference, Object service) {
- //the agent is going away so withdraw our service
- if (repositoryManagerRegistration != null) {
- repositoryManagerRegistration.unregister();
- repositoryManagerRegistration = null;
- }
}
}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java
index 901457a8e..6a0a01505 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryComponent.java
@@ -10,8 +10,6 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.repository;
-import org.eclipse.equinox.internal.provisional.p2.core.eventbus.IProvisioningEventBus;
-import org.eclipse.equinox.p2.core.IAgentLocation;
import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.spi.IAgentServiceFactory;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
@@ -22,11 +20,6 @@ import org.eclipse.equinox.p2.repository.artifact.IArtifactRepositoryManager;
public class ArtifactRepositoryComponent implements IAgentServiceFactory {
public Object createService(IProvisioningAgent agent) {
- final ArtifactRepositoryManager manager = new ArtifactRepositoryManager();
- manager.setEventBus((IProvisioningEventBus) agent.getService(IProvisioningEventBus.SERVICE_NAME));
- manager.setAgentLocation((IAgentLocation) agent.getService(IAgentLocation.SERVICE_NAME));
- manager.setAgent(agent);
- Activator.addManager(manager, agent);
- return manager;
+ return new ArtifactRepositoryManager(agent);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java
index 21e54aa6f..9b6cfdb01 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/ArtifactRepositoryManager.java
@@ -16,10 +16,8 @@ import java.util.HashMap;
import java.util.Map;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.core.helpers.LogHelper;
-import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.repository.helpers.AbstractRepositoryManager;
-import org.eclipse.equinox.p2.core.IAgentLocation;
-import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.core.*;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.repository.IRepository;
import org.eclipse.equinox.p2.repository.artifact.*;
@@ -33,8 +31,8 @@ import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory;
*/
public class ArtifactRepositoryManager extends AbstractRepositoryManager<IArtifactKey> implements IArtifactRepositoryManager {
- public ArtifactRepositoryManager() {
- super();
+ public ArtifactRepositoryManager(IProvisioningAgent agent) {
+ super(agent);
}
public void addRepository(IArtifactRepository repository) {
@@ -109,7 +107,7 @@ public class ArtifactRepositoryManager extends AbstractRepositoryManager<IArtifa
*/
protected void restoreSpecialRepositories() {
// TODO while recreating, we may want to have proxies on repo instead of the real repo object to limit what is activated.
- IAgentLocation location = (IAgentLocation) ServiceHelper.getService(Activator.getContext(), IAgentLocation.class.getName());
+ IAgentLocation location = (IAgentLocation) getAgent().getService(IAgentLocation.SERVICE_NAME);
if (location == null)
// TODO should do something here since we are failing to restore.
return;
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java
index e1fb37a64..7e2820a80 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/CompositeArtifactRepository.java
@@ -84,7 +84,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl
* This is only called by the parser when loading a repository.
*/
CompositeArtifactRepository(IArtifactRepositoryManager manager, CompositeRepositoryState state) {
- super(state.getName(), state.getType(), state.getVersion(), state.getLocation(), state.getDescription(), state.getProvider(), state.getProperties());
+ super(manager.getAgent(), state.getName(), state.getType(), state.getVersion(), state.getLocation(), state.getDescription(), state.getProvider(), state.getProperties());
this.manager = manager;
for (int i = 0; i < state.getChildren().length; i++)
addChild(state.getChildren()[i], false);
@@ -94,7 +94,7 @@ public class CompositeArtifactRepository extends AbstractArtifactRepository impl
* @noreference This constructor is not intended to be referenced by clients.
*/
protected CompositeArtifactRepository(IArtifactRepositoryManager manager, URI location, String repositoryName, Map<String, String> properties) {
- super(repositoryName, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties);
+ super(manager.getAgent(), repositoryName, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties);
this.manager = manager;
save();
}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java
index 6fb6259de..1fbd11df8 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/MirrorSelector.java
@@ -11,6 +11,7 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.repository;
+import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
@@ -40,8 +41,15 @@ public class MirrorSelector {
* Encapsulates information about a single mirror
*/
public static class MirrorInfo implements Comparable<MirrorInfo> {
+ private static final long PRIMARY_FAILURE_LINGER_TIME = 30000; // Retry again after 30 seconds
+ private static final long SECONDARY_FAILURE_LINGER_TIME = 300000; // Wait 5 minutes
+ private static final int ACCEPTABLE_FILE_NOT_FOUND_COUNT = 5; // Given an established connection, those are generally quick
+ private static final Timer resetFailure = new Timer("Mirror failure timer", true); //$NON-NLS-1$
+
long bytesPerSecond;
int failureCount;
+ int fileNotFoundCount;
+ int totalFailureCount;
private final int initialRank;
String locationString;
@@ -51,33 +59,86 @@ public class MirrorSelector {
if (!locationString.endsWith("/")) //$NON-NLS-1$
locationString = locationString + "/"; //$NON-NLS-1$
failureCount = 0;
+ totalFailureCount = 0;
bytesPerSecond = DownloadStatus.UNKNOWN_RATE;
}
/**
* Comparison used to sort mirrors.
*/
- public int compareTo(MirrorInfo that) {
- //less failures is better
- if (this.failureCount != that.failureCount)
- return this.failureCount - that.failureCount;
- //faster is better
- if (this.bytesPerSecond != that.bytesPerSecond)
- return (int) (that.bytesPerSecond - this.bytesPerSecond);
- //trust that initial rank indicates geographical proximity
- return this.initialRank - that.initialRank;
+ public synchronized int compareTo(MirrorInfo that) {
+ synchronized (that) {
+ double rank = 0.0;
+ if (bytesPerSecond != that.bytesPerSecond) {
+ if (bytesPerSecond != DownloadStatus.UNKNOWN_RATE && that.bytesPerSecond != DownloadStatus.UNKNOWN_RATE) {
+ if (bytesPerSecond > that.bytesPerSecond)
+ rank -= (double) bytesPerSecond / (double) that.bytesPerSecond;
+ else
+ rank += (double) that.bytesPerSecond / (double) bytesPerSecond;
+ }
+ }
+
+ //less failures is better
+ if (failureCount != that.failureCount) {
+ if (failureCount > that.failureCount)
+ rank += ((double) (failureCount + 1) / (double) (that.failureCount + 1)) * 2.0;
+ else
+ rank -= ((double) (that.failureCount + 1) / (double) (failureCount + 1)) * 2.0;
+ }
+
+ if (rank == 0.0)
+ //trust that initial rank indicates geographical proximity
+ rank = initialRank - that.initialRank;
+
+ if (rank == 0.0)
+ return 0;
+
+ int intRank;
+ intRank = (int) rank;
+ if (intRank == 0)
+ intRank = rank > 0 ? 1 : -1;
+ return intRank;
+ }
}
- public void incrementFailureCount() {
- this.failureCount++;
+ public synchronized String toString() {
+ return "Mirror(" + locationString + ',' + failureCount + ',' + bytesPerSecond + ')'; //$NON-NLS-1$
}
- public void setBytesPerSecond(long newValue) {
- this.bytesPerSecond = newValue;
+ public synchronized void decrementFailureCount() {
+ if (failureCount > 0)
+ failureCount--;
}
- public String toString() {
- return "Mirror(" + locationString + ',' + failureCount + ',' + bytesPerSecond + ')'; //$NON-NLS-1$
+ public synchronized void incrementFailureCount() {
+ ++failureCount;
+ ++totalFailureCount;
+ if (totalFailureCount < 3) {
+ resetFailure.schedule(new TimerTask() {
+ @Override
+ public void run() {
+ decrementFailureCount();
+ }
+ }, totalFailureCount == 1 ? PRIMARY_FAILURE_LINGER_TIME : SECONDARY_FAILURE_LINGER_TIME);
+ }
+ }
+
+ public synchronized void setBytesPerSecond(long newValue) {
+ // Any non-positive value is treated as an unknown rate
+ if (newValue <= 0)
+ newValue = DownloadStatus.UNKNOWN_RATE;
+
+ if (newValue > 0)
+ // Back in commission
+ failureCount = 0;
+ bytesPerSecond = newValue;
+ }
+
+ public synchronized void incrementFileNotFoundCount() {
+ if (++fileNotFoundCount > ACCEPTABLE_FILE_NOT_FOUND_COUNT) {
+ incrementFailureCount();
+ fileNotFoundCount = 0;
+ }
}
}
@@ -220,8 +281,16 @@ public class MirrorSelector {
for (int i = 0; i < mirrors.length; i++) {
MirrorInfo mirror = mirrors[i];
if (toDownload.startsWith(mirror.locationString)) {
- if (!result.isOK() && result.getSeverity() != IStatus.CANCEL)
- mirror.incrementFailureCount();
+ if (!result.isOK() && result.getSeverity() != IStatus.CANCEL) {
+ // Punishing a mirror harshly for a FileNotFoundException can be very wrong.
+ // Some artifacts are not found on any mirror. When that's the case,
+ // the best mirrors will be the first to receive that kind of punishment.
+ //
+ if (result.getException() instanceof FileNotFoundException)
+ mirror.incrementFileNotFoundCount();
+ else
+ mirror.incrementFailureCount();
+ }
if (result instanceof DownloadStatus) {
long oldRate = mirror.bytesPerSecond;
long newRate = ((DownloadStatus) result).getTransferRate();
@@ -232,7 +301,6 @@ public class MirrorSelector {
}
if (Tracing.DEBUG_MIRRORS)
Tracing.debug("Updated mirror " + mirror); //$NON-NLS-1$
- Arrays.sort(mirrors);
return;
}
}
@@ -243,9 +311,11 @@ public class MirrorSelector {
* @return whether or not there is a valid mirror in this selector.
*/
public synchronized boolean hasValidMirror() {
- // return true if there is a mirror and it has not failed. Since the mirrors
- // list is sorted with failures last, we only have to test the first element for failure.
- return mirrors != null && mirrors.length > 0 && mirrors[0].failureCount == 0;
+ // return true if there is a mirror and it doesn't have multiple failures.
+ if (mirrors == null || mirrors.length == 0)
+ return false;
+ Arrays.sort(mirrors);
+ return mirrors[0].failureCount < 2;
}
/**
@@ -257,22 +327,37 @@ public class MirrorSelector {
int mirrorCount;
if (mirrors == null || (mirrorCount = mirrors.length) == 0)
return null;
- //this is a function that randomly selects a mirror based on a logarithmic
- //distribution. Mirror 0 has a 1/2 chance of being selected, mirror 1 has a 1/4 chance,
- // mirror 2 has a 1/8 chance, etc. This introduces some variation in the mirror
- //selection, while still heavily favoring better mirrors
- //the algorithm computes the most significant digit in a binary number by computing the base 2 logarithm
- //if the first digit is most significant, mirror 0 is selected, if the second is most significant, mirror 1 is selected, etc
- int highestMirror = Math.min(15, mirrorCount);
- int result = (int) (Math.log(random.nextInt(1 << highestMirror) + 1) / LOG2);
- if (result >= highestMirror || result < 0)
- result = highestMirror - 1;
- MirrorInfo selected = mirrors[highestMirror - 1 - result];
- //if we selected a mirror that has failed in the past, revert to best available mirror
- if (selected.failureCount > 0)
+
+ MirrorInfo selected;
+ if (mirrorCount == 1)
selected = mirrors[0];
- //for now, don't tolerate failing mirrors
- if (selected.failureCount > 0)
+ else {
+ Arrays.sort(mirrors);
+ for (;;) {
+ //this is a function that randomly selects a mirror based on a logarithmic
+ //distribution. Mirror 0 has a 1/2 chance of being selected, mirror 1 has a 1/4 chance,
+ // mirror 2 has a 1/8 chance, etc. This introduces some variation in the mirror
+ //selection, while still heavily favoring better mirrors
+ //the algorithm computes the most significant digit in a binary number by computing the base 2 logarithm
+ //if the first digit is most significant, mirror 0 is selected, if the second is most significant, mirror 1 is selected, etc
+ int highestMirror = Math.min(15, mirrorCount);
+ int result = (int) (Math.log(random.nextInt(1 << highestMirror) + 1) / LOG2);
+ if (result >= highestMirror || result < 0)
+ result = highestMirror - 1;
+
+ int mirrorIndex = highestMirror - 1 - result;
+ selected = mirrors[mirrorIndex];
+
+ // If the ranking of the selected mirror is significantly worse then the top ranked
+ // mirror, then we consider this a bad choice and reiterate.
+ if (mirrorIndex == 0 || mirrors[0].compareTo(selected) < 4)
+ // This is good enough
+ break;
+ }
+ }
+
+ //for now, don't tolerate mirrors with multiple failures
+ if (selected.failureCount > 1)
return null;
return selected;
}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java
index 4f9a0c33c..674df3b9d 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java
@@ -24,11 +24,11 @@ import org.eclipse.equinox.internal.p2.artifact.processors.md5.MD5Verifier;
import org.eclipse.equinox.internal.p2.artifact.repository.*;
import org.eclipse.equinox.internal.p2.artifact.repository.Messages;
import org.eclipse.equinox.internal.p2.core.helpers.FileUtils;
-import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper;
import org.eclipse.equinox.internal.p2.repository.RepositoryTransport;
import org.eclipse.equinox.internal.p2.repository.Transport;
import org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing.*;
import org.eclipse.equinox.internal.provisional.p2.repository.IStateful;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.metadata.IArtifactKey;
import org.eclipse.equinox.p2.query.*;
@@ -257,8 +257,8 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
/*
* This is only called by the parser when loading a repository.
*/
- SimpleArtifactRepository(String name, String type, String version, String description, String provider, Set<SimpleArtifactDescriptor> artifacts, String[][] mappingRules, Map<String, String> properties) {
- super(name, type, version, null, description, provider, properties);
+ SimpleArtifactRepository(IProvisioningAgent agent, String name, String type, String version, String description, String provider, Set<SimpleArtifactDescriptor> artifacts, String[][] mappingRules, Map<String, String> properties) {
+ super(agent, name, type, version, null, description, provider, properties);
this.artifactDescriptors.addAll(artifacts);
this.mappingRules = mappingRules;
for (SimpleArtifactDescriptor desc : artifactDescriptors)
@@ -286,8 +286,8 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
artifactMap.remove(key);
}
- public SimpleArtifactRepository(String repositoryName, URI location, Map<String, String> properties) {
- super(repositoryName, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties);
+ public SimpleArtifactRepository(IProvisioningAgent agent, String repositoryName, URI location, Map<String, String> properties) {
+ super(agent, repositoryName, REPOSITORY_TYPE, REPOSITORY_VERSION.toString(), location, null, null, properties);
initializeAfterLoad(location);
if (properties != null) {
if (properties.containsKey(PUBLISH_PACK_FILES_AS_SIBLINGS)) {
@@ -834,7 +834,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
public OutputStream processDestination(ProcessingStepHandler handler, IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) {
destination = addPostSteps(handler, descriptor, destination, monitor);
- destination = handler.createAndLink(descriptor.getProcessingSteps(), descriptor, destination, monitor);
+ destination = handler.createAndLink(agent, descriptor.getProcessingSteps(), descriptor, destination, monitor);
destination = addPreSteps(handler, descriptor, destination, monitor);
return destination;
}
@@ -940,7 +940,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
os = jOs;
}
super.setProperty(IRepository.PROP_TIMESTAMP, Long.toString(System.currentTimeMillis()));
- new SimpleArtifactRepositoryIO().write(this, os);
+ new SimpleArtifactRepositoryIO(agent).write(this, os);
} catch (IOException e) {
// TODO proper exception handling
e.printStackTrace();
@@ -969,7 +969,7 @@ public class SimpleArtifactRepository extends AbstractArtifactRepository impleme
}
save();
//force repository manager to reload this repository because it caches properties
- ArtifactRepositoryManager manager = (ArtifactRepositoryManager) ServiceHelper.getService(Activator.getContext(), IArtifactRepositoryManager.SERVICE_NAME);
+ ArtifactRepositoryManager manager = (ArtifactRepositoryManager) agent.getService(IArtifactRepositoryManager.SERVICE_NAME);
if (manager.removeRepository(getLocation()))
manager.addRepository(this);
return oldValue;
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java
index a3aec4822..d9cd59a79 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryFactory.java
@@ -10,10 +10,6 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.repository.simple;
-import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory;
-
-import org.eclipse.equinox.p2.core.ProvisionException;
-
import java.io.*;
import java.net.URI;
import java.util.Map;
@@ -25,8 +21,10 @@ import org.eclipse.equinox.internal.p2.artifact.repository.Messages;
import org.eclipse.equinox.internal.p2.core.helpers.Tracing;
import org.eclipse.equinox.internal.p2.repository.RepositoryTransport;
import org.eclipse.equinox.internal.p2.repository.Transport;
+import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.repository.IRepositoryManager;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
+import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory;
import org.eclipse.osgi.util.NLS;
public class SimpleArtifactRepositoryFactory extends ArtifactRepositoryFactory {
@@ -99,7 +97,7 @@ public class SimpleArtifactRepositoryFactory extends ArtifactRepositoryFactory {
}
descriptorStream = jInStream;
}
- SimpleArtifactRepositoryIO io = new SimpleArtifactRepositoryIO();
+ SimpleArtifactRepositoryIO io = new SimpleArtifactRepositoryIO(getAgent());
SimpleArtifactRepository result = (SimpleArtifactRepository) io.read(localFile.toURL(), descriptorStream, sub.newChild(100));
result.initializeAfterLoad(location);
if (Tracing.DEBUG_METADATA_PARSING) {
@@ -124,7 +122,7 @@ public class SimpleArtifactRepositoryFactory extends ArtifactRepositoryFactory {
}
public IArtifactRepository create(URI location, String name, String type, Map<String, String> properties) {
- return new SimpleArtifactRepository(name, location, properties);
+ return new SimpleArtifactRepository(getAgent(), name, location, properties);
}
private Transport getTransport() {
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java
index 477aac105..06df4e3e6 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryIO.java
@@ -10,13 +10,6 @@
*******************************************************************************/
package org.eclipse.equinox.internal.p2.artifact.repository.simple;
-import org.eclipse.equinox.p2.metadata.Version;
-import org.eclipse.equinox.p2.metadata.VersionRange;
-
-import org.eclipse.equinox.p2.core.ProvisionException;
-
-import org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor;
-
import java.io.*;
import java.net.URL;
import java.util.*;
@@ -29,8 +22,12 @@ import org.eclipse.equinox.internal.p2.core.helpers.OrderedProperties;
import org.eclipse.equinox.internal.p2.metadata.ArtifactKey;
import org.eclipse.equinox.internal.p2.persistence.XMLParser;
import org.eclipse.equinox.internal.p2.persistence.XMLWriter;
-import org.eclipse.equinox.p2.metadata.IArtifactKey;
-import org.eclipse.equinox.p2.repository.artifact.*;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
+import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.metadata.*;
+import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
+import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
+import org.eclipse.equinox.p2.repository.artifact.spi.ProcessingStepDescriptor;
import org.eclipse.osgi.util.NLS;
import org.osgi.framework.BundleContext;
import org.xml.sax.*;
@@ -46,6 +43,12 @@ import org.xml.sax.*;
// for getting a repository reader/writer given a repository type
public class SimpleArtifactRepositoryIO {
+ private final IProvisioningAgent agent;
+
+ public SimpleArtifactRepositoryIO(IProvisioningAgent agent) {
+ this.agent = agent;
+ }
+
/**
* Writes the given artifact repository to the stream.
* This method performs buffering, and closes the stream when finished.
@@ -330,7 +333,7 @@ public class SimpleArtifactRepositoryIO {
: propertiesHandler.getProperties());
Set<SimpleArtifactDescriptor> artifacts = (artifactsHandler == null ? new HashSet<SimpleArtifactDescriptor>(0) //
: artifactsHandler.getArtifacts());
- repository = new SimpleArtifactRepository(attrValues[0], attrValues[1], attrValues[2], attrValues[3], //
+ repository = new SimpleArtifactRepository(agent, attrValues[0], attrValues[1], attrValues[2], attrValues[3], //
attrValues[4], artifacts, mappingRules, properties);
}
}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep.java
index 403670e1a..c0e4858ec 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStep.java
@@ -11,13 +11,13 @@
*******************************************************************************/
package org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing;
-import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
-
import java.io.IOException;
import java.io.OutputStream;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.provisional.p2.repository.IStateful;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
+import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
/**
* ProcessingSteps process the data written to them and pass the resultant data on
@@ -41,7 +41,7 @@ public abstract class ProcessingStep extends OutputStream implements IStateful {
* @param descriptor description of the step
* @param context the context in which the step is being used
*/
- public void initialize(IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
+ public void initialize(IProvisioningAgent agent, IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
// nothing to do here!
}
diff --git a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java
index 0387fcd28..e5530e937 100644
--- a/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java
+++ b/bundles/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/provisional/p2/artifact/repository/processing/ProcessingStepHandler.java
@@ -11,15 +11,15 @@
*******************************************************************************/
package org.eclipse.equinox.internal.provisional.p2.artifact.repository.processing;
-import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
-
import java.io.OutputStream;
import java.util.ArrayList;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.artifact.repository.Activator;
import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository.ArtifactOutputStream;
import org.eclipse.equinox.internal.provisional.p2.repository.IStateful;
+import org.eclipse.equinox.p2.core.IProvisioningAgent;
import org.eclipse.equinox.p2.repository.artifact.IArtifactDescriptor;
+import org.eclipse.equinox.p2.repository.artifact.IProcessingStepDescriptor;
import org.eclipse.osgi.util.NLS;
/**
@@ -127,14 +127,14 @@ public class ProcessingStepHandler {
return null;
}
- public ProcessingStep[] create(IProcessingStepDescriptor[] descriptors, IArtifactDescriptor context) {
+ public ProcessingStep[] create(IProvisioningAgent agent, IProcessingStepDescriptor[] descriptors, IArtifactDescriptor context) {
ProcessingStep[] result = new ProcessingStep[descriptors.length];
for (int i = 0; i < descriptors.length; i++)
- result[i] = create(descriptors[i], context);
+ result[i] = create(agent, descriptors[i], context);
return result;
}
- public ProcessingStep create(IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
+ public ProcessingStep create(IProvisioningAgent agent, IProcessingStepDescriptor descriptor, IArtifactDescriptor context) {
IExtensionRegistry registry = RegistryFactory.getRegistry();
IExtension extension = registry.getExtension(PROCESSING_STEPS_EXTENSION_ID, descriptor.getProcessorId());
Exception error;
@@ -143,7 +143,7 @@ public class ProcessingStepHandler {
try {
Object object = config[0].createExecutableExtension("class"); //$NON-NLS-1$
ProcessingStep step = (ProcessingStep) object;
- step.initialize(descriptor, context);
+ step.initialize(agent, descriptor, context);
return step;
} catch (Exception e) {
error = e;
@@ -157,10 +157,10 @@ public class ProcessingStepHandler {
return result;
}
- public OutputStream createAndLink(IProcessingStepDescriptor[] descriptors, IArtifactDescriptor context, OutputStream output, IProgressMonitor monitor) {
+ public OutputStream createAndLink(IProvisioningAgent agent, IProcessingStepDescriptor[] descriptors, IArtifactDescriptor context, OutputStream output, IProgressMonitor monitor) {
if (descriptors == null)
return output;
- ProcessingStep[] steps = create(descriptors, context);
+ ProcessingStep[] steps = create(agent, descriptors, context);
return link(steps, output, monitor);
}

Back to the top