/**
   * Restart a request. Caller should call ,false first, at which point we setStarted, and ,true
   * when it has actually started (a race condition means we don't setStarted at that point since
   * it's possible the success/failure callback might happen first).
   */
  public synchronized void updateStarted(String identifier, boolean started) {
    RequestStatus status = requestsByIdentifier.get(identifier);
    if (status == null) return; // Can happen during cancel etc.

    if (!started)
      // Caller should call with false first, so we only need to unset finished when setting
      // started=false.
      status.restart(false);
    else
      // Already restarted, just set started = true.
      status.setStarted(started);
  }
 synchronized void removeByIdentifier(String identifier) {
   RequestStatus status = requestsByIdentifier.remove(identifier);
   if (status == null) return;
   if (status instanceof DownloadRequestStatus) {
     downloads.remove(status);
     FreenetURI uri = status.getURI();
     assert (uri != null);
     downloadsByURI.removeElement(uri, status);
   } else if (status instanceof UploadRequestStatus) {
     uploads.remove(status);
     FreenetURI uri = ((UploadRequestStatus) status).getFinalURI();
     if (uri != null) uploadsByFinalURI.removeElement(uri, status);
   }
 }
  public void testNoProblemWithMissingOptionalDependency() {
    // CDT will be missing a requirement but it is optional so everything should be good
    // EMF will be not be good because it is missing a requirement
    IRequirement missingOptionalDependency =
        MetadataFactory.createRequirement(
            IInstallableUnit.NAMESPACE_IU_ID,
            "MissingSomething",
            new VersionRange("[1.0.0, 1.0.0]"),
            null,
            true,
            false);
    IInstallableUnit cdt =
        createIU(
            "CDT",
            PublisherHelper.fromOSGiVersion(new org.osgi.framework.Version("1.0.0")),
            new IRequirement[] {missingOptionalDependency});

    IRequirement emfMissing =
        MetadataFactory.createRequirement(
            IInstallableUnit.NAMESPACE_IU_ID,
            "EMFPart",
            new VersionRange("[1.0.0, 1.0.0]"),
            null,
            false,
            false);
    IInstallableUnit emf =
        createIU(
            "EMF",
            PublisherHelper.fromOSGiVersion(new org.osgi.framework.Version("1.0.0")),
            new IRequirement[] {emfMissing},
            NO_PROPERTIES,
            true);

    createTestMetdataRepository(new IInstallableUnit[] {cdt, emf});
    ProfileChangeRequest pcr = new ProfileChangeRequest(profile);
    pcr.addInstallableUnits(new IInstallableUnit[] {cdt, emf});
    ProvisioningPlan plan = (ProvisioningPlan) planner.getProvisioningPlan(pcr, null, null);
    RequestStatus requestStatus = ((PlannerStatus) plan.getStatus()).getRequestStatus();
    assertTrue(requestStatus.getConflictsWithInstalledRoots().contains(emf));
    assertFalse(requestStatus.getConflictsWithInstalledRoots().contains(cdt));
    assertFalse(requestStatus.getConflictsWithInstalledRoots().contains(sdk));

    //		assertTrue(plan.getRequestStatus(cdt).getSeverity() != IStatus.ERROR);
    //
    //		assertTrue(plan.getRequestStatus(emf).getSeverity() == IStatus.ERROR);
    //		assertEquals(0, plan.getRequestStatus(emf).getConflictsWithInstalledRoots());
  }
 public void setPriority(String identifier, short newPriorityClass) {
   RequestStatus status = requestsByIdentifier.get(identifier);
   if (status == null) return; // Can happen during cancel etc.
   status.setPriority(newPriorityClass);
 }
 public synchronized void addTo(List<RequestStatus> status) {
   // FIXME is it better to just synchronize on the RequestStatusCache when
   // rendering the downloads page, and when updating? Ugly though ...
   for (RequestStatus req : requestsByIdentifier.values()) status.add(req.clone());
 }
 synchronized void updateStatus(String identifier, SplitfileProgressEvent event) {
   RequestStatus status = requestsByIdentifier.get(identifier);
   if (status == null) return; // Can happen during cancel etc.
   status.updateStatus(event);
 }