예제 #1
0
  @Override
  // @Stateless
  public ListenableFuture<Folder> open(String folder, boolean readWrite) {
    Preconditions.checkState(
        mailClientHandler.isLoggedIn(), "Can't execute command because client is not logged in");
    Preconditions.checkState(
        !mailClientHandler.idleRequested.get(),
        "Can't execute command while idling (are you watching a folder?)");

    final SettableFuture<Folder> valueFuture = SettableFuture.create();
    final SettableFuture<Folder> externalFuture = SettableFuture.create();

    valueFuture.addListener(
        new Runnable() {
          @Override
          public void run() {
            try {
              // We do this to enforce a happens-before ordering between the time a folder is
              // saved to currentFolder and a listener registered by the user may fire in a parallel
              // executor service.
              currentFolder = valueFuture.get();
              externalFuture.set(currentFolder);
            } catch (InterruptedException e) {
              log.error("Interrupted while attempting to open a folder", e);
            } catch (ExecutionException e) {
              log.error("Execution exception while attempting to open a folder", e);
              externalFuture.setException(e);
            }
          }
        },
        workerPool);

    String args = '"' + folder + "\"";
    send(readWrite ? Command.FOLDER_OPEN : Command.FOLDER_EXAMINE, args, valueFuture);

    return externalFuture;
  }
예제 #2
0
 @Override
 public void addListener(Runnable runnable, Executor executor) {
   settableFuture.addListener(runnable, executor);
 }