Package org.hive2hive.core.processes.framework.interfaces

Examples of org.hive2hive.core.processes.framework.interfaces.IProcessComponent


      System.out.println("ERROR: Cannot wait until process is done.");
    }
  }

  public static void register(UserCredentials credentials, NetworkManager networkManager) throws NoPeerConnectionException {
    IProcessComponent process = ProcessFactory.instance().createRegisterProcess(credentials, networkManager);
    executeProcess(process);
  }
View Full Code Here


      throws NoPeerConnectionException {
    SessionParameters sessionParameters = new SessionParameters();
    sessionParameters.setFileConfig(new TestFileConfiguration());
    sessionParameters.setRoot(root.toPath());
    sessionParameters.setProfileManager(new UserProfileManager(networkManager.getDataManager(), credentials));
    IProcessComponent process = ProcessFactory.instance().createLoginProcess(credentials, sessionParameters,
        networkManager);
    executeProcess(process);
  }
View Full Code Here

    return manager.getUserProfile(UUID.randomUUID().toString(), false);
  }

  public static void uploadNewFile(NetworkManager networkManager, File file) throws NoSessionException,
      NoPeerConnectionException {
    IProcessComponent process = ProcessFactory.instance().createNewFileProcess(file, networkManager);
    executeProcess(process);
  }
View Full Code Here

    executeProcess(process);
  }

  public static void uploadNewVersion(NetworkManager networkManager, File file) throws NoSessionException,
      IllegalArgumentException, NoPeerConnectionException {
    IProcessComponent process = ProcessFactory.instance().createUpdateFileProcess(file, networkManager);
    executeProcess(process);
  }
View Full Code Here

    executeProcess(process);
  }

  public static File downloadFile(NetworkManager networkManager, PublicKey fileKey) throws NoSessionException,
      GetFailedException, NoPeerConnectionException {
    IProcessComponent process = ProcessFactory.instance().createDownloadFileProcess(fileKey, networkManager);
    executeProcess(process);
    UserProfile userProfile = getUserProfile(networkManager, networkManager.getSession().getCredentials());
    return FileUtil.getPath(networkManager.getSession().getRoot(), userProfile.getFileById(fileKey)).toFile();
  }
View Full Code Here

        File file = askForFile(true);
        if (file == null) {
          return;
        }

        IProcessComponent addFileProcess = menus.getNodeMenu().getNode().getFileManager().add(file);
        executeBlocking(addFileProcess, displayText);
      }
    });

    add(new H2HConsoleMenuItem("Update File") {
      protected boolean checkPreconditions() {
        return createRootDirectory();
      }

      protected void execute() throws Hive2HiveException, InterruptedException {

        File file = askForFile(true);
        if (file == null) {
          return;
        }
        IProcessComponent updateFileProcess = menus.getNodeMenu().getNode().getFileManager().update(file);
        executeBlocking(updateFileProcess, displayText);
      }
    });

    add(new H2HConsoleMenuItem("Move File") {
      protected boolean checkPreconditions() {
        return createRootDirectory();
      }

      protected void execute() throws Hive2HiveException, InterruptedException {
        File source = askForFile("Specify the relative path of the source file to the root directory '%s'.", true);
        if (source == null) {
          return;
        }

        File destination = askForFile(
            "Specify the relative path of the destination file to the root directory '%s'.", false);
        if (destination == null) {
          return;
        }

        IProcessComponent moveFileProcess = menus.getNodeMenu().getNode().getFileManager().move(source, destination);
        executeBlocking(moveFileProcess, displayText);
      }
    });

    add(new H2HConsoleMenuItem("Delete File") {
      protected boolean checkPreconditions() {
        return createRootDirectory();
      }

      protected void execute() throws Hive2HiveException, InterruptedException {
        File file = askForFile(true);
        if (file == null) {
          return;
        }

        IProcessComponent deleteFileProcess = menus.getNodeMenu().getNode().getFileManager().delete(file);
        executeBlocking(deleteFileProcess, displayText);
      }
    });

    add(new H2HConsoleMenuItem("Recover File") {
      protected boolean checkPreconditions() {
        return createRootDirectory();
      }

      protected void execute() throws Hive2HiveException, FileNotFoundException, IllegalArgumentException,
          InterruptedException {

        File file = askForFile(true);
        if (file == null) {
          return;
        }

        IVersionSelector versionSelector = new IVersionSelector() {
          public IFileVersion selectVersion(List<IFileVersion> availableVersions) {
            return new SelectionMenu<IFileVersion>(availableVersions, "Choose the version you want to recover.")
                .openAndSelect();
          }

          public String getRecoveredFileName(String fullName, String name, String extension) {
            print(String
                .format("Specify the new name for the recovered file '%s' or enter 'default' to take the default values:",
                    fullName));
            String input = awaitStringParameter();
            if ("default".equalsIgnoreCase(input)) {
              return null;
            } else {
              return input;
            }
          }
        };

        IProcessComponent recoverFileProcess = menus.getNodeMenu().getNode().getFileManager()
            .recover(file, versionSelector);
        executeBlocking(recoverFileProcess, displayText);
      }
    });

    add(new H2HConsoleMenuItem("Share File") {
      protected boolean checkPreconditions() {
        return createRootDirectory();
      }

      protected void execute() throws NoSessionException, NoPeerConnectionException, InvalidProcessStateException,
          InterruptedException {

        File folderToShare = askForFolder(
            "Specify the relative path of the folder you want to share to the root directory '%s'.", true);
        if (folderToShare == null) {
          return;
        }

        print("Specify the user ID of the user you want to share with.");
        String friendID = awaitStringParameter();

        PermissionType permission = askForPermission(folderToShare.getAbsolutePath(), friendID);
        if (permission == null) {
          return;
        }

        IProcessComponent shareProcess;
        try {
          shareProcess = menus.getNodeMenu().getNode().getFileManager().share(folderToShare, friendID, permission);
        } catch (IllegalFileLocation | IllegalArgumentException e) {
          printError(e.getMessage());
          return;
View Full Code Here

    fileBuffer.removeAll(toDelete);

    for (File file : fileBuffer) {
      try {
        IProcessComponent process = fileManager.update(file);
        if (!fileManager.isAutostart()) {
          process.start();
        }
      } catch (IllegalArgumentException | NoSessionException | NoPeerConnectionException
          | InvalidProcessStateException e) {
        logger.error(e.getMessage());
      }
View Full Code Here

    // delete individual files
    for (File toDelete : bufferedFiles) {
      try {
        logger.debug("Starting to delete buffered file {}.", toDelete);
        IProcessComponent delete = fileManager.delete(toDelete);
        if (!fileManager.isAutostart())
          delete.start();
        delete.await(MAX_DELETION_PROCESS_DURATION_MS);
      } catch (NoSessionException | NoPeerConnectionException | InvalidProcessStateException
          | InterruptedException e) {
        logger.error(e.getMessage());
      }
    }
View Full Code Here

  protected void processBuffer(IFileBufferHolder buffer) {
    Set<File> fileBuffer = filterBuffer(buffer.getFileBuffer(), buffer.getSyncFiles());

    for (File toAdd : fileBuffer) {
      try {
        IProcessComponent process = fileManager.add(toAdd);
        if (!fileManager.isAutostart())
          process.start();
      } catch (NoSessionException | NoPeerConnectionException | IllegalFileLocation
          | InvalidProcessStateException e) {
        logger.error(e.getMessage());
      }
    }
View Full Code Here

    NetworkManager notifier = network.get(0);
    // send notification to own peers
    Set<String> users = new HashSet<String>(1);
    users.add(userACredentials.getUserId());
    CountingNotificationMessageFactory msgFactory = new CountingNotificationMessageFactory(notifier);
    IProcessComponent process = ProcessFactory.instance().createNotificationProcess(msgFactory, users,
        notifier);
    process.start();

    H2HWaiter waiter = new H2HWaiter(20);
    do {
      waiter.tickASecond();
    } while (!msgFactory.allMsgsArrived());

    Assert.assertEquals(ProcessState.SUCCEEDED, process.getState());
  }
View Full Code Here

TOP

Related Classes of org.hive2hive.core.processes.framework.interfaces.IProcessComponent

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.