/** * Acks the provided {@code ackIds} back to Pubsub, blocking until all of the messages are * ACKed. * * <p>CAUTION: May be invoked from a separate thread. * * <p>CAUTION: Retains {@code ackIds}. */ void ackBatch(List<String> ackIds) throws IOException { pubsubClient.get().acknowledge(subscription, ackIds); ackedIds.add(ackIds); }
private String pollForResultForDuration( SubscriptionPath signalSubscriptionPath, Duration duration) throws IOException { List<PubsubClient.IncomingMessage> signal = null; DateTime endPolling = DateTime.now().plus(duration.getMillis()); do { try { signal = pubsub.pull(DateTime.now().getMillis(), signalSubscriptionPath, 1, false); pubsub.acknowledge( signalSubscriptionPath, signal.stream().map(m -> m.ackId).collect(toList())); break; } catch (StatusRuntimeException e) { if (!Status.DEADLINE_EXCEEDED.equals(e.getStatus())) { LOG.warn( "(Will retry) Error while polling {} for signal: {}", signalSubscriptionPath, e.getStatus()); } sleep(500); } } while (DateTime.now().isBefore(endPolling)); if (signal == null) { throw new AssertionError( String.format( "Did not receive signal on %s in %ss", signalSubscriptionPath, duration.getStandardSeconds())); } return new String(signal.get(0).elementBytes, UTF_8); }