comparison src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java @ 964:768414c16e10

remove SelectSet
author Franklin Schmidt <fschmidt@gmail.com>
date Fri, 14 Oct 2016 01:03:47 -0600
parents 4b6216fa9cec
children 866f2e801618
comparison
equal deleted inserted replaced
963:4b6216fa9cec 964:768414c16e10
30 import org.eclipse.jetty.io.AsyncEndPoint; 30 import org.eclipse.jetty.io.AsyncEndPoint;
31 import org.eclipse.jetty.io.Buffer; 31 import org.eclipse.jetty.io.Buffer;
32 import org.eclipse.jetty.io.ConnectedEndPoint; 32 import org.eclipse.jetty.io.ConnectedEndPoint;
33 import org.eclipse.jetty.io.Connection; 33 import org.eclipse.jetty.io.Connection;
34 import org.eclipse.jetty.io.EofException; 34 import org.eclipse.jetty.io.EofException;
35 import org.eclipse.jetty.io.nio.SelectorManager.SelectSet;
36 import org.slf4j.Logger; 35 import org.slf4j.Logger;
37 import org.slf4j.LoggerFactory; 36 import org.slf4j.LoggerFactory;
38 37
39 38
40 /* ------------------------------------------------------------ */ 39 /* ------------------------------------------------------------ */
43 */ 42 */
44 public final class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPoint, ConnectedEndPoint 43 public final class SelectChannelEndPoint extends ChannelEndPoint implements AsyncEndPoint, ConnectedEndPoint
45 { 44 {
46 public static final Logger LOG=LoggerFactory.getLogger("org.eclipse.jetty.io.nio"); 45 public static final Logger LOG=LoggerFactory.getLogger("org.eclipse.jetty.io.nio");
47 46
48 private final SelectorManager.SelectSet _selectSet;
49 private final SelectorManager _manager; 47 private final SelectorManager _manager;
50 private final SelectionKey _key; 48 private final SelectionKey _key;
51 private final Runnable _handler = new Runnable() 49 private final Runnable _handler = new Runnable()
52 { 50 {
53 public void run() { handle(); } 51 public void run() { handle(); }
77 /** True if a thread has is blocked in {@link #blockWritable(long)} */ 75 /** True if a thread has is blocked in {@link #blockWritable(long)} */
78 private boolean _writeBlocked; 76 private boolean _writeBlocked;
79 77
80 private boolean _ishut = false; 78 private boolean _ishut = false;
81 79
82 public SelectChannelEndPoint(SocketChannel channel, SelectSet selectSet, SelectionKey key, int maxIdleTime) 80 public SelectChannelEndPoint(SocketChannel channel, SelectorManager manager, SelectionKey key, int maxIdleTime)
83 throws IOException 81 throws IOException
84 { 82 {
85 super(channel, maxIdleTime); 83 super(channel, maxIdleTime);
86 84
87 _manager = selectSet.getManager(); 85 _manager = manager;
88 _selectSet = selectSet;
89 _key = key; 86 _key = key;
90 } 87 }
91 88
92 @Override 89 @Override
93 public Connection getConnection() 90 public Connection getConnection()
232 public synchronized boolean blockReadable(long timeoutMs) throws IOException 229 public synchronized boolean blockReadable(long timeoutMs) throws IOException
233 { 230 {
234 if (isInputShutdown()) 231 if (isInputShutdown())
235 throw new EofException(); 232 throw new EofException();
236 233
237 long now = _selectSet.getNow(); 234 long now = _manager.getNow();
238 long end = now+timeoutMs; 235 long end = now+timeoutMs;
239 try 236 try
240 { 237 {
241 _readBlocked = true; 238 _readBlocked = true;
242 while (!isInputShutdown() && _readBlocked) 239 while (!isInputShutdown() && _readBlocked)
250 { 247 {
251 LOG.warn("",e); 248 LOG.warn("",e);
252 } 249 }
253 finally 250 finally
254 { 251 {
255 now = _selectSet.getNow(); 252 now = _manager.getNow();
256 } 253 }
257 254
258 if (_readBlocked && timeoutMs>0 && now>=end) 255 if (_readBlocked && timeoutMs>0 && now>=end)
259 return false; 256 return false;
260 } 257 }
274 public synchronized boolean blockWritable(long timeoutMs) throws IOException 271 public synchronized boolean blockWritable(long timeoutMs) throws IOException
275 { 272 {
276 if (isOutputShutdown()) 273 if (isOutputShutdown())
277 throw new EofException(); 274 throw new EofException();
278 275
279 long now=_selectSet.getNow(); 276 long now=_manager.getNow();
280 long end=now+timeoutMs; 277 long end=now+timeoutMs;
281 try 278 try
282 { 279 {
283 _writeBlocked = true; 280 _writeBlocked = true;
284 while (_writeBlocked && !isOutputShutdown()) 281 while (_writeBlocked && !isOutputShutdown())
292 { 289 {
293 LOG.warn("",e); 290 LOG.warn("",e);
294 } 291 }
295 finally 292 finally
296 { 293 {
297 now = _selectSet.getNow(); 294 now = _manager.getNow();
298 } 295 }
299 if (_writeBlocked && timeoutMs>0 && now>=end) 296 if (_writeBlocked && timeoutMs>0 && now>=end)
300 return false; 297 return false;
301 } 298 }
302 } 299 }
331 int interestOps = 328 int interestOps =
332 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0) 329 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0)
333 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0); 330 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0);
334 if( _key.interestOps() != interestOps ) { 331 if( _key.interestOps() != interestOps ) {
335 _key.interestOps(interestOps); 332 _key.interestOps(interestOps);
336 _selectSet.getSelector().update(); 333 _manager.getSelector().update();
337 } 334 }
338 } else { 335 } else {
339 _key.cancel(); 336 _key.cancel();
340 // update needed? 337 // update needed?
341 } 338 }