Mercurial Hosting > luan
annotate src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java @ 967:8a8dc0b1742f
remove getConnection()
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 14 Oct 2016 02:30:48 -0600 |
parents | 866f2e801618 |
children | 0d20943cfea2 |
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; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
35 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
802
diff
changeset
|
36 import org.slf4j.LoggerFactory; |
940
b77d631b9e28
remove scheduleTimeout() and cancelTimeout()
Franklin Schmidt <fschmidt@gmail.com>
parents:
915
diff
changeset
|
37 |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 |
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 * An Endpoint that can be scheduled by {@link SelectorManager}. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 */ |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
43 public final class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPoint, ConnectedEndPoint |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 { |
865 | 45 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
|
46 |
865 | 47 private final SelectorManager _manager; |
961
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
48 private final SelectionKey _key; |
865 | 49 private final Runnable _handler = new Runnable() |
50 { | |
51 public void run() { handle(); } | |
52 }; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 |
865 | 54 /** |
55 * The connection instance is the handler for any IO activity on the endpoint. | |
56 * There is a different type of connection for HTTP, AJP, WebSocket and | |
57 * ProxyConnect. The connection may change for an SCEP as it is upgraded | |
58 * from HTTP to proxy connect or websocket. | |
59 */ | |
60 private volatile AsyncConnection _connection; | |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
61 /* |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
62 private static final int STATE_NEEDS_DISPATCH = -1; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
63 private static final int STATE_UNDISPATCHED = 0; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
64 private static final int STATE_DISPATCHED = 1; |
865 | 65 private int _state; |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
66 */ |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
67 private boolean isDispatched = false; |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
68 |
865 | 69 /** true if the last write operation succeed and wrote all offered bytes */ |
70 private volatile boolean _writable = true; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
71 |
865 | 72 /** True if a thread has is blocked in {@link #blockReadable(long)} */ |
73 private boolean _readBlocked; | |
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 #blockWritable(long)} */ |
76 private boolean _writeBlocked; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
77 |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
78 private boolean _ishut = false; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
79 |
964 | 80 public SelectChannelEndPoint(SocketChannel channel, SelectorManager manager, SelectionKey key, int maxIdleTime) |
865 | 81 throws IOException |
82 { | |
83 super(channel, maxIdleTime); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
84 |
964 | 85 _manager = manager; |
865 | 86 _key = key; |
87 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
88 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
89 @Override |
865 | 90 public void setConnection(Connection connection) |
91 { | |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
92 _connection = (AsyncConnection)connection; |
865 | 93 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
94 |
865 | 95 /* ------------------------------------------------------------ */ |
96 /** Called by selectSet to schedule handling | |
97 * | |
98 */ | |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
99 public synchronized void schedule() |
865 | 100 { |
961
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
101 if (!_key.isValid()) |
865 | 102 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
103 /* |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
104 _readBlocked = false; |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
105 _writeBlocked = false; |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
106 this.notifyAll(); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
107 */ |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
108 _key.cancel(); |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
109 return; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
110 } |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
111 |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
112 // If there are threads dispatched reading and writing |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
113 if (_readBlocked || _writeBlocked) |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
114 { |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
115 // assert _dispatched; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
116 if (_readBlocked && _key.isReadable()) |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
117 _readBlocked = false; |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
118 if (_writeBlocked && _key.isWritable()) |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
119 _writeBlocked = false; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
120 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
121 // wake them up is as good as a dispatched. |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
122 this.notifyAll(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
123 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
124 // we are not interested in further selecting |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
125 _key.interestOps(0); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
126 if( !isDispatched ) |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
127 updateKey(); |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
128 return; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
129 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
130 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
131 // Remove writeable op |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
132 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
|
133 { |
865 | 134 // Remove writeable op |
962
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
135 int interestOps = _key.interestOps() & ~SelectionKey.OP_WRITE; |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
136 _key.interestOps(interestOps); |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
137 _writable = true; // Once writable is in ops, only removed with dispatch. |
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 // If dispatched, then deregister interest |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
141 if (isDispatched) |
953
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 else |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
144 { |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
145 // other wise do the dispatch |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
146 dispatch(); |
865 | 147 } |
148 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
149 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
150 @Override |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
151 public synchronized void dispatch() |
865 | 152 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
153 if( !isDispatched ) |
865 | 154 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
155 isDispatched = true; |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
156 try { |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
157 _manager.execute(_handler); |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
158 } catch(RejectedExecutionException e) { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
159 isDispatched = false; |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
160 LOG.warn("Dispatched Failed! "+this+" to "+_manager); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
161 // updateKey(); |
865 | 162 } |
163 } | |
164 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
165 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
166 @Override |
865 | 167 public int fill(Buffer buffer) throws IOException |
168 { | |
169 int fill=super.fill(buffer); | |
170 return fill; | |
171 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
172 |
865 | 173 @Override |
174 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException | |
175 { | |
176 int l = super.flush(header, buffer, trailer); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
177 |
865 | 178 // If there was something to write and it wasn't written, then we are not writable. |
179 if (l==0 && ( header!=null && header.hasContent() || buffer!=null && buffer.hasContent() || trailer!=null && trailer.hasContent())) | |
180 { | |
181 synchronized (this) | |
182 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
183 _writable = false; |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
184 if( !isDispatched ) |
865 | 185 updateKey(); |
186 } | |
187 } | |
188 else if (l>0) | |
189 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
190 _writable = true; |
865 | 191 } |
192 return l; | |
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 buffer) throws IOException | |
197 { | |
198 int l = super.flush(buffer); | |
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 && buffer!=null && buffer.hasContent()) | |
202 { | |
203 synchronized (this) | |
204 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
205 _writable = false; |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
206 if( !isDispatched ) |
865 | 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 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
214 |
865 | 215 return l; |
216 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
217 |
865 | 218 /* ------------------------------------------------------------ */ |
219 /* | |
220 * Allows thread to block waiting for further events. | |
221 */ | |
222 @Override | |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
223 public synchronized boolean blockReadable(long timeoutMs) throws IOException |
865 | 224 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
225 if (isInputShutdown()) |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
226 throw new EofException(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
227 |
964 | 228 long now = _manager.getNow(); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
229 long end = now+timeoutMs; |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
230 try |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
231 { |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
232 _readBlocked = true; |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
233 while (!isInputShutdown() && _readBlocked) |
865 | 234 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
235 try |
865 | 236 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
237 updateKey(); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
238 this.wait(timeoutMs>0?(end-now):10000); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
239 } |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
240 catch (final InterruptedException e) |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
241 { |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
242 LOG.warn("",e); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
243 } |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
244 finally |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
245 { |
964 | 246 now = _manager.getNow(); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
247 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
248 |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
249 if (_readBlocked && timeoutMs>0 && now>=end) |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
250 return false; |
865 | 251 } |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
252 } |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
253 finally |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
254 { |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
255 _readBlocked = false; |
865 | 256 } |
257 return true; | |
258 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
259 |
865 | 260 /* ------------------------------------------------------------ */ |
261 /* | |
262 * Allows thread to block waiting for further events. | |
263 */ | |
264 @Override | |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
265 public synchronized boolean blockWritable(long timeoutMs) throws IOException |
865 | 266 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
267 if (isOutputShutdown()) |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
268 throw new EofException(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
269 |
964 | 270 long now=_manager.getNow(); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
271 long end=now+timeoutMs; |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
272 try |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
273 { |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
274 _writeBlocked = true; |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
275 while (_writeBlocked && !isOutputShutdown()) |
865 | 276 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
277 try |
865 | 278 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
279 updateKey(); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
280 this.wait(timeoutMs>0?(end-now):10000); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
281 } |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
282 catch (final InterruptedException e) |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
283 { |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
284 LOG.warn("",e); |
865 | 285 } |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
286 finally |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
287 { |
964 | 288 now = _manager.getNow(); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
289 } |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
290 if (_writeBlocked && timeoutMs>0 && now>=end) |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
291 return false; |
865 | 292 } |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
293 } |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
294 finally |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
295 { |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
296 _writeBlocked = false; |
865 | 297 } |
298 return true; | |
299 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
300 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
301 @Override |
865 | 302 public boolean hasProgressed() |
303 { | |
304 return false; | |
305 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
306 |
865 | 307 /* ------------------------------------------------------------ */ |
308 /** | |
309 * Updates selection key. Adds operations types to the selection key as needed. No operations | |
310 * are removed as this is only done during dispatch. This method records the new key and | |
311 * schedules a call to doUpdateKey to do the keyChange | |
312 */ | |
962
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
313 private synchronized void updateKey() |
865 | 314 { |
962
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
315 if( getChannel().isOpen() && _key.isValid()) |
865 | 316 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
317 boolean read_interest = _readBlocked || (!isDispatched && !_connection.isSuspended()); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
318 boolean write_interest = _writeBlocked || (!isDispatched && !_writable); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
319 // boolean write_interest = _writeBlocked || !isDispatched; |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
320 // boolean write_interest = true; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
321 |
962
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
322 int interestOps = |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
323 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0) |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
324 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0); |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
325 if( _key.interestOps() != interestOps ) { |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
326 _key.interestOps(interestOps); |
964 | 327 _manager.getSelector().update(); |
865 | 328 } |
962
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
329 } else { |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
330 _key.cancel(); |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
331 // update needed? |
865 | 332 } |
333 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
334 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
335 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
336 private void handle() |
865 | 337 { |
338 try | |
339 { | |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
340 try |
865 | 341 { |
965
866f2e801618
handle() returns void
Franklin Schmidt <fschmidt@gmail.com>
parents:
964
diff
changeset
|
342 _connection.handle(); |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
343 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
344 catch (ClosedChannelException e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
345 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
346 LOG.trace("",e); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
347 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
348 catch (EofException e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
349 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
350 LOG.debug("EOF", e); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
351 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
352 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
353 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
354 catch (IOException e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
355 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
356 LOG.warn(e.toString()); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
357 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
358 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
359 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
360 catch (Throwable e) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
361 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
362 LOG.warn("handle failed", e); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
363 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
364 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
365 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
366 finally |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
367 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
368 if (!_ishut && isInputShutdown() && isOpen()) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
369 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
370 _ishut = true; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
371 try |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
372 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
373 _connection.onInputShutdown(); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
374 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
375 catch(Throwable x) |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
376 { |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
377 LOG.warn("onInputShutdown failed", x); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
378 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
379 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
380 } |
865 | 381 } |
382 } | |
383 } | |
384 finally | |
385 { | |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
386 isDispatched = false; |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
959
diff
changeset
|
387 updateKey(); |
865 | 388 } |
389 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
390 |
865 | 391 @Override |
392 public void close() throws IOException | |
393 { | |
394 try | |
395 { | |
396 super.close(); | |
397 } | |
398 catch (IOException e) | |
399 { | |
400 LOG.trace("",e); | |
401 } | |
402 finally | |
403 { | |
404 updateKey(); | |
405 } | |
406 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
407 |
865 | 408 @Override |
409 public String toString() | |
410 { | |
411 // Do NOT use synchronized (this) | |
412 // because it's very easy to deadlock when debugging is enabled. | |
413 // We do a best effort to print the right toString() and that's it. | |
414 SelectionKey key = _key; | |
415 String keyString = ""; | |
961
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
416 if (key.isValid()) |
865 | 417 { |
961
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
418 if (key.isReadable()) |
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
419 keyString += "r"; |
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
420 if (key.isWritable()) |
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
421 keyString += "w"; |
865 | 422 } |
423 else | |
424 { | |
961
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
425 keyString += "!"; |
865 | 426 } |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
427 return String.format("SCEP@%x{l(%s)<->r(%s),dispatched=%b,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%s}-{%s}", |
865 | 428 hashCode(), |
429 _socket.getRemoteSocketAddress(), | |
430 _socket.getLocalSocketAddress(), | |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
431 isDispatched, |
865 | 432 isOpen(), |
433 isInputShutdown(), | |
434 isOutputShutdown(), | |
435 _readBlocked, | |
436 _writeBlocked, | |
437 _writable, | |
438 keyString, | |
439 _connection); | |
440 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
441 |
865 | 442 /* ------------------------------------------------------------ */ |
443 /** | |
444 * Don't set the SoTimeout | |
445 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#setMaxIdleTime(int) | |
446 */ | |
447 @Override | |
448 public void setMaxIdleTime(int timeMs) throws IOException | |
449 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
450 _maxIdleTime = timeMs; |
865 | 451 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
452 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
453 } |