Skip to content

Commit 35e1d2b

Browse files
sduskischingor13
authored andcommitted
---
yaml --- r: 34687 b: refs/heads/autosynth-texttospeech c: cef6cd0 h: refs/heads/master i: 34685: a485b40 34683: 00eb016 34679: 66cd0d9 34671: 22f4456 34655: 6f9597e 34623: 581a3b9 34559: abe1b95
1 parent c20497a commit 35e1d2b

2 files changed

Lines changed: 25 additions & 25 deletions

File tree

  • branches/autosynth-texttospeech/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
@@ -140,7 +140,7 @@ refs/heads/autosynth-scheduler: a3de6480746d1cd586ca8b9d75c55a636f371539
140140
refs/heads/autosynth-spanner: d963fe4368e79cf6abae5d511785e8ced8ac57f4
141141
refs/heads/autosynth-speech: c563dcd420cce0a37c39b1b9c24be1b9ba604dc7
142142
refs/heads/autosynth-tasks: 25d1eafe8cb66b00e3dad765dac74a5b45b83e63
143-
refs/heads/autosynth-texttospeech: 7f889b23478560861361715a9021c5477361f33e
143+
refs/heads/autosynth-texttospeech: cef6cd03f92eb9ac491fcb97639769fd06cde841
144144
refs/heads/autosynth-trace: c94eef6e4d9c6fd24888216e28ca7271959c1cf0
145145
refs/heads/autosynth-websecurityscanner: fa561b356aabcd92d415ae8dc88fd8d87dbc5b23
146146
refs/heads/bigquerystorage: 06db74d123d7f8a3ef48755c2fcabed09faf8e64

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -222,14 +222,7 @@ && hasBatchingBytes()
222222
}
223223
}
224224
// Setup the next duration based delivery alarm if there are messages batched.
225-
if (!messagesBatch.isEmpty()) {
226-
setupDurationBasedPublishAlarm();
227-
} else if (currentAlarmFuture != null) {
228-
logger.log(Level.FINER, "Cancelling alarm, no more messages");
229-
if (activeAlarm.getAndSet(false)) {
230-
currentAlarmFuture.cancel(false);
231-
}
232-
}
225+
setupAlarm();
233226
} finally {
234227
messagesBatchLock.unlock();
235228
}
@@ -266,22 +259,29 @@ public void run() {
266259
return publishResult;
267260
}
268261

269-
private void setupDurationBasedPublishAlarm() {
270-
if (!activeAlarm.getAndSet(true)) {
271-
long delayThresholdMs = getBatchingSettings().getDelayThreshold().toMillis();
272-
logger.log(Level.FINER, "Setting up alarm for the next {0} ms.", delayThresholdMs);
273-
currentAlarmFuture =
274-
executor.schedule(
275-
new Runnable() {
276-
@Override
277-
public void run() {
278-
logger.log(Level.FINER, "Sending messages based on schedule.");
279-
activeAlarm.getAndSet(false);
280-
publishAllOutstanding();
281-
}
282-
},
283-
delayThresholdMs,
284-
TimeUnit.MILLISECONDS);
262+
private void setupAlarm() {
263+
if (!messagesBatch.isEmpty()) {
264+
if (!activeAlarm.getAndSet(true)) {
265+
long delayThresholdMs = getBatchingSettings().getDelayThreshold().toMillis();
266+
logger.log(Level.FINER, "Setting up alarm for the next {0} ms.", delayThresholdMs);
267+
currentAlarmFuture =
268+
executor.schedule(
269+
new Runnable() {
270+
@Override
271+
public void run() {
272+
logger.log(Level.FINER, "Sending messages based on schedule.");
273+
activeAlarm.getAndSet(false);
274+
publishAllOutstanding();
275+
}
276+
},
277+
delayThresholdMs,
278+
TimeUnit.MILLISECONDS);
279+
}
280+
} else if (currentAlarmFuture != null) {
281+
logger.log(Level.FINER, "Cancelling alarm, no more messages");
282+
if (activeAlarm.getAndSet(false)) {
283+
currentAlarmFuture.cancel(false);
284+
}
285285
}
286286
}
287287

0 commit comments

Comments
 (0)