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