/** * Log failures in the output of {@link #executeAndGetResults()}. * @param results output of {@link #executeAndGetResults()} * @param useLogger logger to log the messages into. * @param atMost will log at most this many errors. */ public static <T> void logFailures(List<Either<T, ExecutionException>> results, Logger useLogger, int atMost) { Logger actualLogger = useLogger == null ? log : useLogger; Iterator<Either<T, ExecutionException>> it = results.iterator(); int printed = 0; while (it.hasNext()) { Either<T, ExecutionException> nextResult = it.next(); if (nextResult instanceof Either.Right) { ExecutionException exc = ((Either.Right<T, ExecutionException>) nextResult).getRight(); actualLogger.error("Iterator executor failure.", exc); printed++; if (printed >= atMost) { return; } } } }
for (Either<VerifiedDataset, ExecutionException> either: futures) { if (either instanceof Either.Right) { ExecutionException exc = ((Either.Right<VerifiedDataset, ExecutionException>) either).getRight(); DatasetVerificationException dve = (DatasetVerificationException) exc.getCause(); log.error ("Verification raised an exception:" + ExceptionUtils.getStackTrace(dve.cause));
@Override protected void processMessage(MessageAndMetadata<byte[], byte[]> message) { try { Collection<Either<JobSpec, URI>> parsedCollection = parseJobSpec(message.message()); for (Either<JobSpec, URI> parsedMessage : parsedCollection) { if (parsedMessage instanceof Either.Left) { this.newSpecs.inc(); this.jobCatalog.put(((Either.Left<JobSpec, URI>) parsedMessage).getLeft()); } else if (parsedMessage instanceof Either.Right) { this.remmovedSpecs.inc(); this.jobCatalog.remove(((Either.Right<JobSpec, URI>) parsedMessage).getRight()); } } } catch (IOException ioe) { String messageStr = new String(message.message(), Charsets.UTF_8); log.error(String.format("Failed to parse kafka message with offset %d: %s.", message.offset(), messageStr), ioe); } }
/** * Create an instance of {@link Either} with value of type {@link T}. * @param right value of this instance. * @return an instance of {@link Right}. */ public static <S, T> Either<S, T> right(T right) { return new Right<>(right); }