diff --git a/pom.xml b/pom.xml
index 00f35fea5..621cf1717 100644
--- a/pom.xml
+++ b/pom.xml
@@ -109,6 +109,11 @@
pushy
0.9.3
+
+ com.relayrides
+ pushy-dropwizard-metrics-listener
+ 0.9.3
+
org.whispersystems
gcm-sender-async
diff --git a/src/main/java/org/whispersystems/textsecuregcm/push/RetryingApnsClient.java b/src/main/java/org/whispersystems/textsecuregcm/push/RetryingApnsClient.java
index 5b1930dee..7a8839470 100644
--- a/src/main/java/org/whispersystems/textsecuregcm/push/RetryingApnsClient.java
+++ b/src/main/java/org/whispersystems/textsecuregcm/push/RetryingApnsClient.java
@@ -1,5 +1,8 @@
package org.whispersystems.textsecuregcm.push;
+import com.codahale.metrics.Metric;
+import com.codahale.metrics.MetricRegistry;
+import com.codahale.metrics.SharedMetricRegistries;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
@@ -13,11 +16,13 @@ import com.relayrides.pushy.apns.ApnsServerException;
import com.relayrides.pushy.apns.ClientNotConnectedException;
import com.relayrides.pushy.apns.DeliveryPriority;
import com.relayrides.pushy.apns.PushNotificationResponse;
+import com.relayrides.pushy.apns.metrics.dropwizard.DropwizardApnsClientMetricsListener;
import com.relayrides.pushy.apns.util.SimpleApnsPushNotification;
import org.bouncycastle.openssl.PEMReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.whispersystems.textsecuregcm.util.Constants;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@@ -26,10 +31,12 @@ import java.security.KeyPair;
import java.security.PrivateKey;
import java.security.cert.X509Certificate;
import java.util.Date;
+import java.util.Map;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
+import static com.codahale.metrics.MetricRegistry.name;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.GenericFutureListener;
@@ -43,24 +50,36 @@ public class RetryingApnsClient {
RetryingApnsClient(String apnCertificate, String apnKey, int retryCount)
throws IOException
{
- this(new ApnsClientBuilder().setClientCredentials(initializeCertificate(apnCertificate),
- initializePrivateKey(apnKey), null)
- .build(),
- retryCount);
+ MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME);
+ DropwizardApnsClientMetricsListener metricsListener = new DropwizardApnsClientMetricsListener();
+
+ for (Map.Entry entry : metricsListener.getMetrics().entrySet()) {
+ metricRegistry.register(name(getClass(), entry.getKey()), entry.getValue());
+ }
+
+ this.apnsClient = new ApnsClientBuilder().setClientCredentials(initializeCertificate(apnCertificate),
+ initializePrivateKey(apnKey), null)
+ .setMetricsListener(metricsListener)
+ .build();
+ this.retryExecutor = initializeExecutor(retryCount);
}
@VisibleForTesting
public RetryingApnsClient(ApnsClient apnsClient, int retryCount) {
+ this.apnsClient = apnsClient;
+ this.retryExecutor = initializeExecutor(retryCount);
+ }
+
+ private static RetryExecutor initializeExecutor(int retryCount) {
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
- this.apnsClient = apnsClient;
- this.retryExecutor = new AsyncRetryExecutor(executorService).retryOn(ClientNotConnectedException.class)
- .retryOn(InterruptedException.class)
- .retryOn(ApnsServerException.class)
- .withExponentialBackoff(100, 2.0)
- .withUniformJitter()
- .withMaxDelay(4000)
- .withMaxRetries(retryCount);
+ return new AsyncRetryExecutor(executorService).retryOn(ClientNotConnectedException.class)
+ .retryOn(InterruptedException.class)
+ .retryOn(ApnsServerException.class)
+ .withExponentialBackoff(100, 2.0)
+ .withUniformJitter()
+ .withMaxDelay(4000)
+ .withMaxRetries(retryCount);
}
ListenableFuture send(final String apnId, final String topic, final String payload, final Date expiration) {