Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 88919 Details for
Bug 207802
[prov] Add multi-threaded download and mirror selection into p2's artifact retrieval
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Threaded downloads and mirror lookups
patch-207802-threadedl-wmirrors.txt (text/plain), 30.56 KB, created by
Timothy Webb
on 2008-02-05 14:02:38 EST
(
hide
)
Description:
Threaded downloads and mirror lookups
Filename:
MIME Type:
Creator:
Timothy Webb
Created:
2008-02-05 14:02:38 EST
Size:
30.56 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.equinox.p2.tests >Index: src/org/eclipse/equinox/p2/tests/TestArtifactRepository.java >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestArtifactRepository.java,v >retrieving revision 1.5 >diff -u -r1.5 TestArtifactRepository.java >--- src/org/eclipse/equinox/p2/tests/TestArtifactRepository.java 15 Dec 2007 02:13:20 -0000 1.5 >+++ src/org/eclipse/equinox/p2/tests/TestArtifactRepository.java 5 Feb 2008 18:56:08 -0000 >@@ -13,8 +13,7 @@ > import java.util.*; > import junit.framework.Assert; > import org.eclipse.core.runtime.*; >-import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRequest; >-import org.eclipse.equinox.internal.p2.artifact.repository.Transport; >+import org.eclipse.equinox.internal.p2.artifact.repository.*; > import org.eclipse.equinox.p2.artifact.repository.*; > import org.eclipse.equinox.p2.artifact.repository.processing.ProcessingStepHandler; > import org.eclipse.equinox.p2.core.repository.RepositoryCreationException; >@@ -47,7 +46,7 @@ > */ > Set artifactDescriptors = new HashSet(); > >- Transport testhandler = new Transport() { >+ IArtifactTransport testhandler = new Transport() { > public IStatus download(String toDownload, OutputStream target, IProgressMonitor pm) { > byte[] contents = (byte[]) locationsToContents.get(toDownload); > if (contents == null) >#P org.eclipse.equinox.p2.artifact.repository >Index: src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties,v >retrieving revision 1.7 >diff -u -r1.7 messages.properties >--- src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties 25 Jan 2008 17:03:55 -0000 1.7 >+++ src/org/eclipse/equinox/internal/p2/artifact/repository/messages.properties 5 Feb 2008 18:56:08 -0000 >@@ -26,4 +26,7 @@ > repoMan_internalError=Internal error. > repoMan_notExists=No repository found at {0}. > repoMan_unknownType=Unknown repository type at {0}. >+ >+download_thread_interrupted=Download thread {0} was interrupted, incomplete artifact retrieval. >+downloading_requests=Downloading {0} request(s). > >\ No newline at end of file >Index: src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java,v >retrieving revision 1.6 >diff -u -r1.6 Messages.java >--- src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java 25 Jan 2008 17:03:55 -0000 1.6 >+++ src/org/eclipse/equinox/internal/p2/artifact/repository/Messages.java 5 Feb 2008 18:56:08 -0000 >@@ -42,4 +42,6 @@ > public static String io_incompatibleVersion; > public static String mirroring; > >+ public static String download_thread_interrupted; >+ public static String downloading_requests; > } >\ No newline at end of file >Index: src/org/eclipse/equinox/internal/p2/artifact/repository/Transport.java >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/Transport.java,v >retrieving revision 1.1 >diff -u -r1.1 Transport.java >--- src/org/eclipse/equinox/internal/p2/artifact/repository/Transport.java 5 Oct 2007 01:44:28 -0000 1.1 >+++ src/org/eclipse/equinox/internal/p2/artifact/repository/Transport.java 5 Feb 2008 18:56:08 -0000 >@@ -13,7 +13,11 @@ > import java.io.OutputStream; > import org.eclipse.core.runtime.IProgressMonitor; > import org.eclipse.core.runtime.IStatus; >+import org.eclipse.equinox.p2.artifact.repository.IArtifactTransport; > >-public abstract class Transport { >+public abstract class Transport implements IArtifactTransport { >+ /* (non-Javadoc) >+ * @see org.eclipse.equinox.internal.p2.artifact.repository.IArtifactTransport#download(java.lang.String, java.io.OutputStream, org.eclipse.core.runtime.IProgressMonitor) >+ */ > public abstract IStatus download(String toDownload, OutputStream target, IProgressMonitor pm); > } >Index: META-INF/MANIFEST.MF >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.artifact.repository/META-INF/MANIFEST.MF,v >retrieving revision 1.11 >diff -u -r1.11 MANIFEST.MF >--- META-INF/MANIFEST.MF 11 Dec 2007 08:31:09 -0000 1.11 >+++ META-INF/MANIFEST.MF 5 Feb 2008 18:56:08 -0000 >@@ -6,12 +6,13 @@ > Bundle-Localization: plugin > Bundle-Version: 0.1.0.qualifier > Export-Package: org.eclipse.equinox.internal.p2.artifact.mirror;x-internal:=true, >- org.eclipse.equinox.internal.p2.artifact.repository;x-friends:="org.eclipse.equinox.p2.metadata.generator,org.eclipse.equinox.p2.tests", >+ org.eclipse.equinox.internal.p2.artifact.repository;x-friends:="org.eclipse.equinox.p2.metadata.generator,org.eclipse.equinox.p2.artifact.dlmirrors,org.eclipse.equinox.p2.tests", > org.eclipse.equinox.internal.p2.artifact.repository.simple;x-friends:="org.eclipse.equinox.p2.selfhosting,org.eclipse.equinox.p2.touchpoint.eclipse,org.eclipse.equinox.p2.tests", > org.eclipse.equinox.p2.artifact.repository, > org.eclipse.equinox.p2.artifact.repository.processing, > org.eclipse.equinox.spi.p2.artifact.repository > Import-Package: javax.xml.parsers, >+ org.eclipse.core.runtime.jobs, > org.eclipse.core.runtime.preferences;resolution:=optional, > org.eclipse.equinox.app;version="1.0.0", > org.eclipse.equinox.internal.p2.core.helpers, >Index: src/org/eclipse/equinox/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java,v >retrieving revision 1.1 >diff -u -r1.1 SimpleArtifactRepositoryFactory.java >--- src/org/eclipse/equinox/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java 31 Jan 2008 20:55:24 -0000 1.1 >+++ src/org/eclipse/equinox/spi/p2/artifact/repository/SimpleArtifactRepositoryFactory.java 5 Feb 2008 18:56:09 -0000 >@@ -18,8 +18,9 @@ > import org.eclipse.equinox.internal.p2.artifact.repository.*; > import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepository; > import org.eclipse.equinox.internal.p2.artifact.repository.simple.SimpleArtifactRepositoryIO; >+import org.eclipse.equinox.internal.p2.core.helpers.ServiceHelper; > import org.eclipse.equinox.internal.p2.core.helpers.Tracing; >-import org.eclipse.equinox.p2.artifact.repository.IArtifactRepository; >+import org.eclipse.equinox.p2.artifact.repository.*; > import org.eclipse.equinox.p2.core.ProvisionException; > import org.eclipse.osgi.util.NLS; > >@@ -42,11 +43,11 @@ > boolean compress = true; > try { > artifacts = new BufferedOutputStream(new FileOutputStream(temp)); >- IStatus status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100)); >+ IStatus status = getTransport(location).download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100)); > if (!status.isOK()) { > // retry uncompressed > compress = false; >- status = getTransport().download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100)); >+ status = getTransport(location).download(SimpleArtifactRepository.getActualLocation(location, compress).toExternalForm(), artifacts, sub.newChild(100)); > if (!status.isOK()) > throw new ProvisionException(new Status(IStatus.ERROR, Activator.ID, ProvisionException.REPOSITORY_NOT_FOUND, status.getMessage(), null)); > } >@@ -98,7 +99,13 @@ > return new SimpleArtifactRepository(name, location); > } > >- private Transport getTransport() { >- return ECFTransport.getInstance(); >+ private IArtifactTransport getTransport(URL location) { >+ IArtifactTransport transport = null; >+ IArtifactTransportFactory manager = (IArtifactTransportFactory) ServiceHelper.getService(Activator.getContext(), IArtifactTransportFactory.class.getName()); >+ if (manager != null) >+ transport = manager.getTransport(location); >+ if (transport == null) >+ transport = ECFTransport.getInstance(); >+ return transport; > } > } >Index: src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java >=================================================================== >RCS file: /cvsroot/eclipse/equinox-incubator/provisioning/org.eclipse.equinox.p2.artifact.repository/src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java,v >retrieving revision 1.31 >diff -u -r1.31 SimpleArtifactRepository.java >--- src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java 2 Feb 2008 03:51:36 -0000 1.31 >+++ src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepository.java 5 Feb 2008 18:56:09 -0000 >@@ -24,8 +24,9 @@ > import org.eclipse.equinox.p2.core.ProvisionException; > import org.eclipse.equinox.p2.metadata.IArtifactKey; > import org.eclipse.equinox.spi.p2.artifact.repository.AbstractArtifactRepository; >+import org.eclipse.osgi.util.NLS; > >-public class SimpleArtifactRepository extends AbstractArtifactRepository implements IArtifactRepository, IFileArtifactRepository { >+public class SimpleArtifactRepository extends AbstractArtifactRepository implements IArtifactRepository, IFileArtifactRepository, IMultiThreadedArtifactRepository { > > public class ArtifactOutputStream extends OutputStream implements IStateful { > private boolean closed; >@@ -159,10 +160,13 @@ > protected Set artifactDescriptors = new HashSet(); > private transient BlobStore blobStore; > transient private Mapper mapper = new Mapper(); >+ transient private IArtifactTransport transport; > > static final private String PACKED_FORMAT = "packed"; //$NON-NLS-1$ > static final private String PUBLISH_PACK_FILES_AS_SIBLINGS = "publishPackFilesAsSiblings"; //$NON-NLS-1$ > >+ static final private int DEFAULT_MAX_THREADS = 4; >+ > protected String[][] mappingRules = DEFAULT_MAPPING_RULES; > > private boolean signatureVerification = false; >@@ -379,7 +383,7 @@ > return super.getAdapter(adapter); > } > >- private IStatus getArtifact(ArtifactRequest request, IProgressMonitor monitor) { >+ IStatus getArtifact(ArtifactRequest request, IProgressMonitor monitor) { > request.setSourceRepository(this); > request.perform(monitor); > return request.getResult(); >@@ -429,20 +433,53 @@ > } > > public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) { >- SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length); >- try { >- MultiStatus overallStatus = new MultiStatus(Activator.ID, IStatus.OK, null, null); >- for (int i = 0; i < requests.length; i++) { >- if (monitor.isCanceled()) >- return Status.CANCEL_STATUS; >- IStatus result = getArtifact((ArtifactRequest) requests[i], subMonitor.newChild(1)); >- if (!result.isOK()) >- overallStatus.add(result); >+ final MultiStatus overallStatus = new MultiStatus(Activator.ID, IStatus.OK, null, null); >+ LinkedList requestsPending = new LinkedList(Arrays.asList(requests)); >+ >+ if (!isMultiThreadingEnabled() || requests.length <= 1) { >+ // multi-threading isn't enabled or too few requests, use simple inline download of artifacts >+ SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length); >+ try { >+ for (int i = 0; i < requests.length; i++) { >+ if (monitor.isCanceled()) >+ return Status.CANCEL_STATUS; >+ IStatus result = getArtifact((ArtifactRequest) requests[i], subMonitor.newChild(1)); >+ if (!result.isOK()) >+ overallStatus.add(result); >+ } >+ } finally { >+ subMonitor.done(); >+ } >+ } else { >+ // initialize the various jobs needed to process the get artifact requests >+ monitor.beginTask(NLS.bind(Messages.downloading_requests, new Integer(requests.length)), requests.length); >+ try { >+ // don't allocate more jobs than we have requests >+ int numberOfJobs = Math.min(requests.length, getMaximumThreads()); >+ SimpleArtifactRepositoryDownloadJob jobs[] = new SimpleArtifactRepositoryDownloadJob[numberOfJobs]; >+ for (int i = 0; i < numberOfJobs; i++) { >+ jobs[i] = new SimpleArtifactRepositoryDownloadJob("downloadjob-" + i); //$NON-NLS-1$ >+ jobs[i].initialize(this, requestsPending, monitor, overallStatus); >+ } >+ // schedule the various jobs >+ for (int i = 0; i < numberOfJobs; i++) { >+ jobs[i].schedule(); >+ } >+ // wait for all the jobs to complete >+ for (int i = 0; i < numberOfJobs; i++) { >+ try { >+ jobs[i].join(); >+ } catch (InterruptedException e) { >+ synchronized (overallStatus) { >+ overallStatus.add(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.download_thread_interrupted, jobs[i].getName()))); >+ } >+ } >+ } >+ } finally { >+ monitor.done(); > } >- return (monitor.isCanceled() ? Status.CANCEL_STATUS : overallStatus); >- } finally { >- subMonitor.done(); > } >+ return (monitor.isCanceled() ? Status.CANCEL_STATUS : overallStatus); > } > > public synchronized IArtifactDescriptor getCompleteArtifactDescriptor(IArtifactKey key) { >@@ -507,6 +544,17 @@ > return null; > } > >+ private int getMaximumThreads() { >+ try { >+ Object value = getProperties().get(PROP_MAX_THREADS); >+ if (value != null && value instanceof String) >+ return Math.max(1, Integer.parseInt((String) getProperties().get(PROP_MAX_THREADS))); >+ } catch (NumberFormatException nfe) { >+ // return default number of threads >+ } >+ return DEFAULT_MAX_THREADS; >+ } >+ > public OutputStream getOutputStream(IArtifactDescriptor descriptor) { > assertModifiable(); > // TODO we need a better way of distinguishing between errors and cases where >@@ -577,8 +625,15 @@ > return signatureVerification; > } > >- private Transport getTransport() { >- return ECFTransport.getInstance(); >+ private IArtifactTransport getTransport() { >+ if (transport == null) { >+ IArtifactTransportFactory manager = (IArtifactTransportFactory) ServiceHelper.getService(Activator.getContext(), IArtifactTransportFactory.class.getName()); >+ if (manager != null) >+ transport = manager.getTransport(getLocation()); >+ if (transport == null) >+ transport = ECFTransport.getInstance(); >+ } >+ return transport; > } > > // use this method to setup any transient fields etc after the object has been restored from a stream >@@ -615,6 +670,10 @@ > return isLocal(); > } > >+ public boolean isMultiThreadingEnabled() { >+ return !isLocal() && getMaximumThreads() > 1; >+ } >+ > 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); >@@ -752,5 +811,4 @@ > public String toString() { > return location.toExternalForm(); > } >- > } >Index: src/org/eclipse/equinox/p2/artifact/repository/dlmirrors/IDownloadMirrorsDelegate.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/artifact/repository/dlmirrors/IDownloadMirrorsDelegate.java >diff -N src/org/eclipse/equinox/p2/artifact/repository/dlmirrors/IDownloadMirrorsDelegate.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/artifact/repository/dlmirrors/IDownloadMirrorsDelegate.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,19 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Genuitec, LLC and others. All rights reserved. This >+ * program and the accompanying materials are made available under the terms of >+ * the Eclipse Public License v1.0 which accompanies this distribution, and is >+ * available at http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: Genuitec, LLC - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.equinox.p2.artifact.repository.dlmirrors; >+ >+import java.net.URL; >+ >+public interface IDownloadMirrorsDelegate { >+ >+ boolean worksWith(URL artifactRepoLocation); >+ >+ IDownloadMirror determineDownloadMirror(String toDownload); >+ >+} >Index: src/org/eclipse/equinox/p2/artifact/repository/IArtifactTransport.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/artifact/repository/IArtifactTransport.java >diff -N src/org/eclipse/equinox/p2/artifact/repository/IArtifactTransport.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/artifact/repository/IArtifactTransport.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,24 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Genuitec, LLC and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Genuitec, LLC - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.p2.artifact.repository; >+ >+import java.io.OutputStream; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+ >+public interface IArtifactTransport { >+ >+ /** >+ * Download the given artifact to the specified output stream. >+ */ >+ public IStatus download(String toDownload, OutputStream target, IProgressMonitor pm); >+ >+} >Index: src/org/eclipse/equinox/internal/p2/artifact/repository/ECFTransportWithMirrors.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/p2/artifact/repository/ECFTransportWithMirrors.java >diff -N src/org/eclipse/equinox/internal/p2/artifact/repository/ECFTransportWithMirrors.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/p2/artifact/repository/ECFTransportWithMirrors.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,42 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Genuitec, LLC and others. All rights reserved. This >+ * program and the accompanying materials are made available under the terms of >+ * the Eclipse Public License v1.0 which accompanies this distribution, and is >+ * available at http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: Genuitec, LLC - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.equinox.internal.p2.artifact.repository; >+ >+import java.io.OutputStream; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.equinox.p2.artifact.repository.IArtifactTransport; >+import org.eclipse.equinox.p2.artifact.repository.dlmirrors.IDownloadMirror; >+import org.eclipse.equinox.p2.artifact.repository.dlmirrors.IDownloadMirrorsDelegate; >+ >+/** >+ * A transport implementation that looks up a download mirror before >+ * calling down to the ECF transport implementation. >+ */ >+public class ECFTransportWithMirrors implements IArtifactTransport { >+ >+ private final IDownloadMirrorsDelegate downloadMirrorsDelegate; >+ >+ public ECFTransportWithMirrors(IDownloadMirrorsDelegate delegate) { >+ this.downloadMirrorsDelegate = delegate; >+ } >+ >+ public IStatus download(String toDownload, OutputStream target, IProgressMonitor monitor) { >+ >+ // use a download mirror if available >+ IDownloadMirror mirror = downloadMirrorsDelegate.determineDownloadMirror(toDownload); >+ if (mirror != null) { >+ IStatus result = ECFTransport.getInstance().download(mirror.getLocation(toDownload), target, monitor); >+ mirror.reportStatus(result); >+ return result; >+ } >+ >+ return ECFTransport.getInstance().download(toDownload, target, monitor); >+ } >+} >Index: src/org/eclipse/equinox/p2/artifact/repository/IArtifactTransportFactory.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/artifact/repository/IArtifactTransportFactory.java >diff -N src/org/eclipse/equinox/p2/artifact/repository/IArtifactTransportFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/artifact/repository/IArtifactTransportFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,28 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Genuitec, LLC and others. All rights reserved. This >+ * program and the accompanying materials are made available under the terms of >+ * the Eclipse Public License v1.0 which accompanies this distribution, and is >+ * available at http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: Genuitec, LLC - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.equinox.p2.artifact.repository; >+ >+import java.net.URL; >+import org.eclipse.equinox.p2.artifact.repository.dlmirrors.IDownloadMirrorsDelegate; >+ >+public interface IArtifactTransportFactory { >+ >+ /** >+ * Determine and return the transport for the specified base location. >+ * Return null if a default transport should be used by the consuming >+ * artifact repository. >+ */ >+ public IArtifactTransport getTransport(URL artifactRepoLocation); >+ >+ /** >+ * Register the specified download mirrors delegate which can provide >+ * mirrors for one or more artifact repositories. >+ */ >+ public void registerDownloadMirrors(IDownloadMirrorsDelegate downloadMirrorsDelegate); >+} >Index: src/org/eclipse/equinox/p2/artifact/repository/dlmirrors/IDownloadMirror.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/artifact/repository/dlmirrors/IDownloadMirror.java >diff -N src/org/eclipse/equinox/p2/artifact/repository/dlmirrors/IDownloadMirror.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/artifact/repository/dlmirrors/IDownloadMirror.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,19 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Genuitec, LLC and others. All rights reserved. This >+ * program and the accompanying materials are made available under the terms of >+ * the Eclipse Public License v1.0 which accompanies this distribution, and is >+ * available at http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: Genuitec, LLC - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.equinox.p2.artifact.repository.dlmirrors; >+ >+import org.eclipse.core.runtime.IStatus; >+ >+public interface IDownloadMirror { >+ >+ String getLocation(String toDownload); >+ >+ void reportStatus(IStatus result); >+ >+} >Index: src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryDownloadJob.java >=================================================================== >RCS file: src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryDownloadJob.java >diff -N src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryDownloadJob.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/internal/p2/artifact/repository/simple/SimpleArtifactRepositoryDownloadJob.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,70 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Genuitec, LLC and others. All rights reserved. This >+ * program and the accompanying materials are made available under the terms of >+ * the Eclipse Public License v1.0 which accompanies this distribution, and is >+ * available at http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: Genuitec, LLC - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.equinox.internal.p2.artifact.repository.simple; >+ >+import java.util.LinkedList; >+import org.eclipse.core.runtime.*; >+import org.eclipse.core.runtime.jobs.Job; >+import org.eclipse.equinox.internal.p2.artifact.repository.ArtifactRequest; >+import org.eclipse.equinox.p2.artifact.repository.IArtifactRequest; >+ >+public class SimpleArtifactRepositoryDownloadJob extends Job { >+ >+ private LinkedList requestsPending; >+ private SimpleArtifactRepository repository; >+ private IProgressMonitor masterMonitor; >+ private MultiStatus overallStatus; >+ >+ SimpleArtifactRepositoryDownloadJob(String name) { >+ super(name); >+ setSystem(true); >+ } >+ >+ void initialize(SimpleArtifactRepository repository, LinkedList requestsPending, IProgressMonitor masterMonitor, MultiStatus overallStatus) { >+ this.repository = repository; >+ this.requestsPending = requestsPending; >+ this.masterMonitor = masterMonitor; >+ this.overallStatus = overallStatus; >+ } >+ >+ protected IStatus run(IProgressMonitor jobMonitor) { >+ jobMonitor.beginTask("Downloading artifacts", 1); >+ boolean workRemaining = false; >+ do { >+ // get the request we are going to process >+ IArtifactRequest request; >+ synchronized (requestsPending) { >+ if (requestsPending.isEmpty()) >+ break; >+ request = (IArtifactRequest) requestsPending.removeFirst(); >+ } >+ if (masterMonitor.isCanceled()) >+ return Status.CANCEL_STATUS; >+ >+ // prepare a progress monitor that reports to both the master monitor and for the job >+ IProgressMonitor monitor = new NullProgressMonitor(); >+ // progress monitor updating from getArtifact() doesn't seem to be working >+ masterMonitor.subTask("Downloading " + request.getArtifactKey().getId() + "."); >+ >+ // process the actual request >+ IStatus status = repository.getArtifact((ArtifactRequest) request, monitor); >+ if (!status.isOK()) { >+ synchronized (overallStatus) { >+ overallStatus.add(status); >+ } >+ } >+ >+ // update progress >+ masterMonitor.worked(1); >+ } while (true); >+ >+ jobMonitor.done(); >+ return Status.OK_STATUS; >+ } >+} >Index: src/org/eclipse/equinox/p2/artifact/repository/IMultiThreadedArtifactRepository.java >=================================================================== >RCS file: src/org/eclipse/equinox/p2/artifact/repository/IMultiThreadedArtifactRepository.java >diff -N src/org/eclipse/equinox/p2/artifact/repository/IMultiThreadedArtifactRepository.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/p2/artifact/repository/IMultiThreadedArtifactRepository.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,27 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Genuitec, LLC and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Genuitec, LLC - initial API and implementation >+ *******************************************************************************/ >+package org.eclipse.equinox.p2.artifact.repository; >+ >+public interface IMultiThreadedArtifactRepository extends IArtifactRepository { >+ >+ /** >+ * The property key for a integer property controls the maximum number >+ * of threads that should be used when optimizing downloads from a remote >+ * artifact repository. >+ */ >+ static public String PROP_MAX_THREADS = "p2.max.threads"; //$NON-NLS-1$ >+ >+ /** >+ * Indicates if the artifact repository may choose to use multiple threads >+ * when a request is received for multiple artifacts. >+ */ >+ public boolean isMultiThreadingEnabled(); >+} >Index: src/org/eclipse/equinox/spi/p2/artifact/repository/SimpleArtifactTransportFactory.java >=================================================================== >RCS file: src/org/eclipse/equinox/spi/p2/artifact/repository/SimpleArtifactTransportFactory.java >diff -N src/org/eclipse/equinox/spi/p2/artifact/repository/SimpleArtifactTransportFactory.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/equinox/spi/p2/artifact/repository/SimpleArtifactTransportFactory.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,35 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 Genuitec, LLC and others. All rights reserved. This >+ * program and the accompanying materials are made available under the terms of >+ * the Eclipse Public License v1.0 which accompanies this distribution, and is >+ * available at http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: Genuitec, LLC - initial API and implementation >+ ******************************************************************************/ >+package org.eclipse.equinox.spi.p2.artifact.repository; >+ >+import java.net.URL; >+import java.util.*; >+import org.eclipse.equinox.internal.p2.artifact.repository.ECFTransport; >+import org.eclipse.equinox.internal.p2.artifact.repository.ECFTransportWithMirrors; >+import org.eclipse.equinox.p2.artifact.repository.IArtifactTransport; >+import org.eclipse.equinox.p2.artifact.repository.IArtifactTransportFactory; >+import org.eclipse.equinox.p2.artifact.repository.dlmirrors.IDownloadMirrorsDelegate; >+ >+public class SimpleArtifactTransportFactory implements IArtifactTransportFactory { >+ >+ private Set delegates = new HashSet(); >+ >+ public IArtifactTransport getTransport(URL artifactRepoLocation) { >+ for (Iterator iter = delegates.iterator(); iter.hasNext();) { >+ IDownloadMirrorsDelegate delegate = (IDownloadMirrorsDelegate) iter.next(); >+ if (delegate.worksWith(artifactRepoLocation)) >+ return new ECFTransportWithMirrors(delegate); >+ } >+ return ECFTransport.getInstance(); >+ } >+ >+ public void registerDownloadMirrors(IDownloadMirrorsDelegate downloadMirrorsDelegate) { >+ delegates.add(downloadMirrorsDelegate); >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 207802
:
81472
|
83572
|
88433
|
88919