Skip to content

Commit 7058ec0

Browse files
dpcollins-googlesduskis
authored andcommitted
---
yaml --- r: 18935 b: refs/heads/autosynth-vision c: 77fb0ca h: refs/heads/master i: 18933: 5832589 18931: 2b2cc5d 18927: a5d646f
1 parent d570d96 commit 7058ec0

2 files changed

Lines changed: 42 additions & 40 deletions

File tree

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ refs/heads/autosynth-container: f6384095f50b31bfc8208542a49181e158d3681c
117117
refs/heads/autosynth-monitoring: 832528c131ac32b115fd7a369701d9e6e4ec62e5
118118
refs/heads/autosynth-pubsub: 7a327eaed5fb2a5d6c1691feb73c3e0194dd805e
119119
refs/heads/autosynth-video-intelligence: 53ca56e5d077bf67065b730f3fe621f40689fb4c
120-
refs/heads/autosynth-vision: aa5f27188cc55ebb5773b6597c6c49c965a40add
120+
refs/heads/autosynth-vision: 77fb0ca8e507c38b4b559836b5c55576ef50e0c9
121121
refs/heads/spanner: b01127f885b4611bf1852abb0ce481eeb7fcc131
122122
refs/tags/v0.68.0: 9cc799fcf68c82ab431d425fefa58ef615ce8e5b
123123
refs/tags/v0.69.0: 78f67a29e8b9c46ba01de566a2eae0fd1c03edea

branches/autosynth-vision/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/MessageDispatcher.java

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -402,51 +402,53 @@ public void processOutstandingBatches() {
402402
batchCallback = nextBatch.doneCallback;
403403
}
404404
}
405-
406-
final PubsubMessage message = outstandingMessage.receivedMessage().getMessage();
407-
final AckHandler ackHandler = outstandingMessage.ackHandler();
408-
final SettableApiFuture<AckReply> response = SettableApiFuture.create();
409-
final AckReplyConsumer consumer =
410-
new AckReplyConsumer() {
411-
@Override
412-
public void ack() {
413-
response.set(AckReply.ACK);
414-
}
415-
416-
@Override
417-
public void nack() {
418-
response.set(AckReply.NACK);
419-
}
420-
};
421-
ApiFutures.addCallback(response, ackHandler, MoreExecutors.directExecutor());
422-
executor.execute(
423-
new Runnable() {
424-
@Override
425-
public void run() {
426-
try {
427-
if (ackHandler
428-
.totalExpiration
429-
.plusSeconds(messageDeadlineSeconds.get())
430-
.isBefore(now())) {
431-
// Message expired while waiting. We don't extend these messages anymore,
432-
// so it was probably sent to someone else. Don't work on it.
433-
// Don't nack it either, because we'd be nacking someone else's message.
434-
ackHandler.forget();
435-
return;
436-
}
437-
438-
receiver.receiveMessage(message, consumer);
439-
} catch (Exception e) {
440-
response.setException(e);
441-
}
442-
}
443-
});
405+
processOutstandingMessage(
406+
outstandingMessage.receivedMessage.getMessage(), outstandingMessage.ackHandler);
444407
if (batchDone) {
445408
batchCallback.run();
446409
}
447410
}
448411
}
449412

413+
private void processOutstandingMessage(final PubsubMessage message, final AckHandler ackHandler) {
414+
final SettableApiFuture<AckReply> response = SettableApiFuture.create();
415+
final AckReplyConsumer consumer =
416+
new AckReplyConsumer() {
417+
@Override
418+
public void ack() {
419+
response.set(AckReply.ACK);
420+
}
421+
422+
@Override
423+
public void nack() {
424+
response.set(AckReply.NACK);
425+
}
426+
};
427+
ApiFutures.addCallback(response, ackHandler, MoreExecutors.directExecutor());
428+
executor.execute(
429+
new Runnable() {
430+
@Override
431+
public void run() {
432+
try {
433+
if (ackHandler
434+
.totalExpiration
435+
.plusSeconds(messageDeadlineSeconds.get())
436+
.isBefore(now())) {
437+
// Message expired while waiting. We don't extend these messages anymore,
438+
// so it was probably sent to someone else. Don't work on it.
439+
// Don't nack it either, because we'd be nacking someone else's message.
440+
ackHandler.forget();
441+
return;
442+
}
443+
444+
receiver.receiveMessage(message, consumer);
445+
} catch (Exception e) {
446+
response.setException(e);
447+
}
448+
}
449+
});
450+
}
451+
450452
/** Compute the ideal deadline, set subsequent modacks to this deadline, and return it. */
451453
@InternalApi
452454
int computeDeadlineSeconds() {

0 commit comments

Comments
 (0)