Package org.hive2hive.core.processes.framework.concretes

Examples of org.hive2hive.core.processes.framework.concretes.SequentialProcess


  public ProcessComponent createShareProcess(File folder, UserPermission permission, NetworkManager networkManager)
      throws NoSessionException, NoPeerConnectionException {
    ShareProcessContext context = new ShareProcessContext(folder, permission);

    SequentialProcess process = new SequentialProcess();
    process.add(new VerifyFriendIdStep(networkManager.getSession().getKeyManager(), permission.getUserId()));
    process.add(new UpdateUserProfileStep(context, networkManager.getSession()));
    process.add(new InitializeMetaUpdateStep(context, networkManager.getDataManager()));
    process.add(new PrepareNotificationsStep(context, networkManager.getUserId()));
    process.add(createNotificationProcess(context, networkManager));

    return process;
  }
View Full Code Here


  private ProcessComponent createNotificationProcess(IConsumeNotificationFactory providerContext,
      NetworkManager networkManager) throws IllegalArgumentException, NoPeerConnectionException, NoSessionException {
    NotifyProcessContext context = new NotifyProcessContext(providerContext);

    SequentialProcess process = new SequentialProcess();
    process.add(new VerifyNotificationFactoryStep(context, networkManager.getUserId()));
    process.add(new GetPublicKeysStep(context, networkManager.getSession().getKeyManager()));
    process.add(new PutAllUserProfileTasksStep(context, networkManager));
    process.add(new GetAllLocationsStep(context, networkManager.getDataManager()));
    process.add(new SendNotificationsMessageStep(context, networkManager));

    return process;
  }
View Full Code Here

   * @throws NoPeerConnectionException
   */
  public static ProcessComponent buildUploadProcess(List<Path> files, FileProcessAction action,
      NetworkManager networkManager) throws NoSessionException, NoPeerConnectionException {
    // the sequential root process
    SequentialProcess rootProcess = new SequentialProcess();

    // key idea: Find the children with the same parents and add them to a sequential process. They need
    // to be sequential because the parent meta file must be adapted. If they would run in parallel, they
    // would modify the parent meta folder simultaneously.
    Map<Path, SequentialProcess> sameParents = new HashMap<Path, SequentialProcess>();
    for (Path file : files) {
      // create the process which uploads or updates the file
      ProcessComponent uploadProcess;
      if (action == FileProcessAction.NEW_FILE)
        uploadProcess = ProcessFactory.instance().createNewFileProcess(file.toFile(), networkManager);
      else
        uploadProcess = ProcessFactory.instance().createUpdateFileProcess(file.toFile(),
            networkManager);

      Path parentFile = file.getParent();
      if (sameParents.containsKey(parentFile)) {
        // a sibling exists that already created a sequential process
        SequentialProcess sequentialProcess = sameParents.get(parentFile);
        sequentialProcess.add(uploadProcess);
      } else {
        // first file with this parent; create new sequential process
        SequentialProcess sequentialProcess = new SequentialProcess();
        sequentialProcess.add(uploadProcess);
        sameParents.put(parentFile, sequentialProcess);
      }
    }

    // the children are now grouped together. Next, we need to link the parent files.
    for (Path parent : sameParents.keySet()) {
      AsyncComponent asyncChain = new AsyncComponent(sameParents.get(parent));
      Path parentOfParent = parent.getParent();
      if (sameParents.containsKey(parentOfParent)) {
        // parent exists, we add this sub-process (sequential) to it. It can be async here
        SequentialProcess sequentialProcess = sameParents.get(parentOfParent);
        sequentialProcess.add(asyncChain);
      } else {
        // parent does not exist --> attach the sub-tree to the root
        rootProcess.add(asyncChain);
      }
    }
View Full Code Here

   * @throws NoPeerConnectionException
   */
  public static ProcessComponent buildDeletionProcess(List<Path> files, NetworkManager networkManager)
      throws NoSessionException, NoPeerConnectionException {
    // the sequential root process
    SequentialProcess rootProcess = new SequentialProcess();

    // deletion must happen in reverse tree order. Since this is very complicated when it contains
    // asynchronous components, we simply delete them all in the same thread (reverse preorder of course)
    Collections.reverse(files);
    for (Path file : files) {
      ProcessComponent deletionProcess = ProcessFactory.instance().createDeleteFileProcess(
          file.toFile(), networkManager);
      rootProcess.add(deletionProcess);
    }

    return new AsyncComponent(rootProcess);
  }
View Full Code Here

   * @throws NoSessionException
   */
  public static ProcessComponent buildDownloadProcess(List<Index> files, NetworkManager networkManager)
      throws NoSessionException {
    // the root process, where everything runs in parallel (only async children are added)
    SequentialProcess rootProcess = new SequentialProcess();

    // build a flat map of the folders to download (such that O(1) for each lookup)
    Map<FolderIndex, SequentialProcess> folderMap = new HashMap<FolderIndex, SequentialProcess>();
    Map<FileIndex, AsyncComponent> fileMap = new HashMap<FileIndex, AsyncComponent>();

    for (Index file : files) {
      PublicKey fileKey = file.getFilePublicKey();
      ProcessComponent downloadProcess = ProcessFactory.instance().createDownloadFileProcess(fileKey,
          networkManager);
      if (file.isFolder()) {
        // when a directory, the process may have multiple children, thus we need a sequential process
        SequentialProcess folderProcess = new SequentialProcess();
        folderProcess.add(downloadProcess);
        folderMap.put((FolderIndex) file, folderProcess);
      } else {
        // when a file, the process can run in parallel with all siblings (done in next step)
        fileMap.put((FileIndex) file, new AsyncComponent(downloadProcess));
      }
    }

    // find children with same parents and make them run in parallel
    // idea: iterate through all children and search for parent in other map. If not there, they can be
    // added to the root process anyway
    for (FileIndex file : fileMap.keySet()) {
      AsyncComponent fileProcess = fileMap.get(file);
      Index parent = file.getParent();
      if (parent == null) {
        // file is in root, thus we can add it to the root process
        rootProcess.add(fileProcess);
      } else if (folderMap.containsKey(parent)) {
        // the parent exists here
        SequentialProcess parentProcess = folderMap.get(parent);
        parentProcess.add(fileProcess);
      } else {
        // file is not in root and parent is not here, thus we simply add it to the root process
        rootProcess.add(fileProcess);
      }
    }

    // files and folder are linked. We now link the folders with other folders
    for (FolderIndex folder : folderMap.keySet()) {
      SequentialProcess folderProcess = folderMap.get(folder);
      // In addition, we can make this process run asynchronous because it does not affect the siblings
      AsyncComponent asyncFolderProcess = new AsyncComponent(folderProcess);
      Index parent = folder.getParent();
      if (parent == null) {
        // file is in root, thus we can add it to the root process.
        rootProcess.add(asyncFolderProcess);
      } else if (folderMap.containsKey(parent)) {
        // this folder has a parent
        SequentialProcess parentProcess = folderMap.get(parent);
        parentProcess.add(asyncFolderProcess);
      } else {
        // folder is not in root and parent folder does not sync here, add it to the root process
        rootProcess.add(asyncFolderProcess);
      }
    }
View Full Code Here

        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    SimpleGetUserProfileTaskContext context = new SimpleGetUserProfileTaskContext();

    SequentialProcess process = new SequentialProcess();
    process.add(new TestPutUserProfileTaskStep(userId, userProfileTask, key.getPublic(), node));
    process.add(new GetUserProfileTaskStep(context, node));

    UseCaseTestUtil.executeProcess(process);
  }
View Full Code Here

        "pin")), publicKeyManager, new DownloadManager(node.getDataManager(), node.getMessageManager(),
        publicKeyManager, config), config, FileTestUtil.getTempDirectory().toPath()));

    SimpleGetUserProfileTaskContext context = new SimpleGetUserProfileTaskContext();

    SequentialProcess process = new SequentialProcess();
    process.add(new TestPutUserProfileTaskStep(userId, userProfileTask, key.getPublic(), node));
    process.add(new GetUserProfileTaskStep(context, node));
    process.add(new RemoveUserProfileTaskStep(context, node));

    UseCaseTestUtil.executeProcess(process);

    Parameters parameters = new Parameters().setLocationKey(userId).setDomainKey(H2HConstants.USER_PROFILE_TASK_DOMAIN)
        .setContentKey(userProfileTask.getContentKey());
View Full Code Here

  @Test
  public void asyncRollbackTest() throws InvalidProcessStateException {
   
    // sync components (level-1 fail)
    SequentialProcess subProcess = new SequentialProcess();
    ProcessStep subStep1 = new SucceedingProcessStep();
    ProcessStep subStep2 = new SucceedingProcessStep();
    subProcess.add(subStep1);
    subProcess.add(subStep2);

    SequentialProcess process = new SequentialProcess();
    ProcessStep step1 = new SucceedingProcessStep();
    ProcessStep step2 = new SucceedingProcessStep();
    ProcessStep step3 = new FailingProcessStep();
    ProcessStep step4 = new SucceedingProcessStep();
    process.add(step1);
    process.add(step2);
    process.add(subProcess);
    process.add(step3);
    process.add(step4);
    AsyncComponent asyncProcess = new AsyncComponent(process);
    asyncProcess.start();

    TestUtil.wait(WAIT_FOR_ASYNC);
   
    assertTrue(asyncProcess.getState() == ProcessState.FAILED);
    assertTrue(process.getState() == ProcessState.FAILED);
    assertTrue(step1.getState() == ProcessState.FAILED);
    assertTrue(step2.getState() == ProcessState.FAILED);
    assertTrue(subProcess.getState() == ProcessState.FAILED);
    assertTrue(subStep1.getState() == ProcessState.FAILED);
    assertTrue(subStep2.getState() == ProcessState.FAILED);
    assertTrue(step3.getState() == ProcessState.FAILED);
    assertTrue(step4.getState() == ProcessState.READY);

    // sync components (level-2 fail)
    subProcess = new SequentialProcess();
    subStep1 = new SucceedingProcessStep();
    subStep2 = new FailingProcessStep();
    ProcessStep subStep3 = new SucceedingProcessStep();
    subProcess.add(subStep1);
    subProcess.add(subStep2);
    subProcess.add(subStep3);

    process = new SequentialProcess();
    step1 = new SucceedingProcessStep();
    step2 = new SucceedingProcessStep();
    step3 = new SucceedingProcessStep();
    process.add(step1);
    process.add(step2);
    process.add(subProcess);
    process.add(step3);
    asyncProcess = new AsyncComponent(process);
    asyncProcess.start();
   
    TestUtil.wait(WAIT_FOR_ASYNC);

    assertTrue(asyncProcess.getState() == ProcessState.FAILED);
    assertTrue(process.getState() == ProcessState.FAILED);
    assertTrue(step1.getState() == ProcessState.FAILED);
    assertTrue(step2.getState() == ProcessState.FAILED);
    assertTrue(subProcess.getState() == ProcessState.FAILED);
    assertTrue(subStep1.getState() == ProcessState.FAILED);
    assertTrue(subStep2.getState() == ProcessState.FAILED);
    assertTrue(subStep3.getState() == ProcessState.READY);
    assertTrue(step3.getState() == ProcessState.READY);

    // async components (level-1 fail)
    // sync step fails
    subProcess = new SequentialProcess();
    subStep1 = new SucceedingProcessStep();
    subStep2 = new SucceedingProcessStep();
    subProcess.add(subStep1);
    subProcess.add(subStep2);

    process = new SequentialProcess();
    step1 = new SucceedingProcessStep();
    step2 = new BusySucceedingStep(); // make sure rollback waits for all async components
    AsyncComponent asyncStep2 = new AsyncComponent(step2);
    step3 = new FailingProcessStep();
    step4 = new SucceedingProcessStep();
    process.add(step1);
    process.add(asyncStep2);
    process.add(subProcess);
    process.add(step3);
    process.add(step4);
    asyncProcess = new AsyncComponent(process);
    asyncProcess.start();
   
    TestUtil.wait(WAIT_FOR_ASYNC);

    assertTrue(asyncProcess.getState() == ProcessState.FAILED);
    assertTrue(process.getState() == ProcessState.FAILED);
    assertTrue(step1.getState() == ProcessState.FAILED);
    assertTrue(asyncStep2.getState() == ProcessState.FAILED);
    assertTrue(asyncStep2.getState() == ProcessState.FAILED);
    assertTrue(subProcess.getState() == ProcessState.FAILED);
    assertTrue(subStep1.getState() == ProcessState.FAILED);
    assertTrue(subStep2.getState() == ProcessState.FAILED);
    assertTrue(step3.getState() == ProcessState.FAILED);
    assertTrue(step4.getState() == ProcessState.READY);

    // async step fails
    subProcess = new SequentialProcess();
    subStep1 = new SucceedingProcessStep();
    subStep2 = new SucceedingProcessStep();
    subProcess.add(subStep1);
    subProcess.add(subStep2);

    process = new SequentialProcess();
    step1 = new SucceedingProcessStep();
    step2 = new SucceedingProcessStep();
    step3 = new BusyFailingStep(); // make sure rollback waits for all async components
    AsyncComponent asyncStep3 = new AsyncComponent(step3);
    step4 = new SucceedingProcessStep();
    process.add(step1);
    process.add(step2);
    process.add(subProcess);
    process.add(asyncStep3);
    process.add(step4);
    asyncProcess = new AsyncComponent(process);
    asyncProcess.start();
   
    TestUtil.wait(WAIT_FOR_ASYNC);

    assertTrue(asyncProcess.getState() == ProcessState.FAILED);
    assertTrue(process.getState() == ProcessState.FAILED);
    assertTrue(step1.getState() == ProcessState.FAILED);
    assertTrue(step2.getState() == ProcessState.FAILED);
    assertTrue(subProcess.getState() == ProcessState.FAILED);
    assertTrue(subStep1.getState() == ProcessState.FAILED);
    assertTrue(subStep2.getState() == ProcessState.FAILED);
    assertTrue(asyncStep3.getState() == ProcessState.FAILED);
    assertTrue(step3.getState() == ProcessState.FAILED);
    assertTrue(step4.getState() == ProcessState.READY || step4.getState() == ProcessState.FAILED);

    // async components (level-2 fail)
    subProcess = new SequentialProcess();
    subStep1 = new SucceedingProcessStep();
    subStep2 = new FailingProcessStep();
    subStep3 = new SucceedingProcessStep();
    subProcess.add(subStep1);
    subProcess.add(subStep2);
    subProcess.add(subStep3);
    AsyncComponent asyncSubProcess = new AsyncComponent(subProcess);

    process = new SequentialProcess();
    step1 = new SucceedingProcessStep();
    step2 = new SucceedingProcessStep();
    step3 = new SucceedingProcessStep();
    process.add(step1);
    process.add(step2);
    process.add(asyncSubProcess);
    process.add(step3);
    asyncProcess = new AsyncComponent(process);
    asyncProcess.start();
   
    TestUtil.wait(WAIT_FOR_ASYNC);

    assertTrue(asyncProcess.getState() == ProcessState.FAILED);
    assertTrue(process.getState() == ProcessState.FAILED);
    assertTrue(step1.getState() == ProcessState.FAILED);
    assertTrue(step2.getState() == ProcessState.FAILED);
    assertTrue(asyncSubProcess.getState() == ProcessState.FAILED);
    assertTrue(subProcess.getState() == ProcessState.FAILED);
    assertTrue(subStep1.getState() == ProcessState.FAILED);
View Full Code Here

 
  @Test
  public void awaitSyncTest() throws InvalidProcessStateException, InterruptedException {
   
    // succeeding process
    SequentialProcess process = new SequentialProcess();
    process.add(new BusySucceedingStep());
    process.start();
    process.await();
    if (process.getState() != ProcessState.SUCCEEDED)
      fail("Busy process should have finished. Await() did not block.");
    TestUtil.wait(TestUtil.DEFAULT_WAITING_TIME);
    assertTrue(process.getState() == ProcessState.SUCCEEDED);
   
    // failing process
    SequentialProcess process2 = new SequentialProcess();
    process2.add(new BusyFailingStep());
    process2.start();
    process2.await();
    if (process2.getState() != ProcessState.FAILED)
      fail("Busy process should have finished. Await() did not block.");
    TestUtil.wait(TestUtil.DEFAULT_WAITING_TIME);
    assertTrue(process2.getState() == ProcessState.FAILED);
  }
View Full Code Here

 
  @Test
  public void awaitAsyncTest() throws InvalidProcessStateException, InterruptedException {
   
    // succeeding process
    SequentialProcess process = new SequentialProcess();
    process.add(new BusySucceedingStep());
    AsyncComponent asyncProcess = new AsyncComponent(process);
    asyncProcess.start();
    asyncProcess.await();
    if (asyncProcess.getState() != ProcessState.SUCCEEDED)
      fail("Busy process should have finished. Await() did not block.");
    TestUtil.wait(TestUtil.DEFAULT_WAITING_TIME);
    assertTrue(asyncProcess.getState() == ProcessState.SUCCEEDED);
   
    // failing process
    SequentialProcess process2 = new SequentialProcess();
    process2.add(new BusyFailingStep());
    AsyncComponent asyncProcess2 = new AsyncComponent(process2);
    asyncProcess2.start();
    asyncProcess2.await();
    if (asyncProcess2.getState() != ProcessState.FAILED)
      fail("Busy process should have finished. Await() did not block.");
View Full Code Here

TOP

Related Classes of org.hive2hive.core.processes.framework.concretes.SequentialProcess

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.