Skip to content

Commit f112d4e

Browse files
committed
Introduce a channel handler/factory for channel management requests
1 parent 6d28c9f commit f112d4e

File tree

4 files changed

+583
-0
lines changed

4 files changed

+583
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.eatthepath.pushy.apns;
2+
3+
import io.netty.channel.Channel;
4+
import io.netty.channel.ChannelPipeline;
5+
import io.netty.handler.flush.FlushConsolidationHandler;
6+
import io.netty.handler.ssl.SslHandler;
7+
import io.netty.handler.timeout.IdleStateHandler;
8+
import io.netty.util.AttributeKey;
9+
import io.netty.util.concurrent.Promise;
10+
11+
import java.util.concurrent.TimeUnit;
12+
13+
/**
14+
* An APNs channel factory creates new channels connected to an APNs server. Channels constructed by this factory are
15+
* intended for use in an {@link ApnsChannelPool}.
16+
*/
17+
class ApnsChannelManagementChannelFactory extends AbstractApnsChannelFactory {
18+
19+
private final ApnsClientConfiguration clientConfiguration;
20+
21+
ApnsChannelManagementChannelFactory(final ApnsClientConfiguration clientConfiguration,
22+
final ApnsClientResources clientResources) {
23+
24+
super(clientConfiguration.getApnsServerAddress(),
25+
clientConfiguration.getSslContext(),
26+
clientConfiguration.getProxyHandlerFactory().orElse(null),
27+
clientConfiguration.isHostnameVerificationEnabled(),
28+
clientConfiguration.getConnectionTimeout().orElse(null),
29+
clientResources);
30+
31+
this.clientConfiguration = clientConfiguration;
32+
}
33+
34+
protected void constructPipeline(final SslHandler sslHandler, final ChannelPipeline pipeline) {
35+
final String authority = clientConfiguration.getApnsServerAddress().getHostName();
36+
37+
final ApnsChannelManagementHandler apnsClientHandler;
38+
{
39+
final ApnsChannelManagementHandler.ApnsChannelManagementHandlerBuilder channelManagementHandlerBuilder;
40+
41+
channelManagementHandlerBuilder = new ApnsChannelManagementHandler.ApnsChannelManagementHandlerBuilder()
42+
.signingKey(clientConfiguration.getSigningKey().get())
43+
.tokenExpiration(clientConfiguration.getTokenExpiration())
44+
.authority(authority);
45+
46+
clientConfiguration.getFrameLogger().ifPresent(channelManagementHandlerBuilder::frameLogger);
47+
48+
apnsClientHandler = channelManagementHandlerBuilder.build();
49+
50+
clientConfiguration.getGracefulShutdownTimeout().ifPresent(timeout ->
51+
apnsClientHandler.gracefulShutdownTimeoutMillis(timeout.toMillis()));
52+
}
53+
54+
clientConfiguration.getProxyHandlerFactory().ifPresent(proxyHandlerFactory ->
55+
pipeline.addFirst(proxyHandlerFactory.createProxyHandler()));
56+
57+
pipeline.addLast(sslHandler);
58+
pipeline.addLast(apnsClientHandler);
59+
}
60+
}

0 commit comments

Comments
 (0)