Mercurial Hosting > luan
comparison src/org/eclipse/jetty/io/nio/SelectChannelEndPoint.java @ 961:790c01734386
make SelectChannelEndPoint._key final
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 13 Oct 2016 22:03:24 -0600 |
parents | 3cd4c706a61f |
children | 94498d6daf5b |
comparison
equal
deleted
inserted
replaced
960:3cd4c706a61f | 961:790c01734386 |
---|---|
45 { | 45 { |
46 public static final Logger LOG=LoggerFactory.getLogger("org.eclipse.jetty.io.nio"); | 46 public static final Logger LOG=LoggerFactory.getLogger("org.eclipse.jetty.io.nio"); |
47 | 47 |
48 private final SelectorManager.SelectSet _selectSet; | 48 private final SelectorManager.SelectSet _selectSet; |
49 private final SelectorManager _manager; | 49 private final SelectorManager _manager; |
50 private SelectionKey _key; | 50 private final SelectionKey _key; |
51 private final Runnable _handler = new Runnable() | 51 private final Runnable _handler = new Runnable() |
52 { | 52 { |
53 public void run() { handle(); } | 53 public void run() { handle(); } |
54 }; | 54 }; |
55 | 55 |
108 * | 108 * |
109 */ | 109 */ |
110 public synchronized void schedule() | 110 public synchronized void schedule() |
111 { | 111 { |
112 // If there is no key, then do nothing | 112 // If there is no key, then do nothing |
113 if (_key == null || !_key.isValid()) | 113 if (!_key.isValid()) |
114 { | 114 { |
115 _readBlocked = false; | 115 _readBlocked = false; |
116 _writeBlocked = false; | 116 _writeBlocked = false; |
117 this.notifyAll(); | 117 this.notifyAll(); |
118 return; | 118 return; |
339 _interestOps = | 339 _interestOps = |
340 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0) | 340 ((!_socket.isInputShutdown() && read_interest ) ? SelectionKey.OP_READ : 0) |
341 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0); | 341 | ((!_socket.isOutputShutdown()&& write_interest) ? SelectionKey.OP_WRITE : 0); |
342 try | 342 try |
343 { | 343 { |
344 current_ops = ((_key!=null && _key.isValid())?_key.interestOps():-1); | 344 current_ops = ((_key.isValid())?_key.interestOps():-1); |
345 } | 345 } |
346 catch(Exception e) | 346 catch(Exception e) |
347 { | 347 { |
348 _key = null; | 348 _key.cancel(); |
349 LOG.trace("",e); | 349 LOG.trace("",e); |
350 } | 350 } |
351 } | 351 } |
352 changed = _interestOps!=current_ops; | 352 changed = _interestOps!=current_ops; |
353 } | 353 } |
366 */ | 366 */ |
367 synchronized void doUpdateKey() | 367 synchronized void doUpdateKey() |
368 { | 368 { |
369 if (getChannel().isOpen()) | 369 if (getChannel().isOpen()) |
370 { | 370 { |
371 if (_interestOps>0) | 371 _key.interestOps(_interestOps); |
372 { | |
373 if (_key==null || !_key.isValid()) | |
374 { | |
375 SelectableChannel sc = (SelectableChannel)getChannel(); | |
376 if (sc.isRegistered()) | |
377 { | |
378 updateKey(); | |
379 } | |
380 else | |
381 { | |
382 try | |
383 { | |
384 _key = _selectSet.getSelector().register(sc,_interestOps,this); | |
385 } | |
386 catch (Exception e) | |
387 { | |
388 LOG.trace("",e); | |
389 if (_key!=null && _key.isValid()) | |
390 { | |
391 _key.cancel(); | |
392 } | |
393 | |
394 _key = null; | |
395 } | |
396 } | |
397 } | |
398 else | |
399 { | |
400 _key.interestOps(_interestOps); | |
401 } | |
402 } | |
403 else | |
404 { | |
405 if (_key!=null && _key.isValid()) | |
406 _key.interestOps(0); | |
407 else | |
408 _key = null; | |
409 } | |
410 } | 372 } |
411 else | 373 else |
412 { | 374 { |
413 if (_key!=null && _key.isValid()) | 375 _key.cancel(); |
414 _key.cancel(); | |
415 | |
416 _key = null; | |
417 } | 376 } |
418 } | 377 } |
419 | 378 |
420 private void handle() | 379 private void handle() |
421 { | 380 { |
506 // Do NOT use synchronized (this) | 465 // Do NOT use synchronized (this) |
507 // because it's very easy to deadlock when debugging is enabled. | 466 // because it's very easy to deadlock when debugging is enabled. |
508 // We do a best effort to print the right toString() and that's it. | 467 // We do a best effort to print the right toString() and that's it. |
509 SelectionKey key = _key; | 468 SelectionKey key = _key; |
510 String keyString = ""; | 469 String keyString = ""; |
511 if (key != null) | 470 if (key.isValid()) |
512 { | 471 { |
513 if (key.isValid()) | 472 if (key.isReadable()) |
514 { | 473 keyString += "r"; |
515 if (key.isReadable()) | 474 if (key.isWritable()) |
516 keyString += "r"; | 475 keyString += "w"; |
517 if (key.isWritable()) | |
518 keyString += "w"; | |
519 } | |
520 else | |
521 { | |
522 keyString += "!"; | |
523 } | |
524 } | 476 } |
525 else | 477 else |
526 { | 478 { |
527 keyString += "-"; | 479 keyString += "!"; |
528 } | 480 } |
529 return String.format("SCEP@%x{l(%s)<->r(%s),s=%d,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%d%s}-{%s}", | 481 return String.format("SCEP@%x{l(%s)<->r(%s),s=%d,open=%b,ishut=%b,oshut=%b,rb=%b,wb=%b,w=%b,i=%d%s}-{%s}", |
530 hashCode(), | 482 hashCode(), |
531 _socket.getRemoteSocketAddress(), | 483 _socket.getRemoteSocketAddress(), |
532 _socket.getLocalSocketAddress(), | 484 _socket.getLocalSocketAddress(), |