Skip to content

Commit be9e869

Browse files
authored
Merge branch 'master' into je-http2-default
2 parents 11aab96 + ce8e7fd commit be9e869

File tree

5 files changed

+52
-35
lines changed

5 files changed

+52
-35
lines changed

.github/workflows/nightly.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
# Attach the packaged artifacts to the workflow output. These can be manually
4949
# downloaded for later inspection if necessary.
5050
- name: Archive artifacts
51-
uses: actions/upload-artifact@v1
51+
uses: actions/upload-artifact@v4
5252
with:
5353
name: dist
5454
path: dist

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ jobs:
5959
# Attach the packaged artifacts to the workflow output. These can be manually
6060
# downloaded for later inspection if necessary.
6161
- name: Archive artifacts
62-
uses: actions/upload-artifact@v1
62+
uses: actions/upload-artifact@v4
6363
with:
6464
name: dist
6565
path: dist

pom.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6060
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
6161
<skipUTs>${skipTests}</skipUTs>
62-
<netty.version>4.1.110.Final</netty.version>
62+
<netty.version>4.1.113.Final</netty.version>
6363
</properties>
6464

6565
<scm>
@@ -89,7 +89,7 @@
8989
<plugin>
9090
<!-- Generate API docs using Doclava for the developer site -->
9191
<artifactId>maven-javadoc-plugin</artifactId>
92-
<version>3.7.0</version>
92+
<version>3.10.0</version>
9393
<executions>
9494
<execution>
9595
<phase>site</phase>
@@ -157,7 +157,7 @@
157157
<plugins>
158158
<plugin>
159159
<artifactId>maven-gpg-plugin</artifactId>
160-
<version>3.2.4</version>
160+
<version>3.2.5</version>
161161
<executions>
162162
<execution>
163163
<id>sign-artifacts</id>
@@ -280,7 +280,7 @@
280280
<!-- Test Phase -->
281281
<plugin>
282282
<artifactId>maven-surefire-plugin</artifactId>
283-
<version>3.2.5</version>
283+
<version>3.5.0</version>
284284
<configuration>
285285
<skipTests>${skipUTs}</skipTests>
286286
</configuration>
@@ -301,7 +301,7 @@
301301
</plugin>
302302
<plugin>
303303
<artifactId>maven-javadoc-plugin</artifactId>
304-
<version>3.7.0</version>
304+
<version>3.10.0</version>
305305
<executions>
306306
<execution>
307307
<id>attach-javadocs</id>
@@ -337,7 +337,7 @@
337337
<!-- Verify Phase -->
338338
<plugin>
339339
<artifactId>maven-failsafe-plugin</artifactId>
340-
<version>3.2.5</version>
340+
<version>3.5.0</version>
341341
<executions>
342342
<execution>
343343
<goals>
@@ -367,7 +367,7 @@
367367
<plugins>
368368
<plugin>
369369
<artifactId>maven-project-info-reports-plugin</artifactId>
370-
<version>3.5.0</version>
370+
<version>3.7.0</version>
371371
<reportSets>
372372
<reportSet>
373373
<configuration>
@@ -385,14 +385,14 @@
385385
<dependency>
386386
<groupId>com.google.cloud</groupId>
387387
<artifactId>libraries-bom</artifactId>
388-
<version>26.39.0</version>
388+
<version>26.45.0</version>
389389
<type>pom</type>
390390
<scope>import</scope>
391391
</dependency>
392392
<dependency>
393393
<groupId>com.google.api-client</groupId>
394394
<artifactId>google-api-client-bom</artifactId>
395-
<version>2.5.1</version>
395+
<version>2.7.0</version>
396396
<type>pom</type>
397397
<scope>import</scope>
398398
</dependency>
@@ -438,7 +438,7 @@
438438
<dependency>
439439
<groupId>org.slf4j</groupId>
440440
<artifactId>slf4j-api</artifactId>
441-
<version>2.0.13</version>
441+
<version>2.0.16</version>
442442
</dependency>
443443
<dependency>
444444
<groupId>io.netty</groupId>
@@ -490,7 +490,7 @@
490490
<dependency>
491491
<groupId>org.hamcrest</groupId>
492492
<artifactId>hamcrest</artifactId>
493-
<version>2.2</version>
493+
<version>3.0</version>
494494
<scope>test</scope>
495495
</dependency>
496496
<dependency>

src/main/java/com/google/firebase/internal/FirebaseThreadManagers.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
import java.util.Set;
2424
import java.util.concurrent.ExecutorService;
2525
import java.util.concurrent.Executors;
26+
import java.util.concurrent.LinkedBlockingQueue;
2627
import java.util.concurrent.ThreadFactory;
28+
import java.util.concurrent.ThreadPoolExecutor;
29+
import java.util.concurrent.TimeUnit;
2730

2831
import org.slf4j.Logger;
2932
import org.slf4j.LoggerFactory;
@@ -84,7 +87,11 @@ private static class DefaultThreadManager extends GlobalThreadManager {
8487
protected ExecutorService doInit() {
8588
ThreadFactory threadFactory = FirebaseScheduledExecutor.getThreadFactoryWithName(
8689
getThreadFactory(), "firebase-default-%d");
87-
return Executors.newCachedThreadPool(threadFactory);
90+
91+
ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(100, 100, 60L,
92+
TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(), threadFactory);
93+
threadPoolExecutor.allowCoreThreadTimeOut(true);
94+
return threadPoolExecutor;
8895
}
8996

9097
@Override

src/main/java/com/google/firebase/messaging/FirebaseMessaging.java

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.google.common.base.Supplier;
2727
import com.google.common.base.Suppliers;
2828
import com.google.common.collect.ImmutableList;
29+
import com.google.common.util.concurrent.MoreExecutors;
2930
import com.google.firebase.ErrorCode;
3031
import com.google.firebase.FirebaseApp;
3132
import com.google.firebase.ImplFirebaseTrampolines;
@@ -159,7 +160,7 @@ protected String execute() throws FirebaseMessagingException {
159160
* no failures are only indicated by a {@link BatchResponse}.
160161
*/
161162
public BatchResponse sendEach(@NonNull List<Message> messages) throws FirebaseMessagingException {
162-
return sendEachOp(messages, false).call();
163+
return sendEach(messages, false);
163164
}
164165

165166

@@ -186,7 +187,11 @@ public BatchResponse sendEach(@NonNull List<Message> messages) throws FirebaseMe
186187
*/
187188
public BatchResponse sendEach(
188189
@NonNull List<Message> messages, boolean dryRun) throws FirebaseMessagingException {
189-
return sendEachOp(messages, dryRun).call();
190+
try {
191+
return sendEachOpAsync(messages, dryRun).get();
192+
} catch (InterruptedException | ExecutionException e) {
193+
throw new FirebaseMessagingException(ErrorCode.CANCELLED, SERVICE_ID);
194+
}
190195
}
191196

192197
/**
@@ -197,7 +202,7 @@ public BatchResponse sendEach(
197202
* the messages have been sent.
198203
*/
199204
public ApiFuture<BatchResponse> sendEachAsync(@NonNull List<Message> messages) {
200-
return sendEachOp(messages, false).callAsync(app);
205+
return sendEachOpAsync(messages, false);
201206
}
202207

203208
/**
@@ -209,32 +214,37 @@ public ApiFuture<BatchResponse> sendEachAsync(@NonNull List<Message> messages) {
209214
* the messages have been sent.
210215
*/
211216
public ApiFuture<BatchResponse> sendEachAsync(@NonNull List<Message> messages, boolean dryRun) {
212-
return sendEachOp(messages, dryRun).callAsync(app);
217+
return sendEachOpAsync(messages, dryRun);
213218
}
214219

215-
private CallableOperation<BatchResponse, FirebaseMessagingException> sendEachOp(
220+
// Returns an ApiFuture directly since this function is non-blocking. Individual child send
221+
// requests are still called async and run in background threads.
222+
private ApiFuture<BatchResponse> sendEachOpAsync(
216223
final List<Message> messages, final boolean dryRun) {
217224
final List<Message> immutableMessages = ImmutableList.copyOf(messages);
218225
checkArgument(!immutableMessages.isEmpty(), "messages list must not be empty");
219226
checkArgument(immutableMessages.size() <= 500,
220227
"messages list must not contain more than 500 elements");
221228

222-
return new CallableOperation<BatchResponse, FirebaseMessagingException>() {
223-
@Override
224-
protected BatchResponse execute() throws FirebaseMessagingException {
225-
List<ApiFuture<SendResponse>> list = new ArrayList<>();
226-
for (Message message : immutableMessages) {
227-
ApiFuture<SendResponse> messageId = sendOpForSendResponse(message, dryRun).callAsync(app);
228-
list.add(messageId);
229-
}
230-
try {
231-
List<SendResponse> responses = ApiFutures.allAsList(list).get();
232-
return new BatchResponseImpl(responses);
233-
} catch (InterruptedException | ExecutionException e) {
234-
throw new FirebaseMessagingException(ErrorCode.CANCELLED, SERVICE_ID);
235-
}
236-
}
237-
};
229+
List<ApiFuture<SendResponse>> list = new ArrayList<>();
230+
for (Message message : immutableMessages) {
231+
// Make async send calls per message
232+
ApiFuture<SendResponse> messageId = sendOpForSendResponse(message, dryRun).callAsync(app);
233+
list.add(messageId);
234+
}
235+
236+
// Gather all futures and combine into a list
237+
ApiFuture<List<SendResponse>> responsesFuture = ApiFutures.allAsList(list);
238+
239+
// Chain this future to wrap the eventual responses in a BatchResponse without blocking
240+
// the main thread. This uses the current thread to execute, but since the transformation
241+
// function is non-blocking the transformation itself is also non-blocking.
242+
return ApiFutures.transform(
243+
responsesFuture,
244+
(responses) -> {
245+
return new BatchResponseImpl(responses);
246+
},
247+
MoreExecutors.directExecutor());
238248
}
239249

240250
private CallableOperation<SendResponse, FirebaseMessagingException> sendOpForSendResponse(

0 commit comments

Comments
 (0)