Java 类com.intellij.util.BufferedListConsumer 实例源码

项目:tools-idea    文件:FileHistorySessionPartner.java   
public FileHistorySessionPartner(final VcsHistoryProvider vcsHistoryProvider, final AnnotationProvider annotationProvider,
                                 final FilePath path,
                                 final String repositoryPath,
                                 final AbstractVcs vcs,
                                 final FileHistoryRefresherI refresherI) {
  myVcsHistoryProvider = vcsHistoryProvider;
  myAnnotationProvider = annotationProvider;
  myPath = path;
  myLimitHistoryCheck = new LimitHistoryCheck(vcs.getProject(), path.getPath());
  myRepositoryPath = repositoryPath;
  myVcs = vcs;
  myRefresherI = refresherI;
  myBuffer = new BufferedListConsumer<VcsFileRevision>(5, new Consumer<List<VcsFileRevision>>() {
    public void consume(List<VcsFileRevision> vcsFileRevisions) {
      mySession.getRevisionList().addAll(vcsFileRevisions);
      final VcsHistorySession copy = mySession.copyWithCachedRevision();
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        public void run() {
          ensureHistoryPanelCreated().getHistoryPanelRefresh().consume(copy);
        }
      });
    }
  }, 1000);
}
项目:intellij-ce-playground    文件:AbstractVcsHelperImpl.java   
public void run(@NotNull final ProgressIndicator indicator) {
  final AsynchConsumer<List<CommittedChangeList>> appender = myDlg.getAppender();
  final BufferedListConsumer<CommittedChangeList> bufferedListConsumer = new BufferedListConsumer<CommittedChangeList>(10, appender, -1);

  final Application application = ApplicationManager.getApplication();
  try {
    myProvider.loadCommittedChanges(mySettings, myLocation, 0, new AsynchConsumer<CommittedChangeList>() {
      public void consume(CommittedChangeList committedChangeList) {
        myRevisionsReturned = true;
        bufferedListConsumer.consumeOne(committedChangeList);
        if (myCanceled) {
          indicator.cancel();
        }
      }

      public void finished() {
        bufferedListConsumer.flush();
        appender.finished();

        if (! myRevisionsReturned) {
          application.invokeLater(new Runnable() {
            public void run() {
              myDlg.close(-1);
            }
          }, ModalityState.stateForComponent(myDlg.getWindow()));
        }
      }
    });
  }
  catch (VcsException e) {
    myExceptions.add(e);
    application.invokeLater(new Runnable() {
      public void run() {
        myDlg.close(-1);
      }
    }, ModalityState.stateForComponent(myDlg.getWindow()));
  }
}
项目:intellij-ce-playground    文件:FileHistorySessionPartner.java   
public FileHistorySessionPartner(final VcsHistoryProvider vcsHistoryProvider,
                                 @NotNull final FilePath path,
                                 final AbstractVcs vcs,
                                 final FileHistoryRefresherI refresherI) {
  myVcsHistoryProvider = vcsHistoryProvider;
  myPath = path;
  myLimitHistoryCheck = new LimitHistoryCheck(vcs.getProject(), path.getPath());
  myVcs = vcs;
  myRefresherI = refresherI;
  Consumer<List<VcsFileRevision>> sessionRefresher = new Consumer<List<VcsFileRevision>>() {
    public void consume(List<VcsFileRevision> vcsFileRevisions) {
      // TODO: Logic should be revised to we could just append some revisions to history panel instead of creating and showing new history
      // TODO: session
      mySession.getRevisionList().addAll(vcsFileRevisions);
      final VcsHistorySession copy = mySession.copyWithCachedRevision();
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        public void run() {
          ensureHistoryPanelCreated().getHistoryPanelRefresh().consume(copy);
        }
      });
    }
  };
  myBuffer = new BufferedListConsumer<VcsFileRevision>(5, sessionRefresher, 1000) {
    @Override
    protected void invokeConsumer(@NotNull Runnable consumerRunnable) {
      // Do not invoke in arbitrary background thread as due to parallel execution this could lead to cases when invokeLater() (from
      // sessionRefresher) is scheduled at first for history session with (as an example) 10 revisions (new buffered list) and then with
      // 5 revisions (previous buffered list). And so incorrect UI is shown to the user.
      consumerRunnable.run();
    }
  };
}
项目:tools-idea    文件:AbstractVcsHelperImpl.java   
public void run(@NotNull final ProgressIndicator indicator) {
  final AsynchConsumer<List<CommittedChangeList>> appender = myDlg.getAppender();
  final BufferedListConsumer<CommittedChangeList> bufferedListConsumer = new BufferedListConsumer<CommittedChangeList>(10, appender, -1);

  final Application application = ApplicationManager.getApplication();
  try {
    myProvider.loadCommittedChanges(mySettings, myLocation, 0, new AsynchConsumer<CommittedChangeList>() {
      public void consume(CommittedChangeList committedChangeList) {
        myRevisionsReturned = true;
        bufferedListConsumer.consumeOne(committedChangeList);
        if (myCanceled) {
          indicator.cancel();
        }
      }

      public void finished() {
        bufferedListConsumer.flush();
        appender.finished();

        if (! myRevisionsReturned) {
          application.invokeLater(new Runnable() {
            public void run() {
              myDlg.close(-1);
            }
          }, ModalityState.stateForComponent(myDlg.getWindow()));
        }
      }
    });
  }
  catch (VcsException e) {
    myExceptions.add(e);
    application.invokeLater(new Runnable() {
      public void run() {
        myDlg.close(-1);
      }
    }, ModalityState.stateForComponent(myDlg.getWindow()));
  }
}
项目:consulo    文件:AbstractVcsHelperImpl.java   
public void run(@Nonnull final ProgressIndicator indicator) {
  final AsynchConsumer<List<CommittedChangeList>> appender = myDlg.getAppender();
  final BufferedListConsumer<CommittedChangeList> bufferedListConsumer = new BufferedListConsumer<>(10, appender, -1);

  final Application application = ApplicationManager.getApplication();
  try {
    myProvider.loadCommittedChanges(mySettings, myLocation, 0, new AsynchConsumer<CommittedChangeList>() {
      public void consume(CommittedChangeList committedChangeList) {
        myRevisionsReturned = true;
        bufferedListConsumer.consumeOne(committedChangeList);
        if (myCanceled) {
          indicator.cancel();
        }
      }

      public void finished() {
        bufferedListConsumer.flush();
        appender.finished();

        if (! myRevisionsReturned) {
          application.invokeLater(new Runnable() {
            public void run() {
              myDlg.close(-1);
            }
          }, ModalityState.stateForComponent(myDlg.getWindow()));
        }
      }
    });
  }
  catch (VcsException e) {
    myExceptions.add(e);
    application.invokeLater(new Runnable() {
      public void run() {
        myDlg.close(-1);
      }
    }, ModalityState.stateForComponent(myDlg.getWindow()));
  }
}
项目:consulo    文件:FileHistorySessionPartner.java   
public FileHistorySessionPartner(@Nonnull VcsHistoryProvider vcsHistoryProvider,
                                 @Nonnull FilePath path,
                                 @Nullable VcsRevisionNumber startingRevisionNumber,
                                 @Nonnull AbstractVcs vcs,
                                 @Nonnull FileHistoryRefresherI refresherI) {
  myVcsHistoryProvider = vcsHistoryProvider;
  myPath = path;
  myStartingRevisionNumber = startingRevisionNumber;
  myLimitHistoryCheck = new LimitHistoryCheck(vcs.getProject(), path.getPath());
  myVcs = vcs;
  myRefresherI = refresherI;
  Consumer<List<VcsFileRevision>> sessionRefresher = vcsFileRevisions -> {
    // TODO: Logic should be revised to just append some revisions to history panel instead of creating and showing new history session
    mySession.getRevisionList().addAll(vcsFileRevisions);
    VcsHistorySession copy = mySession.copyWithCachedRevision();
    ApplicationManager.getApplication().invokeAndWait(() -> ensureHistoryPanelCreated().getHistoryPanelRefresh().consume(copy));
  };
  myBuffer = new BufferedListConsumer<VcsFileRevision>(5, sessionRefresher, 1000) {
    @Override
    protected void invokeConsumer(@Nonnull Runnable consumerRunnable) {
      // Do not invoke in arbitrary background thread as due to parallel execution this could lead to cases when invokeLater() (from
      // sessionRefresher) is scheduled at first for history session with (as an example) 10 revisions (new buffered list) and then with
      // 5 revisions (previous buffered list). And so incorrect UI is shown to the user.
      consumerRunnable.run();
    }
  };
}
项目:intellij-ce-playground    文件:CommittedChangesPanel.java   
private void refreshChangesFromLocation() {
  myBrowser.reset();

  myInLoad = true;
  myBrowser.setLoading(true);
  ProgressManager.getInstance().run(new Task.Backgroundable(myProject, "Loading changes", true, BackgroundFromStartOption.getInstance()) {

    public void run(@NotNull final ProgressIndicator indicator) {
      try {
        final AsynchConsumer<List<CommittedChangeList>> appender = new AsynchConsumer<List<CommittedChangeList>>() {
          public void finished() {
          }

          public void consume(final List<CommittedChangeList> list) {
            new AbstractCalledLater(myProject, ModalityState.stateForComponent(myBrowser)) {
              public void run() {
                myBrowser.append(list);
              }
            }.callMe();
          }
        };
        final BufferedListConsumer<CommittedChangeList> bufferedListConsumer = new BufferedListConsumer<CommittedChangeList>(30, appender,-1);

        myProvider.loadCommittedChanges(mySettings, myLocation, myMaxCount, new AsynchConsumer<CommittedChangeList>() {
          public void finished() {
            bufferedListConsumer.flush();
          }
          public void consume(CommittedChangeList committedChangeList) {
            if (myDisposed) {
              indicator.cancel();
            }
            ProgressManager.checkCanceled();
            bufferedListConsumer.consumeOne(committedChangeList);
          }
        });
      }
      catch (final VcsException e) {
        LOG.info(e);
        WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {
          public void run() {
            Messages.showErrorDialog(myProject, "Error refreshing view: " + StringUtil.join(e.getMessages(), "\n"), "Committed Changes");
          }
        }, null, myProject);
      } finally {
        myInLoad = false;
        myBrowser.setLoading(false);
      }
    }
  });
}
项目:tools-idea    文件:CommittedChangesPanel.java   
private void refreshChangesFromLocation() {
  myBrowser.reset();

  myInLoad = true;
  myBrowser.setLoading(true);
  ProgressManager.getInstance().run(new Task.Backgroundable(myProject, "Loading changes", true, BackgroundFromStartOption.getInstance()) {

    public void run(@NotNull final ProgressIndicator indicator) {
      try {
        final AsynchConsumer<List<CommittedChangeList>> appender = new AsynchConsumer<List<CommittedChangeList>>() {
          public void finished() {
          }

          public void consume(final List<CommittedChangeList> list) {
            new AbstractCalledLater(myProject, ModalityState.stateForComponent(myBrowser)) {
              public void run() {
                myBrowser.append(list);
              }
            }.callMe();
          }
        };
        final BufferedListConsumer<CommittedChangeList> bufferedListConsumer = new BufferedListConsumer<CommittedChangeList>(30, appender,-1);

        myProvider.loadCommittedChanges(mySettings, myLocation, myMaxCount, new AsynchConsumer<CommittedChangeList>() {
          public void finished() {
            bufferedListConsumer.flush();
          }
          public void consume(CommittedChangeList committedChangeList) {
            if (myDisposed) {
              indicator.cancel();
            }
            ProgressManager.checkCanceled();
            bufferedListConsumer.consumeOne(committedChangeList);
          }
        });
      }
      catch (final VcsException e) {
        LOG.info(e);
        WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {
          public void run() {
            Messages.showErrorDialog(myProject, "Error refreshing view: " + StringUtil.join(e.getMessages(), "\n"), "Committed Changes");
          }
        }, null, myProject);
      } finally {
        myInLoad = false;
        myBrowser.setLoading(false);
      }
    }
  });
}
项目:tools-idea    文件:LoaderAndRefresherImpl.java   
public LoaderAndRefresherImpl(final Ticket ticket,
                              Collection<ChangesFilter.Filter> filters,
                              Mediator mediator,
                              Collection<String> startingPoints,
                              DetailsCache detailsCache,
                              Project project,
                              MyRootHolder rootHolder,
                              final UsersIndex usersIndex,
                              final LoadGrowthController.ID id, boolean haveStructureFilter, boolean topoOrder, boolean haveDisordering) {
  myRootHolder = rootHolder;
  myUsersIndex = usersIndex;
  myId = id;
  myHaveStructureFilter = haveStructureFilter;
  myTopoOrder = topoOrder;
  myLoadParents = ! haveDisordering;
  myTicket = ticket;
  myFilters = filters;
  myMediator = mediator;
  myStartingPoints = startingPoints;
  myDetailsCache = detailsCache;
  myStepType = StepType.CONTINUE;
  myProject = project;
  myProgressAnalog = new Getter<Boolean>() {
    @Override
    public Boolean get() {
      return isInterrupted();
    }
  };
  myLowLevelAccess = new LowLevelAccessImpl(myProject, myRootHolder.getRoot());

  myRealConsumer = new Consumer<List<CommitHashPlusParents>>() {
    @Override
    public void consume(final List<CommitHashPlusParents> list) {
      if (isInterrupted()) return;
      final List<CommitI> buffer = new ArrayList<CommitI>();
      final List<List<AbstractHash>> parents = myLoadParents ? new ArrayList<List<AbstractHash>>() : null;
      for (CommitHashPlusParents commitHashPlusParents : list) {
        CommitI commit = new Commit(commitHashPlusParents.getHash(), commitHashPlusParents.getTime(),
                                    myUsersIndex.put(commitHashPlusParents.getAuthorName()));
        commit = myRootHolder.decorateByRoot(commit);
        buffer.add(commit);
        if (myLoadParents) {
          parents.add(commitHashPlusParents.getParents());
        }
      }

      StepType stepType = myMediator.appendResult(myTicket, buffer, parents, myRootHolder.getRoot(), true);
      if (! StepType.FINISHED.equals(myStepType)) {
        myStepType = stepType;
      }
    }
  };
  myBufferConsumer = new BufferedListConsumer<CommitHashPlusParents>(15, myRealConsumer, 400);
  myRepeatingLoadConsumer = new RepeatingLoadConsumer<CommitHashPlusParents>(myProject, myBufferConsumer.asConsumer());
}
项目:consulo    文件:CommittedChangesPanel.java   
private void refreshChangesFromLocation() {
  myBrowser.reset();

  myInLoad = true;
  myBrowser.setLoading(true);
  ProgressManager.getInstance().run(new Task.Backgroundable(myProject, "Loading changes", true, BackgroundFromStartOption.getInstance()) {

    @Override
    public void run(@Nonnull final ProgressIndicator indicator) {
      try {
        final AsynchConsumer<List<CommittedChangeList>> appender = new AsynchConsumer<List<CommittedChangeList>>() {
          @Override
          public void finished() {
          }

          @Override
          public void consume(final List<CommittedChangeList> list) {
            new AbstractCalledLater(myProject, ModalityState.stateForComponent(myBrowser)) {
              @Override
              public void run() {
                myBrowser.append(list);
              }
            }.callMe();
          }
        };
        final BufferedListConsumer<CommittedChangeList> bufferedListConsumer = new BufferedListConsumer<CommittedChangeList>(30, appender,-1);

        myProvider.loadCommittedChanges(mySettings, myLocation, myMaxCount, new AsynchConsumer<CommittedChangeList>() {
          @Override
          public void finished() {
            bufferedListConsumer.flush();
          }
          @Override
          public void consume(CommittedChangeList committedChangeList) {
            if (myDisposed) {
              indicator.cancel();
            }
            ProgressManager.checkCanceled();
            bufferedListConsumer.consumeOne(committedChangeList);
          }
        });
      }
      catch (final VcsException e) {
        LOG.info(e);
        WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {
          @Override
          public void run() {
            Messages.showErrorDialog(myProject, "Error refreshing view: " + StringUtil.join(e.getMessages(), "\n"), "Committed Changes");
          }
        }, null, myProject);
      } finally {
        myInLoad = false;
        myBrowser.setLoading(false);
      }
    }
  });
}