From 0b1ec1e50be7caa8eff7fe8f1b5647aaa4651ead Mon Sep 17 00:00:00 2001 From: Jon Chambers Date: Fri, 16 Aug 2024 16:45:33 -0400 Subject: [PATCH] Make push notification senders available via `CommandDependencies` --- .../textsecuregcm/workers/CommandDependencies.java | 5 +++++ ...uledApnPushNotificationSenderServiceCommand.java | 13 +------------ ...FinishPushNotificationExperimentCommandTest.java | 2 ++ ...NotifyIdleDevicesWithoutMessagesCommandTest.java | 2 ++ .../StartPushNotificationExperimentCommandTest.java | 2 ++ 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/workers/CommandDependencies.java b/service/src/main/java/org/whispersystems/textsecuregcm/workers/CommandDependencies.java index e50d6e10a..d6fdcdddc 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/workers/CommandDependencies.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/workers/CommandDependencies.java @@ -75,6 +75,8 @@ record CommandDependencies( MessagesManager messagesManager, ClientPresenceManager clientPresenceManager, KeysManager keysManager, + APNSender apnSender, + FcmSender fcmSender, PushNotificationManager pushNotificationManager, PushNotificationExperimentSamples pushNotificationExperimentSamples, FaultTolerantRedisCluster cacheCluster, @@ -254,6 +256,7 @@ static CommandDependencies build( configuration.getDynamoDbTables().getPushNotificationExperimentSamples().getTableName(), Clock.systemUTC()); + environment.lifecycle().manage(apnSender); environment.lifecycle().manage(messagesCache); environment.lifecycle().manage(clientPresenceManager); environment.lifecycle().manage(new ManagedAwsCrt()); @@ -266,6 +269,8 @@ static CommandDependencies build( messagesManager, clientPresenceManager, keys, + apnSender, + fcmSender, pushNotificationManager, pushNotificationExperimentSamples, cacheCluster, diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/workers/ScheduledApnPushNotificationSenderServiceCommand.java b/service/src/main/java/org/whispersystems/textsecuregcm/workers/ScheduledApnPushNotificationSenderServiceCommand.java index a90cb6ab5..8f896b2fc 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/workers/ScheduledApnPushNotificationSenderServiceCommand.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/workers/ScheduledApnPushNotificationSenderServiceCommand.java @@ -5,20 +5,15 @@ package org.whispersystems.textsecuregcm.workers; -import static com.codahale.metrics.MetricRegistry.name; - import io.dropwizard.core.Application; import io.dropwizard.core.cli.ServerCommand; import io.dropwizard.core.server.DefaultServerFactory; import io.dropwizard.core.setup.Environment; import io.dropwizard.jetty.HttpsConnectorFactory; -import java.util.concurrent.ExecutorService; import net.sourceforge.argparse4j.inf.Namespace; import net.sourceforge.argparse4j.inf.Subparser; import org.whispersystems.textsecuregcm.WhisperServerConfiguration; import org.whispersystems.textsecuregcm.metrics.MetricsUtil; -import org.whispersystems.textsecuregcm.push.APNSender; -import org.whispersystems.textsecuregcm.push.FcmSender; import org.whispersystems.textsecuregcm.push.PushNotificationScheduler; import org.whispersystems.textsecuregcm.util.logging.UncaughtExceptionHandler; @@ -73,15 +68,9 @@ protected void run(Environment environment, Namespace namespace, WhisperServerCo }); } - final ExecutorService pushNotificationSenderExecutor = environment.lifecycle().executorService(name(getClass(), "apnSender-%d")) - .maxThreads(1).minThreads(1).build(); - - final APNSender apnSender = new APNSender(pushNotificationSenderExecutor, configuration.getApnConfiguration()); - final FcmSender fcmSender = new FcmSender(pushNotificationSenderExecutor, configuration.getFcmConfiguration().credentials().value()); final PushNotificationScheduler pushNotificationScheduler = new PushNotificationScheduler( - deps.pushSchedulerCluster(), apnSender, fcmSender, deps.accountsManager(), namespace.getInt(WORKER_COUNT), namespace.getInt(MAX_CONCURRENCY)); + deps.pushSchedulerCluster(), deps.apnSender(), deps.fcmSender(), deps.accountsManager(), namespace.getInt(WORKER_COUNT), namespace.getInt(MAX_CONCURRENCY)); - environment.lifecycle().manage(apnSender); environment.lifecycle().manage(pushNotificationScheduler); MetricsUtil.registerSystemResourceMetrics(environment); diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/workers/FinishPushNotificationExperimentCommandTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/workers/FinishPushNotificationExperimentCommandTest.java index 9a67bce4d..65f32351d 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/workers/FinishPushNotificationExperimentCommandTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/workers/FinishPushNotificationExperimentCommandTest.java @@ -72,6 +72,8 @@ void setUp() { null, null, null, + null, + null, pushNotificationExperimentSamples, null, null, diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/workers/NotifyIdleDevicesWithoutMessagesCommandTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/workers/NotifyIdleDevicesWithoutMessagesCommandTest.java index 59aa5b4ad..853217ecb 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/workers/NotifyIdleDevicesWithoutMessagesCommandTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/workers/NotifyIdleDevicesWithoutMessagesCommandTest.java @@ -65,6 +65,8 @@ private TestNotifyIdleDevicesWithoutMessagesCommand(final MessagesManager messag null, null, null, + null, + null, null); this.idleDeviceNotificationScheduler = idleDeviceNotificationScheduler; diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/workers/StartPushNotificationExperimentCommandTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/workers/StartPushNotificationExperimentCommandTest.java index 20ed2ecbb..3b54fc52b 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/workers/StartPushNotificationExperimentCommandTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/workers/StartPushNotificationExperimentCommandTest.java @@ -61,6 +61,8 @@ public TestStartPushNotificationExperimentCommand( null, null, null, + null, + null, pushNotificationExperimentSamples, null, null,