author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 25859 | jdk/src/jdk.sctp/unix/classes/sun/nio/ch/sctp/ResultContainer.java@3317bb8137f4 |
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 |
|
16734
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
27 |
import java.lang.annotation.Native; |
12317
9670c1610c53
7074397: Build infrastructure changes (makefile re-write)
ohair
parents:
11823
diff
changeset
|
28 |
|
2542 | 29 |
/** |
30 |
* Wraps the actual message or notification so that it can be |
|
31 |
* set and returned from the native receive implementation. |
|
32 |
*/ |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
33 |
public class ResultContainer { |
2542 | 34 |
/* 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
|
35 |
@Native static final int NOTHING = 0; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
36 |
@Native static final int MESSAGE = 1; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
37 |
@Native static final int SEND_FAILED = 2; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
38 |
@Native static final int ASSOCIATION_CHANGED = 3; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
39 |
@Native static final int PEER_ADDRESS_CHANGED = 4; |
da1901d79073
8000406: change files using @GenerateNativeHeader to use @Native
dxu
parents:
14342
diff
changeset
|
40 |
@Native static final int SHUTDOWN = 5; |
2542 | 41 |
|
42 |
private Object value; |
|
43 |
private int type; |
|
44 |
||
45 |
int type() { |
|
46 |
return type; |
|
47 |
} |
|
48 |
||
49 |
boolean hasSomething() { |
|
50 |
return type() != NOTHING; |
|
51 |
} |
|
52 |
||
53 |
boolean isNotification() { |
|
54 |
return type() != MESSAGE && type() != NOTHING ? true : false; |
|
55 |
} |
|
56 |
||
57 |
void clear() { |
|
58 |
type = NOTHING; |
|
59 |
value = null; |
|
60 |
} |
|
61 |
||
62 |
SctpNotification notification() { |
|
63 |
assert type() != MESSAGE && type() != NOTHING; |
|
64 |
||
65 |
return (SctpNotification) value; |
|
66 |
} |
|
67 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
68 |
MessageInfoImpl getMessageInfo() { |
2542 | 69 |
assert type() == MESSAGE; |
70 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
71 |
if (value instanceof MessageInfoImpl) |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
72 |
return (MessageInfoImpl) value; |
2542 | 73 |
|
74 |
return null; |
|
75 |
} |
|
76 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
77 |
SendFailed getSendFailed() { |
2542 | 78 |
assert type() == SEND_FAILED; |
79 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
80 |
if (value instanceof SendFailed) |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
81 |
return (SendFailed) value; |
2542 | 82 |
|
83 |
return null; |
|
84 |
} |
|
85 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
86 |
AssociationChange getAssociationChanged() { |
2542 | 87 |
assert type() == ASSOCIATION_CHANGED; |
88 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
89 |
if (value instanceof AssociationChange) |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
90 |
return (AssociationChange) value; |
2542 | 91 |
|
92 |
return null; |
|
93 |
} |
|
94 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
95 |
PeerAddrChange getPeerAddressChanged() { |
2542 | 96 |
assert type() == PEER_ADDRESS_CHANGED; |
97 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
98 |
if (value instanceof PeerAddrChange) |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
99 |
return (PeerAddrChange) value; |
2542 | 100 |
|
101 |
return null; |
|
102 |
} |
|
103 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
104 |
Shutdown getShutdown() { |
2542 | 105 |
assert type() == SHUTDOWN; |
106 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
107 |
if (value instanceof Shutdown) |
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
108 |
return (Shutdown) value; |
2542 | 109 |
|
110 |
return null; |
|
111 |
} |
|
112 |
||
113 |
@Override |
|
114 |
public String toString() { |
|
115 |
StringBuilder sb = new StringBuilder(); |
|
116 |
sb.append("Type: "); |
|
117 |
switch (type) { |
|
118 |
case NOTHING: sb.append("NOTHING"); break; |
|
119 |
case MESSAGE: sb.append("MESSAGE"); break; |
|
120 |
case SEND_FAILED: sb.append("SEND FAILED"); break; |
|
121 |
case ASSOCIATION_CHANGED: sb.append("ASSOCIATION CHANGE"); break; |
|
122 |
case PEER_ADDRESS_CHANGED: sb.append("PEER ADDRESS CHANGE"); break; |
|
123 |
case SHUTDOWN: sb.append("SHUTDOWN"); break; |
|
124 |
default : sb.append("Unknown result type"); |
|
125 |
} |
|
3072
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
126 |
sb.append(", Value: "); |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
127 |
sb.append((value == null) ? "null" : value.toString()); |
a801b122142f
6855335: Several changes in the SCTP implementation.
chegar
parents:
2542
diff
changeset
|
128 |
return sb.toString(); |
2542 | 129 |
} |
130 |
} |