Mercurial Hosting > luan
annotate src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java @ 959:7b94f5b33c64
remove onClose()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 13 Oct 2016 18:53:26 -0600 |
parents | 1094975d013b |
children | 3cd4c706a61f |
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 */ |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
44 public final class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPoint, ConnectedEndPoint |
802
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 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
67 private static final int STATE_NEEDS_DISPATCH = -1; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
68 private static final int STATE_UNDISPATCHED = 0; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
69 private static final int STATE_DISPATCHED = 1; |
865 | 70 private int _state; |
71 | |
72 /** true if the last write operation succeed and wrote all offered bytes */ | |
73 private volatile boolean _writable = true; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
74 |
865 | 75 /** True if a thread has is blocked in {@link #blockReadable(long)} */ |
76 private boolean _readBlocked; | |
802
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 #blockWritable(long)} */ |
79 private boolean _writeBlocked; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
80 |
865 | 81 private boolean _ishut; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
82 |
865 | 83 public SelectChannelEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key, int maxIdleTime) |
84 throws IOException | |
85 { | |
86 super(channel, maxIdleTime); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
87 |
865 | 88 _manager = selectSet.getManager(); |
89 _selectSet = selectSet; | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
90 _state = STATE_UNDISPATCHED; |
865 | 91 _key = key; |
92 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
93 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
94 @Override |
865 | 95 public Connection getConnection() |
96 { | |
97 return _connection; | |
98 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
99 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
100 @Override |
865 | 101 public void setConnection(Connection connection) |
102 { | |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
103 _connection = (AsyncConnection)connection; |
865 | 104 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
105 |
865 | 106 /* ------------------------------------------------------------ */ |
107 /** Called by selectSet to schedule handling | |
108 * | |
109 */ | |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
110 public synchronized void schedule() |
865 | 111 { |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
112 // If there is no key, then do nothing |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
113 if (_key == null || !_key.isValid()) |
865 | 114 { |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
115 _readBlocked = false; |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
116 _writeBlocked = false; |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
117 this.notifyAll(); |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
118 return; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
119 } |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
120 |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
121 // If there are threads dispatched reading and writing |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
122 if (_readBlocked || _writeBlocked) |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
123 { |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
124 // assert _dispatched; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
125 if (_readBlocked && _key.isReadable()) |
865 | 126 _readBlocked=false; |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
127 if (_writeBlocked && _key.isWritable()) |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
128 _writeBlocked = false; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
129 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
130 // wake them up is as good as a dispatched. |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
131 this.notifyAll(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
132 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
133 // we are not interested in further selecting |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
134 _key.interestOps(0); |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
135 if (_state<STATE_DISPATCHED) |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
136 updateKey(); |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
137 return; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
138 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
139 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
140 // Remove writeable op |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
141 if ((_key.readyOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE && (_key.interestOps() & SelectionKey.OP_WRITE) == SelectionKey.OP_WRITE) |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
142 { |
865 | 143 // Remove writeable op |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
144 _interestOps = _key.interestOps() & ~SelectionKey.OP_WRITE; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
145 _key.interestOps(_interestOps); |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
146 _writable = true; // Once writable is in ops, only removed with dispatch. |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
147 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
148 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
149 // If dispatched, then deregister interest |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
150 if (_state>=STATE_DISPATCHED) |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
151 _key.interestOps(0); |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
152 else |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
153 { |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
154 // other wise do the dispatch |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
155 dispatch(); |
865 | 156 } |
157 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
158 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
159 @Override |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
160 public synchronized void dispatch() |
865 | 161 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
162 if (_state<=STATE_UNDISPATCHED) |
865 | 163 { |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
164 _state = STATE_DISPATCHED; |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
165 try { |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
166 _manager.execute(_handler); |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
167 } catch(RejectedExecutionException e) { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
168 _state = STATE_NEEDS_DISPATCH; |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
169 LOG.warn("Dispatched Failed! "+this+" to "+_manager); |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
170 updateKey(); |
865 | 171 } |
172 } | |
173 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
174 |
865 | 175 /* ------------------------------------------------------------ */ |
176 /** | |
177 * Called when a dispatched thread is no longer handling the endpoint. | |
178 * The selection key operations are updated. | |
179 * @return If false is returned, the endpoint has been redispatched and | |
180 * thread must keep handling the endpoint. | |
181 */ | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
182 private synchronized void undispatch() |
865 | 183 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
184 _state = STATE_UNDISPATCHED; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
185 updateKey(); |
865 | 186 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
187 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
188 @Override |
865 | 189 public int fill(Buffer buffer) throws IOException |
190 { | |
191 int fill=super.fill(buffer); | |
192 return fill; | |
193 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
194 |
865 | 195 @Override |
196 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException | |
197 { | |
198 int l = super.flush(header, buffer, trailer); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
199 |
865 | 200 // If there was something to write and it wasn't written, then we are not writable. |
201 if (l==0 && ( header!=null && header.hasContent() || buffer!=null && buffer.hasContent() || trailer!=null && trailer.hasContent())) | |
202 { | |
203 synchronized (this) | |
204 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
205 _writable = false; |
865 | 206 if (_state<STATE_DISPATCHED) |
207 updateKey(); | |
208 } | |
209 } | |
210 else if (l>0) | |
211 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
212 _writable = true; |
865 | 213 } |
214 return l; | |
215 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
216 |
865 | 217 @Override |
218 public int flush(Buffer buffer) throws IOException | |
219 { | |
220 int l = super.flush(buffer); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
221 |
865 | 222 // If there was something to write and it wasn't written, then we are not writable. |
223 if (l==0 && buffer!=null && buffer.hasContent()) | |
224 { | |
225 synchronized (this) | |
226 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
227 _writable = false; |
865 | 228 if (_state<STATE_DISPATCHED) |
229 updateKey(); | |
230 } | |
231 } | |
232 else if (l>0) | |
233 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
234 _writable = true; |
865 | 235 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
236 |
865 | 237 return l; |
238 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
239 |
865 | 240 /* ------------------------------------------------------------ */ |
241 /* | |
242 * Allows thread to block waiting for further events. | |
243 */ | |
244 @Override | |
245 public boolean blockReadable(long timeoutMs) throws IOException | |
246 { | |
247 synchronized (this) | |
248 { | |
249 if (isInputShutdown()) | |
250 throw new EofException(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
251 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
252 long now = _selectSet.getNow(); |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
253 long end = now+timeoutMs; |
865 | 254 try |
255 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
256 _readBlocked = true; |
865 | 257 while (!isInputShutdown() && _readBlocked) |
258 { | |
259 try | |
260 { | |
261 updateKey(); | |
262 this.wait(timeoutMs>0?(end-now):10000); | |
263 } | |
264 catch (final InterruptedException e) | |
265 { | |
266 LOG.warn("",e); | |
267 } | |
268 finally | |
269 { | |
270 now=_selectSet.getNow(); | |
271 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
272 |
865 | 273 if (_readBlocked && timeoutMs>0 && now>=end) |
274 return false; | |
275 } | |
276 } | |
277 finally | |
278 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
279 _readBlocked = false; |
865 | 280 } |
281 } | |
282 return true; | |
283 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
284 |
865 | 285 /* ------------------------------------------------------------ */ |
286 /* | |
287 * Allows thread to block waiting for further events. | |
288 */ | |
289 @Override | |
290 public boolean blockWritable(long timeoutMs) throws IOException | |
291 { | |
292 synchronized (this) | |
293 { | |
294 if (isOutputShutdown()) | |
295 throw new EofException(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
296 |
865 | 297 long now=_selectSet.getNow(); |
298 long end=now+timeoutMs; | |
299 try | |
300 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
301 _writeBlocked = true; |
865 | 302 while (_writeBlocked && !isOutputShutdown()) |
303 { | |
304 try | |
305 { | |
306 updateKey(); | |
307 this.wait(timeoutMs>0?(end-now):10000); | |
308 } | |
309 catch (final InterruptedException e) | |
310 { | |
311 LOG.warn("",e); | |
312 } | |
313 finally | |
314 { | |
315 now=_selectSet.getNow(); | |
316 } | |
317 if (_writeBlocked && timeoutMs>0 && now>=end) | |
318 return false; | |
319 } | |
320 } | |
321 finally | |
322 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
323 _writeBlocked = false; |
865 | 324 } |
325 } | |
326 return true; | |
327 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
328 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
329 @Override |
865 | 330 public boolean hasProgressed() |
331 { | |
332 return false; | |
333 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
334 |
865 | 335 /* ------------------------------------------------------------ */ |
336 /** | |
337 * Updates selection key. Adds operations types to the selection key as needed. No operations | |
338 * are removed as this is only done during dispatch. This method records the new key and | |
339 * schedules a call to doUpdateKey to do the keyChange | |
340 */ | |
341 private void updateKey() | |
342 { | |
343 final boolean changed; | |
344 synchronized (this) | |
345 { | |
346 int current_ops=-1; | |
347 if (getChannel().isOpen()) | |
348 { | |
349 boolean read_interest = _readBlocked || (_state<STATE_DISPATCHED && !_connection.isSuspended()); | |
350 boolean write_interest= _writeBlocked || (_state<STATE_DISPATCHED && !_writable); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
351 |
865 | 352 _interestOps = |
353 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0) | |
354 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0); | |
355 try | |
356 { | |
357 current_ops = ((_key!=null && _key.isValid())?_key.interestOps():-1); | |
358 } | |
359 catch(Exception e) | |
360 { | |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
361 _key = null; |
865 | 362 LOG.trace("",e); |
363 } | |
364 } | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
365 changed = _interestOps!=current_ops; |
865 | 366 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
367 |
865 | 368 if(changed) |
369 { | |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
370 doUpdateKey(); |
950 | 371 _selectSet.getSelector().update(); |
865 | 372 } |
373 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
374 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
375 |
865 | 376 /* ------------------------------------------------------------ */ |
377 /** | |
378 * Synchronize the interestOps with the actual key. Call is scheduled by a call to updateKey | |
379 */ | |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
380 synchronized void doUpdateKey() |
865 | 381 { |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
382 if (getChannel().isOpen()) |
865 | 383 { |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
384 if (_interestOps>0) |
865 | 385 { |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
386 if (_key==null || !_key.isValid()) |
865 | 387 { |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
388 SelectableChannel sc = (SelectableChannel)getChannel(); |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
389 if (sc.isRegistered()) |
865 | 390 { |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
391 updateKey(); |
865 | 392 } |
393 else | |
394 { | |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
395 try |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
396 { |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
397 _key = _selectSet.getSelector().register(sc,_interestOps,this); |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
398 } |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
399 catch (Exception e) |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
400 { |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
401 LOG.trace("",e); |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
402 if (_key!=null && _key.isValid()) |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
403 { |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
404 _key.cancel(); |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
405 } |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
406 |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
407 _key = null; |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
408 } |
865 | 409 } |
410 } | |
411 else | |
412 { | |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
413 _key.interestOps(_interestOps); |
865 | 414 } |
415 } | |
416 else | |
417 { | |
418 if (_key!=null && _key.isValid()) | |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
419 _key.interestOps(0); |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
420 else |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
421 _key = null; |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
422 } |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
423 } |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
424 else |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
425 { |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
426 if (_key!=null && _key.isValid()) |
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
427 _key.cancel(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
428 |
949
e9088af3787f
remove SelectSet._changes
Franklin Schmidt <fschmidt@gmail.com>
parents:
948
diff
changeset
|
429 _key = null; |
865 | 430 } |
431 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
432 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
433 private void handle() |
865 | 434 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
435 boolean dispatched = true; |
865 | 436 try |
437 { | |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
438 try |
865 | 439 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
440 while(true) |
865 | 441 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
442 final AsyncConnection next = (AsyncConnection)_connection.handle(); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
443 if (next!=_connection) |
865 | 444 { |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
445 LOG.debug("{} replaced {}",next,_connection); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
446 _connection=next; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
447 continue; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
448 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
449 break; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
450 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
451 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
452 catch (ClosedChannelException e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
453 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
454 LOG.trace("",e); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
455 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
456 catch (EofException e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
457 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
458 LOG.debug("EOF", e); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
459 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
460 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
461 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
462 catch (IOException e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
463 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
464 LOG.warn(e.toString()); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
465 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
466 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
467 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
468 catch (Throwable e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
469 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
470 LOG.warn("handle failed", e); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
471 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
472 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
473 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
474 finally |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
475 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
476 if (!_ishut && isInputShutdown() && isOpen()) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
477 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
478 _ishut = true; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
479 try |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
480 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
481 _connection.onInputShutdown(); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
482 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
483 catch(Throwable x) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
484 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
485 LOG.warn("onInputShutdown failed", x); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
486 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
487 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
488 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
489 finally |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
490 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
491 updateKey(); |
865 | 492 } |
493 } | |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
494 undispatch(); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
495 dispatched = false; |
865 | 496 } |
497 } | |
498 finally | |
499 { | |
500 if (dispatched) | |
501 { | |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
502 undispatch(); |
865 | 503 } |
504 } | |
505 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
506 |
865 | 507 /* ------------------------------------------------------------ */ |
508 /* | |
509 * @see org.eclipse.io.nio.ChannelEndPoint#close() | |
510 */ | |
511 @Override | |
512 public void close() throws IOException | |
513 { | |
514 try | |
515 { | |
516 super.close(); | |
517 } | |
518 catch (IOException e) | |
519 { | |
520 LOG.trace("",e); | |
521 } | |
522 finally | |
523 { | |
524 updateKey(); | |
525 } | |
526 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
527 |
865 | 528 @Override |
529 public String toString() | |
530 { | |
531 // Do NOT use synchronized (this) | |
532 // because it's very easy to deadlock when debugging is enabled. | |
533 // We do a best effort to print the right toString() and that's it. | |
534 SelectionKey key = _key; | |
535 String keyString = ""; | |
536 if (key != null) | |
537 { | |
538 if (key.isValid()) | |
539 { | |
540 if (key.isReadable()) | |
541 keyString += "r"; | |
542 if (key.isWritable()) | |
543 keyString += "w"; | |
544 } | |
545 else | |
546 { | |
547 keyString += "!"; | |
548 } | |
549 } | |
550 else | |
551 { | |
552 keyString += "-"; | |
553 } | |
554 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}", | |
555 hashCode(), | |
556 _socket.getRemoteSocketAddress(), | |
557 _socket.getLocalSocketAddress(), | |
558 _state, | |
559 isOpen(), | |
560 isInputShutdown(), | |
561 isOutputShutdown(), | |
562 _readBlocked, | |
563 _writeBlocked, | |
564 _writable, | |
565 _interestOps, | |
566 keyString, | |
567 _connection); | |
568 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
569 |
865 | 570 /* ------------------------------------------------------------ */ |
571 /** | |
572 * Don't set the SoTimeout | |
573 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#setMaxIdleTime(int) | |
574 */ | |
575 @Override | |
576 public void setMaxIdleTime(int timeMs) throws IOException | |
577 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
578 _maxIdleTime = timeMs; |
865 | 579 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
580 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
581 } |