Mercurial Hosting > luan
annotate src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java @ 968:0d20943cfea2
remove ConnectedEndPoint
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Fri, 14 Oct 2016 02:37:53 -0600 |
parents | 8a8dc0b1742f |
children | 0650077fcd6c |
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 */ | |
59 private volatile 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; |
86 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
87 |
865 | 88 public void setConnection(Connection connection) |
89 { | |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
90 _connection = (AsyncConnection)connection; |
865 | 91 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
92 |
865 | 93 /* ------------------------------------------------------------ */ |
94 /** Called by selectSet to schedule handling | |
95 * | |
96 */ | |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
97 public synchronized void schedule() |
865 | 98 { |
961
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
99 if (!_key.isValid()) |
865 | 100 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
101 /* |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
102 _readBlocked = false; |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
103 _writeBlocked = false; |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
104 this.notifyAll(); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
105 */ |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
106 _key.cancel(); |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
107 return; |
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 |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
110 // If there are threads dispatched reading and writing |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
111 if (_readBlocked || _writeBlocked) |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
112 { |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
113 // assert _dispatched; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
114 if (_readBlocked && _key.isReadable()) |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
115 _readBlocked = false; |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
116 if (_writeBlocked && _key.isWritable()) |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
117 _writeBlocked = false; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
118 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
119 // wake them up is as good as a dispatched. |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
120 this.notifyAll(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
121 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
122 // we are not interested in further selecting |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
123 _key.interestOps(0); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
124 if( !isDispatched ) |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
125 updateKey(); |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
126 return; |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
127 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
128 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
129 // Remove writeable op |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
130 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
|
131 { |
865 | 132 // Remove writeable op |
962
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
133 int interestOps = _key.interestOps() & ~SelectionKey.OP_WRITE; |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
134 _key.interestOps(interestOps); |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
135 _writable = true; // Once writable is in ops, only removed with dispatch. |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
136 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
137 |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
138 // If dispatched, then deregister interest |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
139 if (isDispatched) |
953
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
140 _key.interestOps(0); |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
141 else |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
142 { |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
143 // other wise do the dispatch |
7db4a488fc82
simplify SelectorManager
Franklin Schmidt <fschmidt@gmail.com>
parents:
952
diff
changeset
|
144 dispatch(); |
865 | 145 } |
146 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
147 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
148 @Override |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
149 public synchronized void dispatch() |
865 | 150 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
151 if( !isDispatched ) |
865 | 152 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
153 isDispatched = true; |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
154 try { |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
155 _manager.execute(_handler); |
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
156 } catch(RejectedExecutionException e) { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
157 isDispatched = false; |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
158 LOG.warn("Dispatched Failed! "+this+" to "+_manager); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
159 // updateKey(); |
865 | 160 } |
161 } | |
162 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
163 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
164 @Override |
865 | 165 public int fill(Buffer buffer) throws IOException |
166 { | |
167 int fill=super.fill(buffer); | |
168 return fill; | |
169 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
170 |
865 | 171 @Override |
172 public int flush(Buffer header, Buffer buffer, Buffer trailer) throws IOException | |
173 { | |
174 int l = super.flush(header, buffer, trailer); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
175 |
865 | 176 // If there was something to write and it wasn't written, then we are not writable. |
177 if (l==0 && ( header!=null && header.hasContent() || buffer!=null && buffer.hasContent() || trailer!=null && trailer.hasContent())) | |
178 { | |
179 synchronized (this) | |
180 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
181 _writable = false; |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
182 if( !isDispatched ) |
865 | 183 updateKey(); |
184 } | |
185 } | |
186 else if (l>0) | |
187 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
188 _writable = true; |
865 | 189 } |
190 return l; | |
191 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
192 |
865 | 193 @Override |
194 public int flush(Buffer buffer) throws IOException | |
195 { | |
196 int l = super.flush(buffer); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
197 |
865 | 198 // If there was something to write and it wasn't written, then we are not writable. |
199 if (l==0 && buffer!=null && buffer.hasContent()) | |
200 { | |
201 synchronized (this) | |
202 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
203 _writable = false; |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
204 if( !isDispatched ) |
865 | 205 updateKey(); |
206 } | |
207 } | |
208 else if (l>0) | |
209 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
210 _writable = true; |
865 | 211 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
212 |
865 | 213 return l; |
214 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
215 |
865 | 216 /* ------------------------------------------------------------ */ |
217 /* | |
218 * Allows thread to block waiting for further events. | |
219 */ | |
220 @Override | |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
221 public synchronized boolean blockReadable(long timeoutMs) throws IOException |
865 | 222 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
223 if (isInputShutdown()) |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
224 throw new EofException(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
225 |
964 | 226 long now = _manager.getNow(); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
227 long end = now+timeoutMs; |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
228 try |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
229 { |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
230 _readBlocked = true; |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
231 while (!isInputShutdown() && _readBlocked) |
865 | 232 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
233 try |
865 | 234 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
235 updateKey(); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
236 this.wait(timeoutMs>0?(end-now):10000); |
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 catch (final InterruptedException e) |
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 LOG.warn("",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 finally |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
243 { |
964 | 244 now = _manager.getNow(); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
245 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
246 |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
247 if (_readBlocked && timeoutMs>0 && now>=end) |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
248 return false; |
865 | 249 } |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
250 } |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
251 finally |
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 _readBlocked = false; |
865 | 254 } |
255 return true; | |
256 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
257 |
865 | 258 /* ------------------------------------------------------------ */ |
259 /* | |
260 * Allows thread to block waiting for further events. | |
261 */ | |
262 @Override | |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
263 public synchronized boolean blockWritable(long timeoutMs) throws IOException |
865 | 264 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
265 if (isOutputShutdown()) |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
266 throw new EofException(); |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
267 |
964 | 268 long now=_manager.getNow(); |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
269 long end=now+timeoutMs; |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
270 try |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
271 { |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
272 _writeBlocked = true; |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
273 while (_writeBlocked && !isOutputShutdown()) |
865 | 274 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
275 try |
865 | 276 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
277 updateKey(); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
278 this.wait(timeoutMs>0?(end-now):10000); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
279 } |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
280 catch (final InterruptedException e) |
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 LOG.warn("",e); |
865 | 283 } |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
284 finally |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
285 { |
964 | 286 now = _manager.getNow(); |
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 if (_writeBlocked && timeoutMs>0 && now>=end) |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
289 return false; |
865 | 290 } |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
291 } |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
292 finally |
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 _writeBlocked = false; |
865 | 295 } |
296 return true; | |
297 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
298 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
299 @Override |
865 | 300 public boolean hasProgressed() |
301 { | |
302 return false; | |
303 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
304 |
865 | 305 /* ------------------------------------------------------------ */ |
306 /** | |
307 * Updates selection key. Adds operations types to the selection key as needed. No operations | |
308 * are removed as this is only done during dispatch. This method records the new key and | |
309 * schedules a call to doUpdateKey to do the keyChange | |
310 */ | |
962
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
311 private synchronized void updateKey() |
865 | 312 { |
962
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
313 if( getChannel().isOpen() && _key.isValid()) |
865 | 314 { |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
315 boolean read_interest = _readBlocked || (!isDispatched && !_connection.isSuspended()); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
316 boolean write_interest = _writeBlocked || (!isDispatched && !_writable); |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
317 // boolean write_interest = _writeBlocked || !isDispatched; |
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
318 // boolean write_interest = true; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
319 |
962
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
320 int interestOps = |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
321 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0) |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
322 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0); |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
323 if( _key.interestOps() != interestOps ) { |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
324 _key.interestOps(interestOps); |
964 | 325 _manager.getSelector().update(); |
865 | 326 } |
962
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
327 } else { |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
328 _key.cancel(); |
94498d6daf5b
remove SelectChannelEndPoint._interestOps
Franklin Schmidt <fschmidt@gmail.com>
parents:
961
diff
changeset
|
329 // update needed? |
865 | 330 } |
331 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
332 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
333 |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
334 private void handle() |
865 | 335 { |
336 try | |
337 { | |
947
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
338 try |
865 | 339 { |
965
866f2e801618
handle() returns void
Franklin Schmidt <fschmidt@gmail.com>
parents:
964
diff
changeset
|
340 _connection.handle(); |
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 (ClosedChannelException 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.trace("",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 catch (EofException 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 LOG.debug("EOF", e); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
349 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
350 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
351 } |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
352 catch (IOException e) |
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 LOG.warn(e.toString()); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
355 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
356 catch(IOException e2){LOG.trace("",e2);} |
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 catch (Throwable e) |
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 LOG.warn("handle failed", e); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
361 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
362 catch(IOException e2){LOG.trace("",e2);} |
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 finally |
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 if (!_ishut && isInputShutdown() && isOpen()) |
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 _ishut = true; |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
369 try |
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 _connection.onInputShutdown(); |
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 catch(Throwable x) |
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 LOG.warn("onInputShutdown failed", x); |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
376 try{close();} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
377 catch(IOException e2){LOG.trace("",e2);} |
64f3d8dae31d
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
946
diff
changeset
|
378 } |
865 | 379 } |
380 } | |
381 } | |
382 finally | |
383 { | |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
384 isDispatched = false; |
960
3cd4c706a61f
simplify ChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
959
diff
changeset
|
385 updateKey(); |
865 | 386 } |
387 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
388 |
865 | 389 @Override |
390 public void close() throws IOException | |
391 { | |
392 try | |
393 { | |
394 super.close(); | |
395 } | |
396 catch (IOException e) | |
397 { | |
398 LOG.trace("",e); | |
399 } | |
400 finally | |
401 { | |
402 updateKey(); | |
403 } | |
404 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
405 |
865 | 406 @Override |
407 public String toString() | |
408 { | |
409 // Do NOT use synchronized (this) | |
410 // because it's very easy to deadlock when debugging is enabled. | |
411 // We do a best effort to print the right toString() and that's it. | |
412 SelectionKey key = _key; | |
413 String keyString = ""; | |
961
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
414 if (key.isValid()) |
865 | 415 { |
961
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
416 if (key.isReadable()) |
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
417 keyString += "r"; |
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
418 if (key.isWritable()) |
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
419 keyString += "w"; |
865 | 420 } |
421 else | |
422 { | |
961
790c01734386
make SelectChannelEndPoint._key final
Franklin Schmidt <fschmidt@gmail.com>
parents:
960
diff
changeset
|
423 keyString += "!"; |
865 | 424 } |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
425 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 | 426 hashCode(), |
427 _socket.getRemoteSocketAddress(), | |
428 _socket.getLocalSocketAddress(), | |
963
4b6216fa9cec
replace SelectChannelEndPoint._state with isDispatched
Franklin Schmidt <fschmidt@gmail.com>
parents:
962
diff
changeset
|
429 isDispatched, |
865 | 430 isOpen(), |
431 isInputShutdown(), | |
432 isOutputShutdown(), | |
433 _readBlocked, | |
434 _writeBlocked, | |
435 _writable, | |
436 keyString, | |
437 _connection); | |
438 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
439 |
865 | 440 /* ------------------------------------------------------------ */ |
441 /** | |
442 * Don't set the SoTimeout | |
443 * @see org.eclipse.jetty.io.nio.ChannelEndPoint#setMaxIdleTime(int) | |
444 */ | |
445 @Override | |
446 public void setMaxIdleTime(int timeMs) throws IOException | |
447 { | |
955
6f49b8dfffe6
simplify SelectChannelEndPoint
Franklin Schmidt <fschmidt@gmail.com>
parents:
953
diff
changeset
|
448 _maxIdleTime = timeMs; |
865 | 449 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
450 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
451 } |