|
Lines 24-31
Link Here
|
| 24 |
import org.eclipse.equinox.p2.core.ProvisionException; |
24 |
import org.eclipse.equinox.p2.core.ProvisionException; |
| 25 |
import org.eclipse.equinox.p2.metadata.IArtifactKey; |
25 |
import org.eclipse.equinox.p2.metadata.IArtifactKey; |
| 26 |
import org.eclipse.equinox.spi.p2.artifact.repository.AbstractArtifactRepository; |
26 |
import org.eclipse.equinox.spi.p2.artifact.repository.AbstractArtifactRepository; |
|
|
27 |
import org.eclipse.osgi.util.NLS; |
| 27 |
|
28 |
|
| 28 |
public class SimpleArtifactRepository extends AbstractArtifactRepository implements IArtifactRepository, IFileArtifactRepository { |
29 |
public class SimpleArtifactRepository extends AbstractArtifactRepository implements IArtifactRepository, IFileArtifactRepository, IMultiThreadedArtifactRepository { |
| 29 |
|
30 |
|
| 30 |
public class ArtifactOutputStream extends OutputStream implements IStateful { |
31 |
public class ArtifactOutputStream extends OutputStream implements IStateful { |
| 31 |
private boolean closed; |
32 |
private boolean closed; |
|
Lines 159-168
Link Here
|
| 159 |
protected Set artifactDescriptors = new HashSet(); |
160 |
protected Set artifactDescriptors = new HashSet(); |
| 160 |
private transient BlobStore blobStore; |
161 |
private transient BlobStore blobStore; |
| 161 |
transient private Mapper mapper = new Mapper(); |
162 |
transient private Mapper mapper = new Mapper(); |
|
|
163 |
transient private IArtifactTransport transport; |
| 162 |
|
164 |
|
| 163 |
static final private String PACKED_FORMAT = "packed"; //$NON-NLS-1$ |
165 |
static final private String PACKED_FORMAT = "packed"; //$NON-NLS-1$ |
| 164 |
static final private String PUBLISH_PACK_FILES_AS_SIBLINGS = "publishPackFilesAsSiblings"; //$NON-NLS-1$ |
166 |
static final private String PUBLISH_PACK_FILES_AS_SIBLINGS = "publishPackFilesAsSiblings"; //$NON-NLS-1$ |
| 165 |
|
167 |
|
|
|
168 |
static final private int DEFAULT_MAX_THREADS = 4; |
| 169 |
|
| 166 |
protected String[][] mappingRules = DEFAULT_MAPPING_RULES; |
170 |
protected String[][] mappingRules = DEFAULT_MAPPING_RULES; |
| 167 |
|
171 |
|
| 168 |
private boolean signatureVerification = false; |
172 |
private boolean signatureVerification = false; |
|
Lines 379-385
Link Here
|
| 379 |
return super.getAdapter(adapter); |
383 |
return super.getAdapter(adapter); |
| 380 |
} |
384 |
} |
| 381 |
|
385 |
|
| 382 |
private IStatus getArtifact(ArtifactRequest request, IProgressMonitor monitor) { |
386 |
IStatus getArtifact(ArtifactRequest request, IProgressMonitor monitor) { |
| 383 |
request.setSourceRepository(this); |
387 |
request.setSourceRepository(this); |
| 384 |
request.perform(monitor); |
388 |
request.perform(monitor); |
| 385 |
return request.getResult(); |
389 |
return request.getResult(); |
|
Lines 429-448
Link Here
|
| 429 |
} |
433 |
} |
| 430 |
|
434 |
|
| 431 |
public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) { |
435 |
public IStatus getArtifacts(IArtifactRequest[] requests, IProgressMonitor monitor) { |
| 432 |
SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length); |
436 |
final MultiStatus overallStatus = new MultiStatus(Activator.ID, IStatus.OK, null, null); |
| 433 |
try { |
437 |
LinkedList requestsPending = new LinkedList(Arrays.asList(requests)); |
| 434 |
MultiStatus overallStatus = new MultiStatus(Activator.ID, IStatus.OK, null, null); |
438 |
|
| 435 |
for (int i = 0; i < requests.length; i++) { |
439 |
if (!isMultiThreadingEnabled() || requests.length <= 1) { |
| 436 |
if (monitor.isCanceled()) |
440 |
// multi-threading isn't enabled or too few requests, use simple inline download of artifacts |
| 437 |
return Status.CANCEL_STATUS; |
441 |
SubMonitor subMonitor = SubMonitor.convert(monitor, requests.length); |
| 438 |
IStatus result = getArtifact((ArtifactRequest) requests[i], subMonitor.newChild(1)); |
442 |
try { |
| 439 |
if (!result.isOK()) |
443 |
for (int i = 0; i < requests.length; i++) { |
| 440 |
overallStatus.add(result); |
444 |
if (monitor.isCanceled()) |
|
|
445 |
return Status.CANCEL_STATUS; |
| 446 |
IStatus result = getArtifact((ArtifactRequest) requests[i], subMonitor.newChild(1)); |
| 447 |
if (!result.isOK()) |
| 448 |
overallStatus.add(result); |
| 449 |
} |
| 450 |
} finally { |
| 451 |
subMonitor.done(); |
| 452 |
} |
| 453 |
} else { |
| 454 |
// initialize the various jobs needed to process the get artifact requests |
| 455 |
monitor.beginTask(NLS.bind(Messages.downloading_requests, new Integer(requests.length)), requests.length); |
| 456 |
try { |
| 457 |
// don't allocate more jobs than we have requests |
| 458 |
int numberOfJobs = Math.min(requests.length, getMaximumThreads()); |
| 459 |
SimpleArtifactRepositoryDownloadJob jobs[] = new SimpleArtifactRepositoryDownloadJob[numberOfJobs]; |
| 460 |
for (int i = 0; i < numberOfJobs; i++) { |
| 461 |
jobs[i] = new SimpleArtifactRepositoryDownloadJob("downloadjob-" + i); //$NON-NLS-1$ |
| 462 |
jobs[i].initialize(this, requestsPending, monitor, overallStatus); |
| 463 |
} |
| 464 |
// schedule the various jobs |
| 465 |
for (int i = 0; i < numberOfJobs; i++) { |
| 466 |
jobs[i].schedule(); |
| 467 |
} |
| 468 |
// wait for all the jobs to complete |
| 469 |
for (int i = 0; i < numberOfJobs; i++) { |
| 470 |
try { |
| 471 |
jobs[i].join(); |
| 472 |
} catch (InterruptedException e) { |
| 473 |
synchronized (overallStatus) { |
| 474 |
overallStatus.add(new Status(IStatus.ERROR, Activator.ID, NLS.bind(Messages.download_thread_interrupted, jobs[i].getName()))); |
| 475 |
} |
| 476 |
} |
| 477 |
} |
| 478 |
} finally { |
| 479 |
monitor.done(); |
| 441 |
} |
480 |
} |
| 442 |
return (monitor.isCanceled() ? Status.CANCEL_STATUS : overallStatus); |
|
|
| 443 |
} finally { |
| 444 |
subMonitor.done(); |
| 445 |
} |
481 |
} |
|
|
482 |
return (monitor.isCanceled() ? Status.CANCEL_STATUS : overallStatus); |
| 446 |
} |
483 |
} |
| 447 |
|
484 |
|
| 448 |
public synchronized IArtifactDescriptor getCompleteArtifactDescriptor(IArtifactKey key) { |
485 |
public synchronized IArtifactDescriptor getCompleteArtifactDescriptor(IArtifactKey key) { |
|
Lines 507-512
Link Here
|
| 507 |
return null; |
544 |
return null; |
| 508 |
} |
545 |
} |
| 509 |
|
546 |
|
|
|
547 |
private int getMaximumThreads() { |
| 548 |
try { |
| 549 |
Object value = getProperties().get(PROP_MAX_THREADS); |
| 550 |
if (value != null && value instanceof String) |
| 551 |
return Math.max(1, Integer.parseInt((String) getProperties().get(PROP_MAX_THREADS))); |
| 552 |
} catch (NumberFormatException nfe) { |
| 553 |
// return default number of threads |
| 554 |
} |
| 555 |
return DEFAULT_MAX_THREADS; |
| 556 |
} |
| 557 |
|
| 510 |
public OutputStream getOutputStream(IArtifactDescriptor descriptor) { |
558 |
public OutputStream getOutputStream(IArtifactDescriptor descriptor) { |
| 511 |
assertModifiable(); |
559 |
assertModifiable(); |
| 512 |
// TODO we need a better way of distinguishing between errors and cases where |
560 |
// TODO we need a better way of distinguishing between errors and cases where |
|
Lines 577-584
Link Here
|
| 577 |
return signatureVerification; |
625 |
return signatureVerification; |
| 578 |
} |
626 |
} |
| 579 |
|
627 |
|
| 580 |
private Transport getTransport() { |
628 |
private IArtifactTransport getTransport() { |
| 581 |
return ECFTransport.getInstance(); |
629 |
if (transport == null) { |
|
|
630 |
IArtifactTransportFactory manager = (IArtifactTransportFactory) ServiceHelper.getService(Activator.getContext(), IArtifactTransportFactory.class.getName()); |
| 631 |
if (manager != null) |
| 632 |
transport = manager.getTransport(getLocation()); |
| 633 |
if (transport == null) |
| 634 |
transport = ECFTransport.getInstance(); |
| 635 |
} |
| 636 |
return transport; |
| 582 |
} |
637 |
} |
| 583 |
|
638 |
|
| 584 |
// use this method to setup any transient fields etc after the object has been restored from a stream |
639 |
// use this method to setup any transient fields etc after the object has been restored from a stream |
|
Lines 615-620
Link Here
|
| 615 |
return isLocal(); |
670 |
return isLocal(); |
| 616 |
} |
671 |
} |
| 617 |
|
672 |
|
|
|
673 |
public boolean isMultiThreadingEnabled() { |
| 674 |
return !isLocal() && getMaximumThreads() > 1; |
| 675 |
} |
| 676 |
|
| 618 |
public OutputStream processDestination(ProcessingStepHandler handler, IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { |
677 |
public OutputStream processDestination(ProcessingStepHandler handler, IArtifactDescriptor descriptor, OutputStream destination, IProgressMonitor monitor) { |
| 619 |
destination = addPostSteps(handler, descriptor, destination, monitor); |
678 |
destination = addPostSteps(handler, descriptor, destination, monitor); |
| 620 |
destination = handler.createAndLink(descriptor.getProcessingSteps(), descriptor, destination, monitor); |
679 |
destination = handler.createAndLink(descriptor.getProcessingSteps(), descriptor, destination, monitor); |
|
Lines 752-756
Link Here
|
| 752 |
public String toString() { |
811 |
public String toString() { |
| 753 |
return location.toExternalForm(); |
812 |
return location.toExternalForm(); |
| 754 |
} |
813 |
} |
| 755 |
|
|
|
| 756 |
} |
814 |
} |