public List next()

in business-model/src/main/java/com/google/cloud/orderbook/QueuedProducer.java [135:178]


  public List<T> next() {

    // If finalised, nothing to return
    if (state.equals(State.FINALISED)) {
      return Arrays.asList();
    }

    // Get next item to execute -- if nothing is there,
    // we need to stop and return null.
    QueuedItem<T> nextWork = this.que.poll();
    if (nextWork == null) {

      // Calculate the shutdown events and return them
      // as there is no more normal work to do.
      ArrayList<T> shutdownEvents = new ArrayList<T>();
      for (Callable<List<T>> task : atShutdownWork) {
        try {
          shutdownEvents.addAll(task.call());
        } catch (Exception e) {
          System.out.println("Exception: " + e.toString());
        }
      }

      // Now finalised - no more events ever!
      state = State.FINALISED;

      return shutdownEvents;
    }

    // Execute the work
    // On exception, return empty list to keep going.
    Callable<List<T>> workTask = nextWork.work;
    lastTick = nextWork.tick;
    List<T> results = null;
    try {
      results = workTask.call();
    } catch (Exception e) {
      System.out.println("Exception: " + e.toString());
      return Arrays.asList();
    }

    return results;

  }