author | jcbeyler |
Wed, 14 Nov 2018 12:25:15 -0800 | |
changeset 52561 | 40098289d580 |
parent 47216 | 71c04702a3d5 |
child 59202 | 533f1183d7c6 |
permissions | -rw-r--r-- |
2542 | 1 |
/* |
16734
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
2 |
* Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved. |
2542 | 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 |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2542 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2542 | 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 |
* |
|
5506 | 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. |
|
2542 | 24 |
*/ |
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
25 |
package sun.nio.ch.sctp; |
2542 | 26 |
|
27 |
import com.sun.nio.sctp.Association; |
|
28 |
import com.sun.nio.sctp.AssociationChangeNotification; |
|
16734
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
29 |
import java.lang.annotation.Native; |
2542 | 30 |
|
31 |
/** |
|
32 |
* An implementation of AssociationChangeNotification |
|
33 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
34 |
public class AssociationChange extends AssociationChangeNotification |
2542 | 35 |
implements SctpNotification |
36 |
{ |
|
37 |
/* static final ints so that they can be referenced from native */ |
|
16734
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
38 |
@Native private final static int SCTP_COMM_UP = 1; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
39 |
@Native private final static int SCTP_COMM_LOST = 2; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
40 |
@Native private final static int SCTP_RESTART = 3; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
41 |
@Native private final static int SCTP_SHUTDOWN = 4; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
42 |
@Native private final static int SCTP_CANT_START = 5; |
2542 | 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 */ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
54 |
private AssociationChange(int assocId, |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
55 |
int intEvent, |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
56 |
int maxOutStreams, |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
57 |
int maxInStreams) { |
2542 | 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 |
} |