Package org.hive2hive.core.processes.implementations.files.download.direct

Examples of org.hive2hive.core.processes.implementations.files.download.direct.DownloadTaskDirect


  }

  private void schedule(BaseDownloadTask task) {
    if (task.isDirectDownload()) {
      // first get the locations of all users having access to this file
      DownloadTaskDirect directTask = (DownloadTaskDirect) task;
      // Hint: Run it in a separate thread (not in the thread pool) because the executor does not
      // guarantee the in-order processing.
      new Thread(new GetLocationsList(directTask, dataManager)).start();

      // then download all chunks in separate threads
View Full Code Here


  private void downloadChunksFromUsers(MetaFileLarge metaFile) throws ProcessExecutionException {
    // TODO support versioning at large files as well

    try {
      Set<String> users = context.consumeIndex().getCalculatedUserList();
      DownloadTaskDirect task = new DownloadTaskDirect(metaFile.getMetaChunks(), destination,
          metaFile.getId(), session.getUserId(), ownPeerAddress, users);
      session.getDownloadManager().submit(task);
      task.join();
    } catch (InterruptedException e) {
      throw new ProcessExecutionException(e.getMessage());
    }

  }
View Full Code Here

    this.context = context;
  }

  @Override
  protected void doExecute() throws InvalidProcessStateException, ProcessExecutionException {
    DownloadTaskDirect task = context.getTask();
    logger.debug("Getting the locations to download {} in a blocking manner.", task.getDestinationName());
    List<Locations> locations = task.consumeLocationsBlocking();
    logger.debug("Got the locations to download {}.", task.getDestinationName());

    if (task.isAborted()) {
      logger.warn("Not executing step because task is aborted");
      return;
    }

    // prefer own user name
    PeerAddress selectedOwnPeer = null;
    for (Locations location : locations) {
      if (location.getUserId().equals(task.getOwnUserName())) {
        selectedOwnPeer = selectAddressOwnUser(location.getPeerAddresses());
        break;
      }
    }

    if (selectedOwnPeer != null) {
      logger.debug("Found peer of own user to contact for the file {}", task.getDestinationName());
      context.setSelectedPeer(selectedOwnPeer, task.getOwnUserName());
      return;
    }

    // if own peer is not possible, take a foreign sharer
    Random rnd = new Random();
    while (!locations.isEmpty()) {
      Locations randomLocation = locations.get(rnd.nextInt(locations.size()));
      List<PeerAddress> addresses = new ArrayList<PeerAddress>(randomLocation.getPeerAddresses());
      if (addresses.isEmpty()) {
        // does not contain any addresses, kick it
        locations.remove(randomLocation);
      } else {
        logger.debug("Found peer of foreign user to contact for the file {}", task.getDestinationName());
        PeerAddress rndAddress = addresses.get(rnd.nextInt(addresses.size()));
        context.setSelectedPeer(rndAddress, randomLocation.getUserId());
        return;
      }
    }

    logger.warn("No online peer found that could be contacted to get the file {}", task.getDestinationName());
    throw new ProcessExecutionException("No online peer found that could be contacted");
  }
View Full Code Here

    logger.warn("No online peer found that could be contacted to get the file {}", task.getDestinationName());
    throw new ProcessExecutionException("No online peer found that could be contacted");
  }

  private PeerAddress selectAddressOwnUser(Set<PeerAddress> addresses) {
    DownloadTaskDirect task = context.getTask();
    addresses.remove(task.getOwnAddress());

    // if possible, select the one with the same external IP (could be in same subnet)
    InetAddress ownInetAddress = task.getOwnAddress().getInetAddress();
    if (ownInetAddress != null) {
      for (PeerAddress peerAddress : addresses) {
        if (ownInetAddress.equals(peerAddress.getInetAddress())) {
          // internet addresses (external IP) match, prefer this address
          // TODO: verify this assumption
View Full Code Here

TOP

Related Classes of org.hive2hive.core.processes.implementations.files.download.direct.DownloadTaskDirect

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.