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