|
1 /* |
|
2 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
|
4 * |
|
5 * This code is free software; you can redistribute it and/or modify it |
|
6 * under the terms of the GNU General Public License version 2 only, as |
|
7 * published by the Free Software Foundation. Oracle designates this |
|
8 * particular file as subject to the "Classpath" exception as provided |
|
9 * by Oracle in the LICENSE file that accompanied this code. |
|
10 * |
|
11 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 * version 2 for more details (a copy is included in the LICENSE file that |
|
15 * accompanied this code). |
|
16 * |
|
17 * You should have received a copy of the GNU General Public License version |
|
18 * 2 along with this work; if not, write to the Free Software Foundation, |
|
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 * |
|
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 * or visit www.oracle.com if you need additional information or have any |
|
23 * questions. |
|
24 */ |
|
25 package sun.nio.ch.sctp; |
|
26 |
|
27 import com.sun.nio.sctp.Association; |
|
28 import com.sun.nio.sctp.AssociationChangeNotification; |
|
29 import java.lang.annotation.Native; |
|
30 |
|
31 /** |
|
32 * An implementation of AssociationChangeNotification |
|
33 */ |
|
34 public class AssociationChange extends AssociationChangeNotification |
|
35 implements SctpNotification |
|
36 { |
|
37 /* static final ints so that they can be referenced from native */ |
|
38 @Native private final static int SCTP_COMM_UP = 1; |
|
39 @Native private final static int SCTP_COMM_LOST = 2; |
|
40 @Native private final static int SCTP_RESTART = 3; |
|
41 @Native private final static int SCTP_SHUTDOWN = 4; |
|
42 @Native private final static int SCTP_CANT_START = 5; |
|
43 |
|
44 private Association association; |
|
45 |
|
46 /* assocId is used to lookup the association before the notification is |
|
47 * returned to user code */ |
|
48 private int assocId; |
|
49 private AssocChangeEvent event; |
|
50 private int maxOutStreams; |
|
51 private int maxInStreams; |
|
52 |
|
53 /* Invoked from native */ |
|
54 private AssociationChange(int assocId, |
|
55 int intEvent, |
|
56 int maxOutStreams, |
|
57 int maxInStreams) { |
|
58 switch (intEvent) { |
|
59 case SCTP_COMM_UP : |
|
60 this.event = AssocChangeEvent.COMM_UP; |
|
61 break; |
|
62 case SCTP_COMM_LOST : |
|
63 this.event = AssocChangeEvent.COMM_LOST; |
|
64 break; |
|
65 case SCTP_RESTART : |
|
66 this.event = AssocChangeEvent.RESTART; |
|
67 break; |
|
68 case SCTP_SHUTDOWN : |
|
69 this.event = AssocChangeEvent.SHUTDOWN; |
|
70 break; |
|
71 case SCTP_CANT_START : |
|
72 this.event = AssocChangeEvent.CANT_START; |
|
73 break; |
|
74 default : |
|
75 throw new AssertionError( |
|
76 "Unknown Association Change Event type: " + intEvent); |
|
77 } |
|
78 |
|
79 this.assocId = assocId; |
|
80 this.maxOutStreams = maxOutStreams; |
|
81 this.maxInStreams = maxInStreams; |
|
82 } |
|
83 |
|
84 @Override |
|
85 public int assocId() { |
|
86 return assocId; |
|
87 } |
|
88 |
|
89 @Override |
|
90 public void setAssociation(Association association) { |
|
91 this.association = association; |
|
92 } |
|
93 |
|
94 @Override |
|
95 public Association association() { |
|
96 assert association != null; |
|
97 return association; |
|
98 } |
|
99 |
|
100 @Override |
|
101 public AssocChangeEvent event() { |
|
102 return event; |
|
103 } |
|
104 |
|
105 int maxOutStreams() { |
|
106 return maxOutStreams; |
|
107 } |
|
108 |
|
109 int maxInStreams() { |
|
110 return maxInStreams; |
|
111 } |
|
112 |
|
113 @Override |
|
114 public String toString() { |
|
115 StringBuilder sb = new StringBuilder(); |
|
116 sb.append(super.toString()).append(" ["); |
|
117 sb.append("Association:").append(association); |
|
118 sb.append(", Event: ").append(event).append("]"); |
|
119 return sb.toString(); |
|
120 } |
|
121 } |