Ejemplo n.º 1
0
  private static <T> Action1<Notification<? super T>> debug(String desc) {

    Function<String, Action1<Notification<? super T>>> debugger =
        (prefix) -> {
          AtomicReference<String> nextOffset = new AtomicReference<String>(">");
          return (Notification<? super T> notif) -> {
            if (notif == null) {
              logger.error("null notification.");
            }

            switch (notif.getKind()) {
              case OnNext:
                {
                  logger.printf(Level.INFO, "%s %s %s", prefix, nextOffset.get(), notif.getValue());
                  nextOffset.getAndUpdate(str -> str + "-");
                  break;
                }
              case OnError:
                {
                  logger.printf(Level.ERROR, "%s %s", prefix, notif.getThrowable().getMessage());
                  break;
                }
              case OnCompleted:
                {
                  logger.printf(Level.ERROR, "%s %s", prefix, "completed");
                  break;
                }
              default:
                logger.error("Unsupport operation");
            }
          };
        };
    return debugger.apply(desc);
  }