38
38
import io .netty .handler .timeout .IdleStateEvent ;
39
39
import io .netty .util .AsciiString ;
40
40
import io .netty .util .collection .IntObjectHashMap ;
41
- import io .netty .util .concurrent .GenericFutureListener ;
42
41
import io .netty .util .concurrent .Promise ;
43
42
import io .netty .util .concurrent .PromiseCombiner ;
44
- import io .netty .util .concurrent .ScheduledFuture ;
45
43
import org .slf4j .Logger ;
46
44
import org .slf4j .LoggerFactory ;
47
45
48
46
import java .io .IOException ;
49
47
import java .nio .charset .StandardCharsets ;
50
48
import java .text .ParseException ;
51
- import java .time .Duration ;
52
49
import java .util .Map ;
53
50
import java .util .Objects ;
54
51
import java .util .UUID ;
55
52
import java .util .concurrent .CompletableFuture ;
56
- import java .util .concurrent .TimeUnit ;
57
53
58
54
class ApnsClientHandler extends Http2ConnectionHandler implements Http2FrameListener , Http2Connection .Listener {
59
55
@@ -65,9 +61,6 @@ class ApnsClientHandler extends Http2ConnectionHandler implements Http2FrameList
65
61
66
62
private final String authority ;
67
63
68
- private final Duration pingTimeout ;
69
- private ScheduledFuture <?> pingTimeoutFuture ;
70
-
71
64
private Throwable connectionErrorCause ;
72
65
73
66
private static final AsciiString APNS_PATH_PREFIX = new AsciiString ("/3/device/" );
@@ -92,7 +85,6 @@ class ApnsClientHandler extends Http2ConnectionHandler implements Http2FrameList
92
85
public static class ApnsClientHandlerBuilder extends AbstractHttp2ConnectionHandlerBuilder <ApnsClientHandler , ApnsClientHandlerBuilder > {
93
86
94
87
private String authority ;
95
- private Duration idlePingInterval ;
96
88
97
89
ApnsClientHandlerBuilder authority (final String authority ) {
98
90
this .authority = authority ;
@@ -103,15 +95,6 @@ String authority() {
103
95
return this .authority ;
104
96
}
105
97
106
- Duration idlePingInterval () {
107
- return idlePingInterval ;
108
- }
109
-
110
- ApnsClientHandlerBuilder idlePingInterval (final Duration idlePingIntervalMillis ) {
111
- this .idlePingInterval = idlePingIntervalMillis ;
112
- return this ;
113
- }
114
-
115
98
@ Override
116
99
public ApnsClientHandlerBuilder frameLogger (final Http2FrameLogger frameLogger ) {
117
100
return super .frameLogger (frameLogger );
@@ -136,7 +119,7 @@ protected boolean encoderEnforceMaxConcurrentStreams() {
136
119
public ApnsClientHandler build (final Http2ConnectionDecoder decoder , final Http2ConnectionEncoder encoder , final Http2Settings initialSettings ) {
137
120
Objects .requireNonNull (this .authority (), "Authority must be set before building an ApnsClientHandler." );
138
121
139
- final ApnsClientHandler handler = new ApnsClientHandler (decoder , encoder , initialSettings , this .authority (), this . idlePingInterval () );
122
+ final ApnsClientHandler handler = new ApnsClientHandler (decoder , encoder , initialSettings , this .authority ());
140
123
this .frameListener (handler );
141
124
return handler ;
142
125
}
@@ -147,7 +130,7 @@ public ApnsClientHandler build() {
147
130
}
148
131
}
149
132
150
- ApnsClientHandler (final Http2ConnectionDecoder decoder , final Http2ConnectionEncoder encoder , final Http2Settings initialSettings , final String authority , final Duration idlePingInterval ) {
133
+ ApnsClientHandler (final Http2ConnectionDecoder decoder , final Http2ConnectionEncoder encoder , final Http2Settings initialSettings , final String authority ) {
151
134
super (decoder , encoder , initialSettings );
152
135
153
136
this .authority = authority ;
@@ -157,8 +140,6 @@ public ApnsClientHandler build() {
157
140
this .streamErrorCausePropertyKey = this .connection ().newKey ();
158
141
159
142
this .connection ().addListener (this );
160
-
161
- this .pingTimeout = idlePingInterval .dividedBy (2 );
162
143
}
163
144
164
145
@ Override
@@ -264,22 +245,8 @@ protected Http2Headers getHeadersForPushNotification(final ApnsPushNotification
264
245
@ Override
265
246
public void userEventTriggered (final ChannelHandlerContext context , final Object event ) throws Exception {
266
247
if (event instanceof IdleStateEvent ) {
267
- log .trace ("Sending ping due to inactivity." );
268
-
269
- this .encoder ().writePing (context , false , System .currentTimeMillis (), context .newPromise ()).addListener (
270
- (GenericFutureListener <ChannelFuture >) future -> {
271
- if (!future .isSuccess ()) {
272
- log .debug ("Failed to write PING frame." , future .cause ());
273
- future .channel ().close ();
274
- }
275
- });
276
-
277
- this .pingTimeoutFuture = context .channel ().eventLoop ().schedule (() -> {
278
- log .debug ("Closing channel due to ping timeout." );
279
- context .channel ().close ();
280
- }, pingTimeout .toMillis (), TimeUnit .MILLISECONDS );
281
-
282
- this .flush (context );
248
+ log .debug ("Closing idle channel." );
249
+ context .close ();
283
250
}
284
251
285
252
super .userEventTriggered (context , event );
@@ -413,11 +380,6 @@ public void onPingRead(final ChannelHandlerContext ctx, final long pingData) {
413
380
414
381
@ Override
415
382
public void onPingAckRead (final ChannelHandlerContext context , final long pingData ) {
416
- if (this .pingTimeoutFuture != null ) {
417
- this .pingTimeoutFuture .cancel (false );
418
- } else {
419
- log .error ("Received PING ACK, but no corresponding outbound PING found." );
420
- }
421
383
}
422
384
423
385
@ Override
@@ -508,10 +470,6 @@ protected void onConnectionError(final ChannelHandlerContext context, final bool
508
470
509
471
@ Override
510
472
public void channelInactive (final ChannelHandlerContext context ) throws Exception {
511
- if (this .pingTimeoutFuture != null ) {
512
- this .pingTimeoutFuture .cancel (false );
513
- }
514
-
515
473
for (final PushNotificationFuture <?, ?> future : this .unattachedResponsePromisesByStreamId .values ()) {
516
474
future .completeExceptionally (STREAM_CLOSED_BEFORE_REPLY_EXCEPTION );
517
475
}
0 commit comments