1 /* |
|
2 * Copyright (c) 2009, 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; |
|
26 |
|
27 import java.net.SocketAddress; |
|
28 import com.sun.nio.sctp.Association; |
|
29 import com.sun.nio.sctp.PeerAddressChangeNotification; |
|
30 |
|
31 /** |
|
32 * An implementation of PeerAddressChangeNotification |
|
33 */ |
|
34 public class SctpPeerAddrChange extends PeerAddressChangeNotification |
|
35 implements SctpNotification |
|
36 { |
|
37 /* static final ints so that they can be referenced from native */ |
|
38 private final static int SCTP_ADDR_AVAILABLE = 1; |
|
39 private final static int SCTP_ADDR_UNREACHABLE = 2; |
|
40 private final static int SCTP_ADDR_REMOVED = 3; |
|
41 private final static int SCTP_ADDR_ADDED = 4; |
|
42 private final static int SCTP_ADDR_MADE_PRIM = 5; |
|
43 private final static int SCTP_ADDR_CONFIRMED =6; |
|
44 |
|
45 private Association association; |
|
46 |
|
47 /* assocId is used to lookup the association before the notification is |
|
48 * returned to user code */ |
|
49 private int assocId; |
|
50 private SocketAddress address; |
|
51 private AddressChangeEvent event; |
|
52 |
|
53 /* Invoked from native */ |
|
54 private SctpPeerAddrChange(int assocId, SocketAddress address, int intEvent) { |
|
55 switch (intEvent) { |
|
56 case SCTP_ADDR_AVAILABLE : |
|
57 this.event = AddressChangeEvent.ADDR_AVAILABLE; |
|
58 break; |
|
59 case SCTP_ADDR_UNREACHABLE : |
|
60 this.event = AddressChangeEvent.ADDR_UNREACHABLE; |
|
61 break; |
|
62 case SCTP_ADDR_REMOVED : |
|
63 this.event = AddressChangeEvent.ADDR_REMOVED; |
|
64 break; |
|
65 case SCTP_ADDR_ADDED : |
|
66 this.event = AddressChangeEvent.ADDR_ADDED; |
|
67 break; |
|
68 case SCTP_ADDR_MADE_PRIM : |
|
69 this.event = AddressChangeEvent.ADDR_MADE_PRIMARY; |
|
70 break; |
|
71 case SCTP_ADDR_CONFIRMED : |
|
72 this.event = AddressChangeEvent.ADDR_CONFIRMED; |
|
73 break; |
|
74 default: |
|
75 throw new AssertionError("Unknown event type"); |
|
76 } |
|
77 this.assocId = assocId; |
|
78 this.address = address; |
|
79 } |
|
80 |
|
81 @Override |
|
82 public int assocId() { |
|
83 return assocId; |
|
84 } |
|
85 |
|
86 @Override |
|
87 public void setAssociation(Association association) { |
|
88 this.association = association; |
|
89 } |
|
90 |
|
91 @Override |
|
92 public SocketAddress address() { |
|
93 assert address != null; |
|
94 return address; |
|
95 } |
|
96 |
|
97 @Override |
|
98 public Association association() { |
|
99 assert association != null; |
|
100 return association; |
|
101 } |
|
102 |
|
103 @Override |
|
104 public AddressChangeEvent event() { |
|
105 assert event != null; |
|
106 return event; |
|
107 } |
|
108 |
|
109 @Override |
|
110 public String toString() { |
|
111 StringBuilder sb = new StringBuilder(); |
|
112 sb.append(super.toString()).append(" ["); |
|
113 sb.append("Address: ").append(address); |
|
114 sb.append(", Association:").append(association); |
|
115 sb.append(", Event: ").append(event).append("]"); |
|
116 return sb.toString(); |
|
117 } |
|
118 } |
|
119 |
|