Mercurial Hosting > luan
annotate src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java @ 952:669769bcdf5c
simplify AsyncEndPoint
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 12 Oct 2016 19:47:45 -0600 |
parents | a778413aefc0 |
children | 7db4a488fc82 |
rev | line source |
---|---|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 // ------------------------------------------------------------------------ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 // All rights reserved. This program and the accompanying materials |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 // are made available under the terms of the Eclipse Public License v1.0 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 // and Apache License v2.0 which accompanies this distribution. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 // The Eclipse Public License is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 // http://www.eclipse.org/legal/epl-v10.html |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 // The Apache License v2.0 is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 // http://www.opensource.org/licenses/apache2.0.php |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 // You may elect to redistribute this code under either of these licenses. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 package org.eclipse.jetty.io.nio; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 import java.io.IOException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 import java.io.InterruptedIOException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import java.nio.channels.ClosedChannelException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import java.nio.channels.SelectableChannel; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import java.nio.channels.SelectionKey; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 import java.nio.channels.SocketChannel; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 import java.util.Locale; |
865 | 28 import java.util.concurrent.RejectedExecutionException; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import org.eclipse.jetty.io.AsyncEndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 import org.eclipse.jetty.io.Buffer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 import org.eclipse.jetty.io.ConnectedEndPoint; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 import org.eclipse.jetty.io.Connection; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 import org.eclipse.jetty.io.EofException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 import org.eclipse.jetty.io.nio.SelectorManager.SelectSet; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
36 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
37 import org.slf4j.LoggerFactory; |
940
b77d631b9e28
remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents:
915
diff
changeset
|
38 |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 /* ------------------------------------------------------------ */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 /** |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 * An Endpoint that can be scheduled by {@link SelectorManager}. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 public class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPoint, ConnectedEndPoint |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 { |
865 | 46 public static final Logger LOG=LoggerFactory.getLogger("org.eclipse.jetty.io.nio"); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
47 |
865 | 48 private final SelectorManager.SelectSet _selectSet; |
49 private final SelectorManager _manager; | |
50 private SelectionKey _key; | |
51 private final Runnable _handler = new Runnable() | |
52 { | |
53 public void run() { handle(); } | |
54 }; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
55 |
865 | 56 /** The desired value for {@link SelectionKey#interestOps()} */ |
57 private int _interestOps; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
58 |
865 | 59 /** |
60 * The connection instance is the handler for any IO activity on the endpoint. | |
61 * There is a different type of connection for HTTP, AJP, WebSocket and | |
62 * ProxyConnect. The connection may change for an SCEP as it is upgraded | |
63 * from HTTP to proxy connect or websocket. | |
64 */ | |
65 private volatile AsyncConnection _connection; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
66 |
865 | 67 private static final int STATE_NEEDS_DISPATCH=-1; |
68 private static final int STATE_UNDISPATCHED=0; | |
69 private static final int STATE_DISPATCHED=1; | |
70 private int _state; | |
71 | |
72 private boolean _onIdle; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
73 |
865 | 74 /** true if the last write operation succeed and wrote all offered bytes */ |
75 private volatile boolean _writable = true; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
76 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
77 |
865 | 78 /** True if a thread has is blocked in {@link #blockReadable(long)} */ |
79 private boolean _readBlocked; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
80 |
865 | 81 /** True if a thread has is blocked in {@link #blockWritable(long)} */ |
82 private boolean _writeBlocked; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
83 |
865 | 84 /** true if {@link SelectSet#destroyEndPoint(SelectChannelEndPoint)} has not been called */ |
85 private boolean _open; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
86 |
865 | 87 private volatile long _idleTimestamp; |
88 private volatile boolean _checkIdle; | |
89 | |
90 private boolean _ishut; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
91 |
865 | 92 /* ------------------------------------------------------------ */ |
93 public SelectChannelEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key, int maxIdleTime) | |
94 throws IOException | |
95 { | |
96 super(channel, maxIdleTime); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
97 |
865 | 98 _manager = selectSet.getManager(); |
99 _selectSet = selectSet; | |
100 _state=STATE_UNDISPATCHED; | |
101 _onIdle=false; | |
102 _open=true; | |
103 _key = key; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
104 |
865 | 105 setCheckForIdle(true); |
106 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
107 |
865 | 108 /* ------------------------------------------------------------ */ |
109 public SelectionKey getSelectionKey() | |
110 { | |
111 synchronized (this) | |
112 { | |
113 return _key; | |
114 } | |
115 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
116 |
865 | 117 public SelectorManager getSelectManager() |
118 { | |
119 return _manager; | |
120 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
121 |
865 | 122 public Connection getConnection() |
123 { | |
124 return _connection; | |
125 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
126 |
865 | 127 public void setConnection(Connection connection) |
128 { | |
129 _connection=(AsyncConnection)connection; | |
130 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
131 |
865 | 132 /* ------------------------------------------------------------ */ |
133 /** Called by selectSet to schedule handling | |
134 * | |
135 */ | |
136 public void schedule() | |
137 { | |
138 synchronized (this) | |
139 { | |
140 // If there is no key, then do nothing | |
141 if (_key == null || !_key.isValid()) | |
142 { | |
143 _readBlocked=false; | |
144 _writeBlocked=false; | |
145 this.notifyAll(); | |
146 return; | |
147 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
148 |
865 | 149 // If there are threads dispatched reading and writing |
150 if (_readBlocked || _writeBlocked) | |
151 { | |
152 // assert _dispatched; | |
153 if (_readBlocked && _key.isReadable()) | |
154 _readBlocked=false; | |
155 if (_writeBlocked && _key.isWritable()) | |
156 _writeBlocked=false; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
157 |
865 | 158 // wake them up is as good as a dispatched. |
159 this.notifyAll(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
160 |
865 | 161 // we are not interested in further selecting |
162 _key.interestOps(0); | |
163 if (_state<STATE_DISPATCHED) | |
164 updateKey(); | |
165 return; | |
166 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
167 |
865 | 168 // Remove writeable op |
169 if ((_key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE && (_key.interestOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) | |
170 { | |
171 // Remove writeable op | |
172 _interestOps = _key.interestOps() & ~SelectionKey.OP_WRITE; | |
173 _key.interestOps(_interestOps); | |
174 _writable = true; // Once writable is in ops, only removed with dispatch. | |
175 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
176 |
865 | 177 // If dispatched, then deregister interest |
178 if (_state>=STATE_DISPATCHED) | |
179 _key.interestOps(0); | |
180 else | |
181 { | |
182 // other wise do the dispatch | |
183 dispatch(); | |
184 } | |
185 } | |
186 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
187 |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
188 public synchronized void dispatch() |
865 | 189 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
190 if (_state<=STATE_UNDISPATCHED) |
865 | 191 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
192 if (_onIdle) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
193 _state = STATE_NEEDS_DISPATCH; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
194 else |
865 | 195 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
196 _state = STATE_DISPATCHED; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
197 try { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
198 _manager.execute(_handler); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
199 } catch(RejectedExecutionException e) { |
865 | 200 _state = STATE_NEEDS_DISPATCH; |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
201 LOG.warn("Dispatched Failed! "+this+" to "+_manager); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
202 updateKey(); |
865 | 203 } |
204 } | |
205 } | |
206 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
207 |
865 | 208 /* ------------------------------------------------------------ */ |
209 /** | |
210 * Called when a dispatched thread is no longer handling the endpoint. | |
211 * The selection key operations are updated. | |
212 * @return If false is returned, the endpoint has been redispatched and | |
213 * thread must keep handling the endpoint. | |
214 */ | |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
215 protected synchronized void undispatch() |
865 | 216 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
217 _state = STATE_UNDISPATCHED; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
218 updateKey(); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
219 // return true; |
865 | 220 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
221 |
865 | 222 public void setCheckForIdle(boolean check) |
223 { | |
224 if (check) | |
225 { | |
226 _idleTimestamp=System.currentTimeMillis(); | |
227 _checkIdle=true; | |
228 } | |
229 else | |
230 _checkIdle=false; | |
231 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
232 |
952
669769bcdf5c
simplify AsyncEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
950
diff
changeset
|
233 private boolean isCheckForIdle() |
865 | 234 { |
235 return _checkIdle; | |
236 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
237 |
865 | 238 protected void notIdle() |
239 { | |
240 _idleTimestamp=System.currentTimeMillis(); | |
241 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
242 |
865 | 243 public void checkIdleTimestamp(long now) |
244 { | |
245 if (isCheckForIdle() && _maxIdleTime>0) | |
246 { | |
247 final long idleForMs=now-_idleTimestamp; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
248 |
865 | 249 if (idleForMs>_maxIdleTime) |
250 { | |
251 // Don't idle out again until onIdleExpired task completes. | |
252 setCheckForIdle(false); | |
253 _manager.execute(new Runnable() | |
254 { | |
255 public void run() | |
256 { | |
257 try | |
258 { | |
259 onIdleExpired(idleForMs); | |
260 } | |
261 finally | |
262 { | |
263 setCheckForIdle(true); | |
264 } | |
265 } | |
266 }); | |
267 } | |
268 } | |
269 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
270 |
952
669769bcdf5c
simplify AsyncEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
950
diff
changeset
|
271 private void onIdleExpired(long idleForMs) |
865 | 272 { |
273 try | |
274 { | |
275 synchronized (this) | |
276 { | |
277 _onIdle=true; | |
278 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
279 |
865 | 280 _connection.onIdleExpired(idleForMs); |
281 } | |
282 finally | |
283 { | |
284 synchronized (this) | |
285 { | |
286 _onIdle=false; | |
287 if (_state==STATE_NEEDS_DISPATCH) | |
288 dispatch(); | |
289 } | |
290 } | |
291 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
292 |
865 | 293 @Override |
294 public int fill(Buffer buffer) throws IOException | |
295 { | |
296 int fill=super.fill(buffer); | |
297 if (fill>0) | |
298 notIdle(); | |
299 return fill; | |
300 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
301 |
865 | 302 @Override |
303 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException | |
304 { | |
305 int l = super.flush(header, buffer, trailer); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
306 |
865 | 307 // If there was something to write and it wasn't written, then we are not writable. |
308 if (l==0 && ( header!=null && header.hasContent() || buffer!=null && buffer.hasContent() || trailer!=null && trailer.hasContent())) | |
309 { | |
310 synchronized (this) | |
311 { | |
312 _writable=false; | |
313 if (_state<STATE_DISPATCHED) | |
314 updateKey(); | |
315 } | |
316 } | |
317 else if (l>0) | |
318 { | |
319 _writable=true; | |
320 notIdle(); | |
321 } | |
322 return l; | |
323 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
324 |
865 | 325 @Override |
326 public int flush(Buffer buffer) throws IOException | |
327 { | |
328 int l = super.flush(buffer); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
329 |
865 | 330 // If there was something to write and it wasn't written, then we are not writable. |
331 if (l==0 && buffer!=null && buffer.hasContent()) | |
332 { | |
333 synchronized (this) | |
334 { | |
335 _writable=false; | |
336 if (_state<STATE_DISPATCHED) | |
337 updateKey(); | |
338 } | |
339 } | |
340 else if (l>0) | |
341 { | |
342 _writable=true; | |
343 notIdle(); | |
344 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
345 |
865 | 346 return l; |
347 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
348 |
865 | 349 /* ------------------------------------------------------------ */ |
350 /* | |
351 * Allows thread to block waiting for further events. | |
352 */ | |
353 @Override | |
354 public boolean blockReadable(long timeoutMs) throws IOException | |
355 { | |
356 synchronized (this) | |
357 { | |
358 if (isInputShutdown()) | |
359 throw new EofException(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
360 |
865 | 361 long now=_selectSet.getNow(); |
362 long end=now+timeoutMs; | |
363 boolean check=isCheckForIdle(); | |
364 setCheckForIdle(true); | |
365 try | |
366 { | |
367 _readBlocked=true; | |
368 while (!isInputShutdown() && _readBlocked) | |
369 { | |
370 try | |
371 { | |
372 updateKey(); | |
373 this.wait(timeoutMs>0?(end-now):10000); | |
374 } | |
375 catch (final InterruptedException e) | |
376 { | |
377 LOG.warn("",e); | |
378 } | |
379 finally | |
380 { | |
381 now=_selectSet.getNow(); | |
382 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
383 |
865 | 384 if (_readBlocked && timeoutMs>0 && now>=end) |
385 return false; | |
386 } | |
387 } | |
388 finally | |
389 { | |
390 _readBlocked=false; | |
391 setCheckForIdle(check); | |
392 } | |
393 } | |
394 return true; | |
395 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
396 |
865 | 397 /* ------------------------------------------------------------ */ |
398 /* | |
399 * Allows thread to block waiting for further events. | |
400 */ | |
401 @Override | |
402 public boolean blockWritable(long timeoutMs) throws IOException | |
403 { | |
404 synchronized (this) | |
405 { | |
406 if (isOutputShutdown()) | |
407 throw new EofException(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
408 |
865 | 409 long now=_selectSet.getNow(); |
410 long end=now+timeoutMs; | |
411 boolean check=isCheckForIdle(); | |
412 setCheckForIdle(true); | |
413 try | |
414 { | |
415 _writeBlocked=true; | |
416 while (_writeBlocked && !isOutputShutdown()) | |
417 { | |
418 try | |
419 { | |
420 updateKey(); | |
421 this.wait(timeoutMs>0?(end-now):10000); | |
422 } | |
423 catch (final InterruptedException e) | |
424 { | |
425 LOG.warn("",e); | |
426 } | |
427 finally | |
428 { | |
429 now=_selectSet.getNow(); | |
430 } | |
431 if (_writeBlocked && timeoutMs>0 && now>=end) | |
432 return false; | |
433 } | |
434 } | |
435 finally | |
436 { | |
437 _writeBlocked=false; | |
438 setCheckForIdle(check); | |
439 } | |
440 } | |
441 return true; | |
442 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
443 |
865 | 444 /* ------------------------------------------------------------ */ |
445 public boolean hasProgressed() | |
446 { | |
447 return false; | |
448 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
449 |
865 | 450 /* ------------------------------------------------------------ */ |
451 /** | |
452 * Updates selection key. Adds operations types to the selection key as needed. No operations | |
453 * are removed as this is only done during dispatch. This method records the new key and | |
454 * schedules a call to doUpdateKey to do the keyChange | |
455 */ | |
456 private void updateKey() | |
457 { | |
458 final boolean changed; | |
459 synchronized (this) | |
460 { | |
461 int current_ops=-1; | |
462 if (getChannel().isOpen()) | |
463 { | |
464 boolean read_interest = _readBlocked || (_state<STATE_DISPATCHED && !_connection.isSuspended()); | |
465 boolean write_interest= _writeBlocked || (_state<STATE_DISPATCHED && !_writable); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
466 |
865 | 467 _interestOps = |
468 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0) | |
469 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0); | |
470 try | |
471 { | |
472 current_ops = ((_key!=null && _key.isValid())?_key.interestOps():-1); | |
473 } | |
474 catch(Exception e) | |
475 { | |
476 _key=null; | |
477 LOG.trace("",e); | |
478 } | |
479 } | |
480 changed=_interestOps!=current_ops; | |
481 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
482 |
865 | 483 if(changed) |
484 { | |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
485 doUpdateKey(); |
950 | 486 _selectSet.getSelector().update(); |
865 | 487 } |
488 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
489 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
490 |
865 | 491 /* ------------------------------------------------------------ */ |
492 /** | |
493 * Synchronize the interestOps with the actual key. Call is scheduled by a call to updateKey | |
494 */ | |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
495 synchronized void doUpdateKey() |
865 | 496 { |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
497 if (getChannel().isOpen()) |
865 | 498 { |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
499 if (_interestOps>0) |
865 | 500 { |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
501 if (_key==null || !_key.isValid()) |
865 | 502 { |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
503 SelectableChannel sc = (SelectableChannel)getChannel(); |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
504 if (sc.isRegistered()) |
865 | 505 { |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
506 updateKey(); |
865 | 507 } |
508 else | |
509 { | |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
510 try |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
511 { |
950 | 512 _key = _selectSet.getSelector().register((SelectableChannel)getChannel(),_interestOps,this); |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
513 } |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
514 catch (Exception e) |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
515 { |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
516 LOG.trace("",e); |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
517 if (_key!=null && _key.isValid()) |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
518 { |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
519 _key.cancel(); |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
520 } |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
521 |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
522 if (_open) |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
523 { |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
524 _selectSet.destroyEndPoint(this); |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
525 } |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
526 _open=false; |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
527 _key = null; |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
528 } |
865 | 529 } |
530 } | |
531 else | |
532 { | |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
533 _key.interestOps(_interestOps); |
865 | 534 } |
535 } | |
536 else | |
537 { | |
538 if (_key!=null && _key.isValid()) | |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
539 _key.interestOps(0); |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
540 else |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
541 _key=null; |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
542 } |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
543 } |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
544 else |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
545 { |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
546 if (_key!=null && _key.isValid()) |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
547 _key.cancel(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
548 |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
549 if (_open) |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
550 { |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
551 _open=false; |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
552 _selectSet.destroyEndPoint(this); |
865 | 553 } |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
554 _key = null; |
865 | 555 } |
556 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
557 |
865 | 558 /* ------------------------------------------------------------ */ |
559 /* | |
560 */ | |
561 protected void handle() | |
562 { | |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
563 boolean dispatched = true; |
865 | 564 try |
565 { | |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
566 try |
865 | 567 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
568 while(true) |
865 | 569 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
570 final AsyncConnection next = (AsyncConnection)_connection.handle(); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
571 if (next!=_connection) |
865 | 572 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
573 LOG.debug("{} replaced {}",next,_connection); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
574 _connection=next; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
575 continue; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
576 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
577 break; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
578 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
579 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
580 catch (ClosedChannelException e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
581 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
582 LOG.trace("",e); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
583 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
584 catch (EofException e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
585 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
586 LOG.debug("EOF", e); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
587 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
588 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
589 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
590 catch (IOException e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
591 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
592 LOG.warn(e.toString()); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
593 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
594 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
595 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
596 catch (Throwable e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
597 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
598 LOG.warn("handle failed", e); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
599 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
600 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
601 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
602 finally |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
603 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
604 if (!_ishut && isInputShutdown() && isOpen()) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
605 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
606 _ishut = true; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
607 try |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
608 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
609 _connection.onInputShutdown(); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
610 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
611 catch(Throwable x) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
612 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
613 LOG.warn("onInputShutdown failed", x); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
614 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
615 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
616 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
617 finally |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
618 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
619 updateKey(); |
865 | 620 } |
621 } | |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
622 undispatch(); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
623 dispatched = false; |
865 | 624 } |
625 } | |
626 finally | |
627 { | |
628 if (dispatched) | |
629 { | |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
630 undispatch(); |
865 | 631 } |
632 } | |
633 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
634 |
865 | 635 /* ------------------------------------------------------------ */ |
636 /* | |
637 * @see org.eclipse.io.nio.ChannelEndPoint#close() | |
638 */ | |
639 @Override | |
640 public void close() throws IOException | |
641 { | |
642 try | |
643 { | |
644 super.close(); | |
645 } | |
646 catch (IOException e) | |
647 { | |
648 LOG.trace("",e); | |
649 } | |
650 finally | |
651 { | |
652 updateKey(); | |
653 } | |
654 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
655 |
865 | 656 /* ------------------------------------------------------------ */ |
657 @Override | |
658 public String toString() | |
659 { | |
660 // Do NOT use synchronized (this) | |
661 // because it's very easy to deadlock when debugging is enabled. | |
662 // We do a best effort to print the right toString() and that's it. | |
663 SelectionKey key = _key; | |
664 String keyString = ""; | |
665 if (key != null) | |
666 { | |
667 if (key.isValid()) | |
668 { | |
669 if (key.isReadable()) | |
670 keyString += "r"; | |
671 if (key.isWritable()) | |
672 keyString += "w"; | |
673 } | |
674 else | |
675 { | |
676 keyString += "!"; | |
677 } | |
678 } | |
679 else | |
680 { | |
681 keyString += "-"; | |
682 } | |
683 return String.format("SCEP@%x{l(%s)<->r(%s),s=%d,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%d%s}-{%s}", | |
684 hashCode(), | |
685 _socket.getRemoteSocketAddress(), | |
686 _socket.getLocalSocketAddress(), | |
687 _state, | |
688 isOpen(), | |
689 isInputShutdown(), | |
690 isOutputShutdown(), | |
691 _readBlocked, | |
692 _writeBlocked, | |
693 _writable, | |
694 _interestOps, | |
695 keyString, | |
696 _connection); | |
697 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
698 |
865 | 699 /* ------------------------------------------------------------ */ |
700 /** | |
701 * Don't set the SoTimeout | |
702 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#setMaxIdleTime(int) | |
703 */ | |
704 @Override | |
705 public void setMaxIdleTime(int timeMs) throws IOException | |
706 { | |
707 _maxIdleTime=timeMs; | |
708 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
709 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
710 } |