Mercurial Hosting > luan
comparison src/org/eclipse/jetty/io/nio/SelectorManager.java @ 943:96f60ce98949
remove Timeout
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 11 Oct 2016 02:02:48 -0600 |
parents | c157a786ed0b |
children | 1d24b6e422fa |
comparison
equal
deleted
inserted
replaced
942:c157a786ed0b | 943:96f60ce98949 |
---|---|
44 import org.eclipse.jetty.util.component.AbstractLifeCycle; | 44 import org.eclipse.jetty.util.component.AbstractLifeCycle; |
45 import org.eclipse.jetty.util.component.AggregateLifeCycle; | 45 import org.eclipse.jetty.util.component.AggregateLifeCycle; |
46 import org.eclipse.jetty.util.component.Dumpable; | 46 import org.eclipse.jetty.util.component.Dumpable; |
47 import org.slf4j.Logger; | 47 import org.slf4j.Logger; |
48 import org.slf4j.LoggerFactory; | 48 import org.slf4j.LoggerFactory; |
49 import org.eclipse.jetty.util.thread.Timeout; | |
50 | 49 |
51 | 50 |
52 /* ------------------------------------------------------------ */ | 51 /* ------------------------------------------------------------ */ |
53 /** | 52 /** |
54 * The Selector Manager manages and number of SelectSets to allow | 53 * The Selector Manager manages and number of SelectSets to allow |
328 /* ------------------------------------------------------------------------------- */ | 327 /* ------------------------------------------------------------------------------- */ |
329 /* ------------------------------------------------------------------------------- */ | 328 /* ------------------------------------------------------------------------------- */ |
330 public class SelectSet implements Dumpable | 329 public class SelectSet implements Dumpable |
331 { | 330 { |
332 private final int _setID; | 331 private final int _setID; |
333 private final Timeout _timeout; | 332 private volatile long _now = System.currentTimeMillis(); |
334 | 333 |
335 private final ConcurrentLinkedQueue<Object> _changes = new ConcurrentLinkedQueue<Object>(); | 334 private final ConcurrentLinkedQueue<Object> _changes = new ConcurrentLinkedQueue<Object>(); |
336 | 335 |
337 private volatile Selector _selector; | 336 private volatile Selector _selector; |
338 | 337 |
348 SelectSet(int acceptorID) throws Exception | 347 SelectSet(int acceptorID) throws Exception |
349 { | 348 { |
350 _setID=acceptorID; | 349 _setID=acceptorID; |
351 | 350 |
352 _idleTick = System.currentTimeMillis(); | 351 _idleTick = System.currentTimeMillis(); |
353 _timeout = new Timeout(this); | |
354 _timeout.setDuration(0L); | |
355 | 352 |
356 // create a selector; | 353 // create a selector; |
357 _selector = Selector.open(); | 354 _selector = Selector.open(); |
358 _monitorNext=System.currentTimeMillis()+__MONITOR_PERIOD; | 355 _monitorNext=System.currentTimeMillis()+__MONITOR_PERIOD; |
359 } | 356 } |
474 | 471 |
475 | 472 |
476 // Do and instant select to see if any connections can be handled. | 473 // Do and instant select to see if any connections can be handled. |
477 int selected=selector.selectNow(); | 474 int selected=selector.selectNow(); |
478 | 475 |
479 long now=System.currentTimeMillis(); | 476 _now = System.currentTimeMillis(); |
480 | 477 |
481 // if no immediate things to do | 478 // if no immediate things to do |
482 if (selected==0 && selector.selectedKeys().isEmpty()) | 479 if (selected==0 && selector.selectedKeys().isEmpty()) |
483 { | 480 { |
484 // If we are in pausing mode | 481 // If we are in pausing mode |
490 } | 487 } |
491 catch(InterruptedException e) | 488 catch(InterruptedException e) |
492 { | 489 { |
493 LOG.trace("",e); | 490 LOG.trace("",e); |
494 } | 491 } |
495 now=System.currentTimeMillis(); | 492 _now = System.currentTimeMillis(); |
496 } | 493 } |
497 | 494 |
498 // workout how long to wait in select | 495 // workout how long to wait in select |
499 _timeout.setNow(now); | |
500 | |
501 long wait = _changes.size()==0?__IDLE_TICK:0L; | 496 long wait = _changes.size()==0?__IDLE_TICK:0L; |
502 | 497 |
503 // If we should wait with a select | 498 // If we should wait with a select |
504 if (wait>0) | 499 if (wait>0) |
505 { | 500 { |
506 long before=now; | 501 long before = _now; |
507 selector.select(wait); | 502 selector.select(wait); |
508 now = System.currentTimeMillis(); | 503 _now = System.currentTimeMillis(); |
509 _timeout.setNow(now); | |
510 | 504 |
511 // If we are monitoring for busy selector | 505 // If we are monitoring for busy selector |
512 // and this select did not wait more than 1ms | 506 // and this select did not wait more than 1ms |
513 if (__MONITOR_PERIOD>0 && now-before <=1) | 507 if (__MONITOR_PERIOD>0 && _now-before <=1) |
514 { | 508 { |
515 // count this as a busy select and if there have been too many this monitor cycle | 509 // count this as a busy select and if there have been too many this monitor cycle |
516 if (++_busySelects>__MAX_SELECTS) | 510 if (++_busySelects>__MAX_SELECTS) |
517 { | 511 { |
518 // Start injecting pauses | 512 // Start injecting pauses |
623 } | 617 } |
624 | 618 |
625 // Everything always handled | 619 // Everything always handled |
626 selector.selectedKeys().clear(); | 620 selector.selectedKeys().clear(); |
627 | 621 |
628 now=System.currentTimeMillis(); | 622 _now = System.currentTimeMillis(); |
629 _timeout.setNow(now); | |
630 | 623 |
631 // Idle tick | 624 // Idle tick |
632 if (now-_idleTick>__IDLE_TICK) | 625 if (_now-_idleTick>__IDLE_TICK) |
633 { | 626 { |
634 _idleTick=now; | 627 _idleTick = _now; |
635 | 628 |
636 final long idle_now=((_lowResourcesConnections>0 && selector.keys().size()>_lowResourcesConnections)) | 629 final long idle_now=((_lowResourcesConnections>0 && selector.keys().size()>_lowResourcesConnections)) |
637 ?(now+_maxIdleTime) | 630 ?(_now+_maxIdleTime) |
638 :now; | 631 :_now; |
639 | 632 |
640 execute(new Runnable() | 633 execute(new Runnable() |
641 { | 634 { |
642 public void run() | 635 public void run() |
643 { | 636 { |
650 }); | 643 }); |
651 | 644 |
652 } | 645 } |
653 | 646 |
654 // Reset busy select monitor counts | 647 // Reset busy select monitor counts |
655 if (__MONITOR_PERIOD>0 && now>_monitorNext) | 648 if (__MONITOR_PERIOD>0 && _now>_monitorNext) |
656 { | 649 { |
657 _busySelects=0; | 650 _busySelects=0; |
658 _pausing=false; | 651 _pausing=false; |
659 _monitorNext=now+__MONITOR_PERIOD; | 652 _monitorNext=_now+__MONITOR_PERIOD; |
660 | 653 |
661 } | 654 } |
662 } | 655 } |
663 catch (ClosedSelectorException e) | 656 catch (ClosedSelectorException e) |
664 { | 657 { |
716 return SelectorManager.this; | 709 return SelectorManager.this; |
717 } | 710 } |
718 | 711 |
719 public long getNow() | 712 public long getNow() |
720 { | 713 { |
721 return _timeout.getNow(); | 714 return _now; |
722 } | 715 } |
723 | 716 |
724 public void wakeup() | 717 public void wakeup() |
725 { | 718 { |
726 try | 719 try |