OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library chat_server; | 5 library chat_server; |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import 'dart:io'; | 7 import 'dart:io'; |
8 import 'dart:isolate'; | 8 import 'dart:isolate'; |
9 import 'dart:json' as json; | 9 import 'dart:json' as json; |
10 import 'dart:math'; | 10 import 'dart:math'; |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
521 } | 521 } |
522 | 522 |
523 void init() { | 523 void init() { |
524 _logRequests = false; | 524 _logRequests = false; |
525 _topic = new Topic(); | 525 _topic = new Topic(); |
526 _serverStart = new DateTime.now(); | 526 _serverStart = new DateTime.now(); |
527 _messageCount = 0; | 527 _messageCount = 0; |
528 _messageRate = new Rate(); | 528 _messageRate = new Rate(); |
529 | 529 |
530 // Start a timer for cleanup events. | 530 // Start a timer for cleanup events. |
531 _cleanupTimer = new Timer.repeating(const Duration(seconds: 10), | 531 _cleanupTimer = new Timer.periodic(const Duration(seconds: 10), |
532 _topic._handleTimer); | 532 _topic._handleTimer); |
533 } | 533 } |
534 | 534 |
535 // Start timer for periodic logging. | 535 // Start timer for periodic logging. |
536 void _handleLogging(Timer timer) { | 536 void _handleLogging(Timer timer) { |
537 if (_logging) { | 537 if (_logging) { |
538 print("${_messageRate.rate} messages/s " | 538 print("${_messageRate.rate} messages/s " |
539 "(total $_messageCount messages)"); | 539 "(total $_messageCount messages)"); |
540 } | 540 } |
541 } | 541 } |
542 | 542 |
(...skipping 26 matching lines...) Expand all Loading... |
569 _server = s; | 569 _server = s; |
570 _server.listen((request) { | 570 _server.listen((request) { |
571 if (handlers.containsKey(request.uri.path)) { | 571 if (handlers.containsKey(request.uri.path)) { |
572 handlers[request.uri.path](request, request.response); | 572 handlers[request.uri.path](request, request.response); |
573 } else { | 573 } else { |
574 _notFoundHandler(request, request.response); | 574 _notFoundHandler(request, request.response); |
575 } | 575 } |
576 }); | 576 }); |
577 replyTo.send(new ChatServerStatus.started(_server.port), null); | 577 replyTo.send(new ChatServerStatus.started(_server.port), null); |
578 _loggingTimer = | 578 _loggingTimer = |
579 new Timer.repeating(const Duration(seconds: 1), _handleLogging); | 579 new Timer.periodic(const Duration(seconds: 1), _handleLogging); |
580 }) | 580 }) |
581 .catchError((e) { | 581 .catchError((e) { |
582 replyTo.send(new ChatServerStatus.error2(e.toString()), null); | 582 replyTo.send(new ChatServerStatus.error2(e.toString()), null); |
583 }); | 583 }); |
584 } else if (message.isStop) { | 584 } else if (message.isStop) { |
585 replyTo.send(new ChatServerStatus.stopping(), null); | 585 replyTo.send(new ChatServerStatus.stopping(), null); |
586 stop(); | 586 stop(); |
587 replyTo.send(new ChatServerStatus.stopped(), null); | 587 replyTo.send(new ChatServerStatus.stopped(), null); |
588 } | 588 } |
589 } | 589 } |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
671 } | 671 } |
672 } | 672 } |
673 | 673 |
674 int _timeRange; | 674 int _timeRange; |
675 List<int> _buckets; | 675 List<int> _buckets; |
676 int _currentBucket; | 676 int _currentBucket; |
677 int _currentBucketTime; | 677 int _currentBucketTime; |
678 num _bucketTimeRange; | 678 num _bucketTimeRange; |
679 int _sum; | 679 int _sum; |
680 } | 680 } |
OLD | NEW |