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