1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.channel.sctp;
17
18 import com.sun.nio.sctp.AbstractNotificationHandler;
19 import com.sun.nio.sctp.AssociationChangeNotification;
20 import com.sun.nio.sctp.HandlerResult;
21 import com.sun.nio.sctp.Notification;
22 import com.sun.nio.sctp.PeerAddressChangeNotification;
23 import com.sun.nio.sctp.SendFailedNotification;
24 import com.sun.nio.sctp.ShutdownNotification;
25
26 import io.netty.channel.ChannelPipeline;
27
28
29
30
31
32
33 public final class SctpNotificationHandler extends AbstractNotificationHandler<Object> {
34
35 private final SctpChannel sctpChannel;
36
37 public SctpNotificationHandler(SctpChannel sctpChannel) {
38 if (sctpChannel == null) {
39 throw new NullPointerException("sctpChannel");
40 }
41 this.sctpChannel = sctpChannel;
42 }
43
44 @Override
45 public HandlerResult handleNotification(AssociationChangeNotification notification, Object o) {
46 fireEvent(notification);
47 return HandlerResult.CONTINUE;
48 }
49
50 @Override
51 public HandlerResult handleNotification(PeerAddressChangeNotification notification, Object o) {
52 fireEvent(notification);
53 return HandlerResult.CONTINUE;
54 }
55
56 @Override
57 public HandlerResult handleNotification(SendFailedNotification notification, Object o) {
58 fireEvent(notification);
59 return HandlerResult.CONTINUE;
60 }
61
62 @Override
63 public HandlerResult handleNotification(ShutdownNotification notification, Object o) {
64 fireEvent(notification);
65 sctpChannel.close();
66 return HandlerResult.RETURN;
67 }
68
69 private void fireEvent(Notification notification) {
70 sctpChannel.pipeline().fireUserEventTriggered(notification);
71 }
72 }
73