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 import io.netty.channel.ChannelPipeline;
26 import io.netty.util.internal.ObjectUtil;
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 this.sctpChannel = ObjectUtil.checkNotNull(sctpChannel, "sctpChannel");
39 }
40
41 @Override
42 public HandlerResult handleNotification(AssociationChangeNotification notification, Object o) {
43 fireEvent(notification);
44 return HandlerResult.CONTINUE;
45 }
46
47 @Override
48 public HandlerResult handleNotification(PeerAddressChangeNotification notification, Object o) {
49 fireEvent(notification);
50 return HandlerResult.CONTINUE;
51 }
52
53 @Override
54 public HandlerResult handleNotification(SendFailedNotification notification, Object o) {
55 fireEvent(notification);
56 return HandlerResult.CONTINUE;
57 }
58
59 @Override
60 public HandlerResult handleNotification(ShutdownNotification notification, Object o) {
61 fireEvent(notification);
62 sctpChannel.close();
63 return HandlerResult.RETURN;
64 }
65
66 private void fireEvent(Notification notification) {
67 sctpChannel.pipeline().fireUserEventTriggered(notification);
68 }
69 }
70