for (Either<VerifiedDataset, ExecutionException> either: futures) { if (either instanceof Either.Right) { ExecutionException exc = ((Either.Right<VerifiedDataset, ExecutionException>) either).getRight(); DatasetVerificationException dve = (DatasetVerificationException) exc.getCause(); failedDatasets.add(dve.dataset);
for (Either<VerifiedDataset, ExecutionException> either: futures) { if (either instanceof Either.Right) { ExecutionException exc = ((Either.Right<VerifiedDataset, ExecutionException>) either).getRight(); DatasetVerificationException dve = (DatasetVerificationException) exc.getCause(); failedDatasets.add(dve.dataset);
Either<T, ExecutionException> nextResult = it.next(); if (nextResult instanceof Either.Right) { exc = ((Either.Right<T, ExecutionException>) nextResult).getRight(); actualLogger.error("Iterator executor failure.", exc); printed++;
@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.removedSpecs.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); } }
/** * 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; } } } }
private TransportConfigCallback buildTransportConfigCallback() { if (this.providerSessionFactoryEither instanceof Either.Left) return null; SshSessionFactory sshSessionFactory = ((Either.Right<CredentialsProvider, SshSessionFactory>) this.providerSessionFactoryEither).getRight(); return transport -> { SshTransport sshTransport = (SshTransport) transport; sshTransport.setSshSessionFactory(sshSessionFactory); }; } }
/** * 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); }
Either<T, ExecutionException> nextResult = it.next(); if (nextResult instanceof Either.Right) { exc = ((Either.Right<T, ExecutionException>) nextResult).getRight(); actualLogger.error("Iterator executor failure.", exc); printed++;
/** * 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; } } } }
@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.removedSpecs.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); } }
@Override public T call() throws Exception { this.queue.put(false); if (this.toReturn instanceof Either.Left) { return ((Either.Left<T, Exception>) this.toReturn).getLeft(); } else { throw ((Either.Right<T, Exception>) this.toReturn).getRight(); } } }
/** * 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); }
private TransportConfigCallback buildTransportConfigCallback() { if (this.providerSessionFactoryEither instanceof Either.Left) return null; SshSessionFactory sshSessionFactory = ((Either.Right<CredentialsProvider, SshSessionFactory>) this.providerSessionFactoryEither).getRight(); return transport -> { SshTransport sshTransport = (SshTransport) transport; sshTransport.setSshSessionFactory(sshSessionFactory); }; } }