author | aph |
Fri, 16 Feb 2018 09:43:26 +0000 | |
changeset 49407 | 7fa5375fa6fd |
parent 47216 | 71c04702a3d5 |
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 java.net.SocketAddress; |
|
28 |
import com.sun.nio.sctp.Association; |
|
29 |
import com.sun.nio.sctp.PeerAddressChangeNotification; |
|
16734
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
30 |
import java.lang.annotation.Native; |
2542 | 31 |
|
32 |
/** |
|
33 |
* An implementation of PeerAddressChangeNotification |
|
34 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
35 |
public class PeerAddrChange extends PeerAddressChangeNotification |
2542 | 36 |
implements SctpNotification |
37 |
{ |
|
38 |
/* 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
|
39 |
@Native private final static int SCTP_ADDR_AVAILABLE = 1; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
40 |
@Native private final static int SCTP_ADDR_UNREACHABLE = 2; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
41 |
@Native private final static int SCTP_ADDR_REMOVED = 3; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
42 |
@Native private final static int SCTP_ADDR_ADDED = 4; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
43 |
@Native private final static int SCTP_ADDR_MADE_PRIM = 5; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
44 |
@Native private final static int SCTP_ADDR_CONFIRMED =6; |
2542 | 45 |
|
46 |
private Association association; |
|
47 |
||
48 |
/* assocId is used to lookup the association before the notification is |
|
49 |
* returned to user code */ |
|
50 |
private int assocId; |
|
51 |
private SocketAddress address; |
|
52 |
private AddressChangeEvent event; |
|
53 |
||
54 |
/* Invoked from native */ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
55 |
private PeerAddrChange(int assocId, SocketAddress address, int intEvent) { |
2542 | 56 |
switch (intEvent) { |
57 |
case SCTP_ADDR_AVAILABLE : |
|
58 |
this.event = AddressChangeEvent.ADDR_AVAILABLE; |
|
59 |
break; |
|
60 |
case SCTP_ADDR_UNREACHABLE : |
|
61 |
this.event = AddressChangeEvent.ADDR_UNREACHABLE; |
|
62 |
break; |
|
63 |
case SCTP_ADDR_REMOVED : |
|
64 |
this.event = AddressChangeEvent.ADDR_REMOVED; |
|
65 |
break; |
|
66 |
case SCTP_ADDR_ADDED : |
|
67 |
this.event = AddressChangeEvent.ADDR_ADDED; |
|
68 |
break; |
|
69 |
case SCTP_ADDR_MADE_PRIM : |
|
70 |
this.event = AddressChangeEvent.ADDR_MADE_PRIMARY; |
|
71 |
break; |
|
72 |
case SCTP_ADDR_CONFIRMED : |
|
73 |
this.event = AddressChangeEvent.ADDR_CONFIRMED; |
|
74 |
break; |
|
75 |
default: |
|
76 |
throw new AssertionError("Unknown event type"); |
|
77 |
} |
|
78 |
this.assocId = assocId; |
|
79 |
this.address = address; |
|
80 |
} |
|
81 |
||
82 |
@Override |
|
83 |
public int assocId() { |
|
84 |
return assocId; |
|
85 |
} |
|
86 |
||
87 |
@Override |
|
88 |
public void setAssociation(Association association) { |
|
89 |
this.association = association; |
|
90 |
} |
|
91 |
||
92 |
@Override |
|
93 |
public SocketAddress address() { |
|
94 |
assert address != null; |
|
95 |
return address; |
|
96 |
} |
|
97 |
||
98 |
@Override |
|
99 |
public Association association() { |
|
100 |
assert association != null; |
|
101 |
return association; |
|
102 |
} |
|
103 |
||
104 |
@Override |
|
105 |
public AddressChangeEvent event() { |
|
106 |
assert event != null; |
|
107 |
return event; |
|
108 |
} |
|
109 |
||
110 |
@Override |
|
111 |
public String toString() { |
|
112 |
StringBuilder sb = new StringBuilder(); |
|
113 |
sb.append(super.toString()).append(" ["); |
|
114 |
sb.append("Address: ").append(address); |
|
115 |
sb.append(", Association:").append(association); |
|
116 |
sb.append(", Event: ").append(event).append("]"); |
|
117 |
return sb.toString(); |
|
118 |
} |
|
119 |
} |
|
120 |