18
18
19
19
import io .netty .buffer .ByteBuf ;
20
20
import io .netty .channel .Channel ;
21
+ import io .netty .channel .ChannelPipeline ;
21
22
import io .netty .channel .DefaultChannelPipeline ;
22
23
23
24
import java .lang .reflect .Constructor ;
24
25
import java .lang .reflect .InvocationTargetException ;
26
+ import java .lang .reflect .Method ;
25
27
import java .net .*;
26
28
import java .util .Queue ;
27
29
28
30
public class RakUtils {
29
31
30
32
private static final Constructor <DefaultChannelPipeline > DEFAULT_CHANNEL_PIPELINE_CONSTRUCTOR ;
33
+ private static final Method PIPELINE_DESTROY_METHOD ;
31
34
32
35
static {
33
36
try {
@@ -37,6 +40,14 @@ public class RakUtils {
37
40
} catch (NoSuchMethodException e ) {
38
41
throw new AssertionError ("Unable to find DefaultChannelPipeline(Channel) constructor" , e );
39
42
}
43
+
44
+ try {
45
+ Method method = DefaultChannelPipeline .class .getDeclaredMethod ("destroy" );
46
+ method .setAccessible (true );
47
+ PIPELINE_DESTROY_METHOD = method ;
48
+ } catch (NoSuchMethodException e ) {
49
+ throw new AssertionError ("Unable to find DefaultChannelPipeline.destroy() method" , e );
50
+ }
40
51
}
41
52
42
53
public static DefaultChannelPipeline newChannelPipeline (Channel channel ) {
@@ -47,6 +58,14 @@ public static DefaultChannelPipeline newChannelPipeline(Channel channel) {
47
58
}
48
59
}
49
60
61
+ public static void destroyChannelPipeline (ChannelPipeline pipeline ) {
62
+ try {
63
+ PIPELINE_DESTROY_METHOD .invoke (pipeline );
64
+ } catch (IllegalAccessException | InvocationTargetException e ) {
65
+ throw new IllegalStateException ("Unable to destroy DefaultChannelPipeline" , e );
66
+ }
67
+ }
68
+
50
69
private static final int AF_INET6 = 23 ;
51
70
52
71
public static InetSocketAddress readAddress (ByteBuf buffer ) {
0 commit comments