Skip to content

Commit e520e18

Browse files
authored
---
yaml --- r: 33665 b: refs/heads/autosynth-redis c: 67668c1 h: refs/heads/master i: 33663: ce3d408
1 parent 732052c commit e520e18

2 files changed

Lines changed: 23 additions & 23 deletions

File tree

  • branches/autosynth-redis/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ refs/heads/autosynth-iot: 044be280805a59e06d09658688c9ee474a9815ad
135135
refs/heads/autosynth-kms: d31449d6621a50fb16a4bef4f30f0f3051d27d7c
136136
refs/heads/autosynth-language: 6130869312f99a1e7d3aa0485759172a23333cc5
137137
refs/heads/autosynth-os-login: 49028d40ac477fca5f948cc5a3ce7422729fdb67
138-
refs/heads/autosynth-redis: 652794a69a167d6223e9abdd512066c21835072d
138+
refs/heads/autosynth-redis: 67668c1411169338374b050eae50ed650e318c54
139139
refs/heads/autosynth-scheduler: 57f9fdb1e7de30c85f4ec7198931a07f50603e55
140140
refs/heads/autosynth-spanner: de02ca32edea133b68b51052e325359a3704b5d2
141141
refs/heads/autosynth-speech: 64692f6db11364f663921be02c08072b966b6e7b

branches/autosynth-redis/google-cloud-clients/google-cloud-pubsub/src/main/java/com/google/cloud/pubsub/v1/Publisher.java

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,7 @@ public String getTopicNameString() {
192192
* @return the message ID wrapped in a future.
193193
*/
194194
public ApiFuture<String> publish(PubsubMessage message) {
195-
if (shutdown.get()) {
196-
throw new IllegalStateException("Cannot publish on a shut-down publisher.");
197-
}
195+
Preconditions.checkState(!shutdown.get(), "Cannot publish on a shut-down publisher.");
198196

199197
final OutstandingPublish outstandingPublish =
200198
new OutstandingPublish(messageTransform.apply(message));
@@ -288,23 +286,15 @@ private void publishOutstandingBatch(final OutstandingBatch outstandingBatch) {
288286
public void onSuccess(PublishResponse result) {
289287
try {
290288
if (result.getMessageIdsCount() != outstandingBatch.size()) {
291-
Throwable t =
289+
outstandingBatch.onFailure(
292290
new IllegalStateException(
293291
String.format(
294292
"The publish result count %s does not match "
295293
+ "the expected %s results. Please contact Cloud Pub/Sub support "
296294
+ "if this frequently occurs",
297-
result.getMessageIdsCount(), outstandingBatch.size()));
298-
for (OutstandingPublish oustandingMessage : outstandingBatch.outstandingPublishes) {
299-
oustandingMessage.publishResult.setException(t);
300-
}
301-
return;
302-
}
303-
304-
Iterator<OutstandingPublish> messagesResultsIt =
305-
outstandingBatch.outstandingPublishes.iterator();
306-
for (String messageId : result.getMessageIdsList()) {
307-
messagesResultsIt.next().publishResult.set(messageId);
295+
result.getMessageIdsCount(), outstandingBatch.size())));
296+
} else {
297+
outstandingBatch.onSuccess(result.getMessageIdsList());
308298
}
309299
} finally {
310300
messagesWaiter.incrementPendingMessages(-outstandingBatch.size());
@@ -314,9 +304,7 @@ public void onSuccess(PublishResponse result) {
314304
@Override
315305
public void onFailure(Throwable t) {
316306
try {
317-
for (OutstandingPublish outstandingPublish : outstandingBatch.outstandingPublishes) {
318-
outstandingPublish.publishResult.setException(t);
319-
}
307+
outstandingBatch.onFailure(t);
320308
} finally {
321309
messagesWaiter.incrementPendingMessages(-outstandingBatch.size());
322310
}
@@ -350,6 +338,19 @@ private List<PubsubMessage> getMessages() {
350338
}
351339
return results;
352340
}
341+
342+
private void onFailure(Throwable t) {
343+
for (OutstandingPublish outstandingPublish : outstandingPublishes) {
344+
outstandingPublish.publishResult.setException(t);
345+
}
346+
}
347+
348+
private void onSuccess(Iterable<String> results) {
349+
Iterator<OutstandingPublish> messagesResultsIt = outstandingPublishes.iterator();
350+
for (String messageId : results) {
351+
messagesResultsIt.next().publishResult.set(messageId);
352+
}
353+
}
353354
}
354355

355356
private static final class OutstandingPublish {
@@ -376,10 +377,9 @@ public BatchingSettings getBatchingSettings() {
376377
* should be invoked prior to deleting the {@link Publisher} object in order to ensure that no
377378
* pending messages are lost.
378379
*/
379-
public void shutdown() throws Exception {
380-
if (shutdown.getAndSet(true)) {
381-
throw new IllegalStateException("Cannot shut down a publisher already shut-down.");
382-
}
380+
public void shutdown() {
381+
Preconditions.checkState(
382+
!shutdown.getAndSet(true), "Cannot shut down a publisher already shut-down.");
383383
if (currentAlarmFuture != null && activeAlarm.getAndSet(false)) {
384384
currentAlarmFuture.cancel(false);
385385
}

0 commit comments

Comments
 (0)