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