author | alanb |
Thu, 15 Mar 2018 10:47:58 +0000 | |
changeset 49248 | 15a0e60c8b97 |
parent 47216 | 71c04702a3d5 |
child 49290 | 07779973cbe2 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49248
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved. |
2 | 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 |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 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. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.nio.ch; |
|
27 |
||
49248
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
28 |
import java.nio.channels.CancelledKeyException; |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
29 |
import java.nio.channels.SelectableChannel; |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
30 |
import java.nio.channels.SelectionKey; |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
31 |
import java.nio.channels.Selector; |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
32 |
import java.nio.channels.spi.AbstractSelectionKey; |
2 | 33 |
|
34 |
||
35 |
/** |
|
36 |
* An implementation of SelectionKey for Solaris. |
|
37 |
*/ |
|
38 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
39 |
public class SelectionKeyImpl |
2 | 40 |
extends AbstractSelectionKey |
41 |
{ |
|
42 |
||
43 |
final SelChImpl channel; // package-private |
|
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
44 |
public final SelectorImpl selector; |
2 | 45 |
|
46 |
// Index for a pollfd array in Selector that this key is registered with |
|
47 |
private int index; |
|
48 |
||
49 |
private volatile int interestOps; |
|
49248
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
50 |
private volatile int readyOps; |
2 | 51 |
|
52 |
SelectionKeyImpl(SelChImpl ch, SelectorImpl sel) { |
|
53 |
channel = ch; |
|
54 |
selector = sel; |
|
55 |
} |
|
56 |
||
57 |
public SelectableChannel channel() { |
|
58 |
return (SelectableChannel)channel; |
|
59 |
} |
|
60 |
||
61 |
public Selector selector() { |
|
62 |
return selector; |
|
63 |
} |
|
64 |
||
65 |
int getIndex() { // package-private |
|
66 |
return index; |
|
67 |
} |
|
68 |
||
69 |
void setIndex(int i) { // package-private |
|
70 |
index = i; |
|
71 |
} |
|
72 |
||
73 |
private void ensureValid() { |
|
74 |
if (!isValid()) |
|
75 |
throw new CancelledKeyException(); |
|
76 |
} |
|
77 |
||
78 |
public int interestOps() { |
|
79 |
ensureValid(); |
|
80 |
return interestOps; |
|
81 |
} |
|
82 |
||
83 |
public SelectionKey interestOps(int ops) { |
|
84 |
ensureValid(); |
|
85 |
return nioInterestOps(ops); |
|
86 |
} |
|
87 |
||
88 |
public int readyOps() { |
|
89 |
ensureValid(); |
|
90 |
return readyOps; |
|
91 |
} |
|
92 |
||
93 |
// The nio versions of these operations do not care if a key |
|
94 |
// has been invalidated. They are for internal use by nio code. |
|
95 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
96 |
public void nioReadyOps(int ops) { |
2 | 97 |
readyOps = ops; |
98 |
} |
|
99 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
100 |
public int nioReadyOps() { |
2 | 101 |
return readyOps; |
102 |
} |
|
103 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
104 |
public SelectionKey nioInterestOps(int ops) { |
2 | 105 |
if ((ops & ~channel().validOps()) != 0) |
106 |
throw new IllegalArgumentException(); |
|
107 |
channel.translateAndSetInterestOps(ops, this); |
|
108 |
interestOps = ops; |
|
109 |
return this; |
|
110 |
} |
|
111 |
||
11823
ee83ae88512d
7041778: Move SCTP implementation out of sun.nio.ch and into its own package
chegar
parents:
5506
diff
changeset
|
112 |
public int nioInterestOps() { |
2 | 113 |
return interestOps; |
114 |
} |
|
115 |
||
49248
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
116 |
@Override |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
117 |
public String toString() { |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
118 |
StringBuilder sb = new StringBuilder(); |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
119 |
sb.append("channel=") |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
120 |
.append(channel) |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
121 |
.append(", selector=") |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
122 |
.append(selector); |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
123 |
if (isValid()) { |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
124 |
sb.append(", interestOps=") |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
125 |
.append(interestOps) |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
126 |
.append(", readyOps=") |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
127 |
.append(readyOps); |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
128 |
} else { |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
129 |
sb.append(", invalid"); |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
130 |
} |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
131 |
return sb.toString(); |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
132 |
} |
15a0e60c8b97
8199611: (se) Minor selector implementation clean-up
alanb
parents:
47216
diff
changeset
|
133 |
|
2 | 134 |
} |