Skip to content

Commit 13ea678

Browse files
committed
connect in dropwizard metrics listener to pushy
// FREEBIE
1 parent 2e98c16 commit 13ea678

2 files changed

Lines changed: 36 additions & 12 deletions

File tree

pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@
109109
<artifactId>pushy</artifactId>
110110
<version>0.9.3</version>
111111
</dependency>
112+
<dependency>
113+
<groupId>com.relayrides</groupId>
114+
<artifactId>pushy-dropwizard-metrics-listener</artifactId>
115+
<version>0.9.3</version>
116+
</dependency>
112117
<dependency>
113118
<groupId>org.whispersystems</groupId>
114119
<artifactId>gcm-sender-async</artifactId>

src/main/java/org/whispersystems/textsecuregcm/push/RetryingApnsClient.java

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package org.whispersystems.textsecuregcm.push;
22

3+
import com.codahale.metrics.Metric;
4+
import com.codahale.metrics.MetricRegistry;
5+
import com.codahale.metrics.SharedMetricRegistries;
36
import com.google.common.annotations.VisibleForTesting;
47
import com.google.common.util.concurrent.ListenableFuture;
58
import com.google.common.util.concurrent.SettableFuture;
@@ -13,11 +16,13 @@
1316
import com.relayrides.pushy.apns.ClientNotConnectedException;
1417
import com.relayrides.pushy.apns.DeliveryPriority;
1518
import com.relayrides.pushy.apns.PushNotificationResponse;
19+
import com.relayrides.pushy.apns.metrics.dropwizard.DropwizardApnsClientMetricsListener;
1620
import com.relayrides.pushy.apns.util.SimpleApnsPushNotification;
1721

1822
import org.bouncycastle.openssl.PEMReader;
1923
import org.slf4j.Logger;
2024
import org.slf4j.LoggerFactory;
25+
import org.whispersystems.textsecuregcm.util.Constants;
2126

2227
import java.io.ByteArrayInputStream;
2328
import java.io.IOException;
@@ -26,10 +31,12 @@
2631
import java.security.PrivateKey;
2732
import java.security.cert.X509Certificate;
2833
import java.util.Date;
34+
import java.util.Map;
2935
import java.util.concurrent.ExecutionException;
3036
import java.util.concurrent.Executors;
3137
import java.util.concurrent.ScheduledExecutorService;
3238

39+
import static com.codahale.metrics.MetricRegistry.name;
3340
import io.netty.util.concurrent.Future;
3441
import io.netty.util.concurrent.GenericFutureListener;
3542

@@ -43,24 +50,36 @@ public class RetryingApnsClient {
4350
RetryingApnsClient(String apnCertificate, String apnKey, int retryCount)
4451
throws IOException
4552
{
46-
this(new ApnsClientBuilder().setClientCredentials(initializeCertificate(apnCertificate),
47-
initializePrivateKey(apnKey), null)
48-
.build(),
49-
retryCount);
53+
MetricRegistry metricRegistry = SharedMetricRegistries.getOrCreate(Constants.METRICS_NAME);
54+
DropwizardApnsClientMetricsListener metricsListener = new DropwizardApnsClientMetricsListener();
55+
56+
for (Map.Entry<String, Metric> entry : metricsListener.getMetrics().entrySet()) {
57+
metricRegistry.register(name(getClass(), entry.getKey()), entry.getValue());
58+
}
59+
60+
this.apnsClient = new ApnsClientBuilder().setClientCredentials(initializeCertificate(apnCertificate),
61+
initializePrivateKey(apnKey), null)
62+
.setMetricsListener(metricsListener)
63+
.build();
64+
this.retryExecutor = initializeExecutor(retryCount);
5065
}
5166

5267
@VisibleForTesting
5368
public RetryingApnsClient(ApnsClient apnsClient, int retryCount) {
69+
this.apnsClient = apnsClient;
70+
this.retryExecutor = initializeExecutor(retryCount);
71+
}
72+
73+
private static RetryExecutor initializeExecutor(int retryCount) {
5474
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
5575

56-
this.apnsClient = apnsClient;
57-
this.retryExecutor = new AsyncRetryExecutor(executorService).retryOn(ClientNotConnectedException.class)
58-
.retryOn(InterruptedException.class)
59-
.retryOn(ApnsServerException.class)
60-
.withExponentialBackoff(100, 2.0)
61-
.withUniformJitter()
62-
.withMaxDelay(4000)
63-
.withMaxRetries(retryCount);
76+
return new AsyncRetryExecutor(executorService).retryOn(ClientNotConnectedException.class)
77+
.retryOn(InterruptedException.class)
78+
.retryOn(ApnsServerException.class)
79+
.withExponentialBackoff(100, 2.0)
80+
.withUniformJitter()
81+
.withMaxDelay(4000)
82+
.withMaxRetries(retryCount);
6483
}
6584

6685
ListenableFuture<ApnResult> send(final String apnId, final String topic, final String payload, final Date expiration) {

0 commit comments

Comments
 (0)