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