Class: Riser::SocketServer
- Inherits:
-
Object
- Object
- Riser::SocketServer
- Defined in:
- lib/riser/server.rb
Constant Summary collapse
- NO_CALL =
:nodoc:
proc{}
Instance Attribute Summary collapse
-
#accept_polling_timeout_seconds ⇒ Object
Returns the value of attribute accept_polling_timeout_seconds.
-
#process_num ⇒ Object
Returns the value of attribute process_num.
-
#process_queue_polling_timeout_seconds ⇒ Object
Returns the value of attribute process_queue_polling_timeout_seconds.
-
#process_queue_size ⇒ Object
Returns the value of attribute process_queue_size.
-
#process_send_io_polling_timeout_seconds ⇒ Object
Returns the value of attribute process_send_io_polling_timeout_seconds.
-
#thread_num ⇒ Object
Returns the value of attribute thread_num.
-
#thread_queue_polling_timeout_seconds ⇒ Object
Returns the value of attribute thread_queue_polling_timeout_seconds.
-
#thread_queue_size ⇒ Object
Returns the value of attribute thread_queue_size.
Instance Method Summary collapse
-
#after_stop(&block) ⇒ Object
:yields:.
-
#at_fork(&block) ⇒ Object
:yields:.
-
#at_stat(&block) ⇒ Object
:yields: stat_info.
-
#at_stop(&block) ⇒ Object
:yields: stop_state.
-
#before_start(&block) ⇒ Object
:yields: server_socket.
-
#dispatch(&block) ⇒ Object
:yields: socket.
-
#initialize ⇒ SocketServer
constructor
A new instance of SocketServer.
-
#postprocess(&block) ⇒ Object
:yields:.
-
#preprocess(&block) ⇒ Object
:yields:.
-
#setup(server_socket) ⇒ Object
after this method call is completed, the object will be ready to accept ‘signal_…’ methods.
-
#signal_stat_get(reset: true) ⇒ Object
should be called from signal(2) handler.
-
#signal_stat_stop ⇒ Object
should be called from signal(2) handler.
-
#signal_stop_forced ⇒ Object
should be called from signal(2) handler.
-
#signal_stop_graceful ⇒ Object
should be called from signal(2) handler.
-
#start(server_socket) ⇒ Object
should be executed on the main thread sharing the stack with signal(2) handlers.
Constructor Details
#initialize ⇒ SocketServer
Returns a new instance of SocketServer.
646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
# File 'lib/riser/server.rb', line 646 def initialize @accept_polling_timeout_seconds = 0.1 @process_num = 0 @process_queue_size = 20 @process_queue_polling_timeout_seconds = 0.1 @process_send_io_polling_timeout_seconds = 0.1 @thread_num = 4 @thread_queue_size = 20 @thread_queue_polling_timeout_seconds = 0.1 @before_start = NO_CALL @at_fork = NO_CALL @at_stop = NO_CALL @at_stat = NO_CALL @preprocess = NO_CALL @postprocess = NO_CALL @after_stop = NO_CALL @dispatch = nil @dispatcher = nil end |
Instance Attribute Details
#accept_polling_timeout_seconds ⇒ Object
Returns the value of attribute accept_polling_timeout_seconds.
666 667 668 |
# File 'lib/riser/server.rb', line 666 def accept_polling_timeout_seconds @accept_polling_timeout_seconds end |
#process_num ⇒ Object
Returns the value of attribute process_num.
667 668 669 |
# File 'lib/riser/server.rb', line 667 def process_num @process_num end |
#process_queue_polling_timeout_seconds ⇒ Object
Returns the value of attribute process_queue_polling_timeout_seconds.
669 670 671 |
# File 'lib/riser/server.rb', line 669 def process_queue_polling_timeout_seconds @process_queue_polling_timeout_seconds end |
#process_queue_size ⇒ Object
Returns the value of attribute process_queue_size.
668 669 670 |
# File 'lib/riser/server.rb', line 668 def process_queue_size @process_queue_size end |
#process_send_io_polling_timeout_seconds ⇒ Object
Returns the value of attribute process_send_io_polling_timeout_seconds.
670 671 672 |
# File 'lib/riser/server.rb', line 670 def process_send_io_polling_timeout_seconds @process_send_io_polling_timeout_seconds end |
#thread_num ⇒ Object
Returns the value of attribute thread_num.
671 672 673 |
# File 'lib/riser/server.rb', line 671 def thread_num @thread_num end |
#thread_queue_polling_timeout_seconds ⇒ Object
Returns the value of attribute thread_queue_polling_timeout_seconds.
673 674 675 |
# File 'lib/riser/server.rb', line 673 def thread_queue_polling_timeout_seconds @thread_queue_polling_timeout_seconds end |
#thread_queue_size ⇒ Object
Returns the value of attribute thread_queue_size.
672 673 674 |
# File 'lib/riser/server.rb', line 672 def thread_queue_size @thread_queue_size end |
Instance Method Details
#after_stop(&block) ⇒ Object
:yields:
705 706 707 708 |
# File 'lib/riser/server.rb', line 705 def after_stop(&block) # :yields: @after_stop = block nil end |
#at_fork(&block) ⇒ Object
:yields:
680 681 682 683 |
# File 'lib/riser/server.rb', line 680 def at_fork(&block) # :yields: @at_fork = block nil end |
#at_stat(&block) ⇒ Object
:yields: stat_info
690 691 692 693 |
# File 'lib/riser/server.rb', line 690 def at_stat(&block) # :yields: stat_info @at_stat = block nil end |
#at_stop(&block) ⇒ Object
:yields: stop_state
685 686 687 688 |
# File 'lib/riser/server.rb', line 685 def at_stop(&block) # :yields: stop_state @at_stop = block nil end |
#before_start(&block) ⇒ Object
:yields: server_socket
675 676 677 678 |
# File 'lib/riser/server.rb', line 675 def before_start(&block) # :yields: server_socket @before_start = block nil end |
#dispatch(&block) ⇒ Object
:yields: socket
710 711 712 713 |
# File 'lib/riser/server.rb', line 710 def dispatch(&block) # :yields: socket @dispatch = block nil end |
#postprocess(&block) ⇒ Object
:yields:
700 701 702 703 |
# File 'lib/riser/server.rb', line 700 def postprocess(&block) # :yields: @postprocess = block nil end |
#preprocess(&block) ⇒ Object
:yields:
695 696 697 698 |
# File 'lib/riser/server.rb', line 695 def preprocess(&block) # :yields: @preprocess = block nil end |
#setup(server_socket) ⇒ Object
after this method call is completed, the object will be ready to accept ‘signal_…’ methods.
741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 |
# File 'lib/riser/server.rb', line 741 def setup(server_socket) if (@process_num > 0) then @dispatcher = SocketProcessDispatcher.new('process_queue', 'thread_queue') @dispatcher.accept_polling_timeout_seconds = @accept_polling_timeout_seconds @dispatcher.process_num = @process_num @dispatcher.process_queue_size = @process_queue_size @dispatcher.process_queue_polling_timeout_seconds = @process_queue_polling_timeout_seconds @dispatcher.process_send_io_polling_timeout_seconds = @process_send_io_polling_timeout_seconds @dispatcher.thread_num = @thread_num @dispatcher.thread_queue_size = @thread_queue_size @dispatcher.thread_queue_polling_timeout_seconds = @thread_queue_polling_timeout_seconds @dispatcher.at_fork{ server_socket.close @at_fork.call } @dispatcher.at_stop(&@at_stop) @dispatcher.at_stat(&@at_stat) @dispatcher.preprocess(&@preprocess) @dispatcher.postprocess(&@postprocess) @dispatcher.dispatch(&@dispatch) @dispatcher.setup else @dispatcher = SocketThreadDispatcher.new('thread_queue') @dispatcher.thread_num = @thread_num @dispatcher.thread_queue_size = @thread_queue_size @dispatcher.thread_queue_polling_timeout_seconds = @thread_queue_polling_timeout_seconds @dispatcher.at_stop(&@at_stop) @dispatcher.at_stat(&@at_stat) @dispatcher.at_stat_get(&NO_CALL) @dispatcher.at_stat_stop(&NO_CALL) @dispatcher.preprocess(&@preprocess) @dispatcher.postprocess(&@postprocess) @dispatcher.accept{ server_socket.accept_timeout(@accept_polling_timeout_seconds) } @dispatcher.accept_return(&NO_CALL) @dispatcher.dispatch(&@dispatch) end nil end |
#signal_stat_get(reset: true) ⇒ Object
should be called from signal(2) handler
728 729 730 731 |
# File 'lib/riser/server.rb', line 728 def signal_stat_get(reset: true) @dispatcher.signal_stat_get(reset: reset) if @dispatcher nil end |
#signal_stat_stop ⇒ Object
should be called from signal(2) handler
734 735 736 737 |
# File 'lib/riser/server.rb', line 734 def signal_stat_stop @dispatcher.signal_stat_stop if @dispatcher nil end |
#signal_stop_forced ⇒ Object
should be called from signal(2) handler
722 723 724 725 |
# File 'lib/riser/server.rb', line 722 def signal_stop_forced @dispatcher.signal_stop_forced if @dispatcher nil end |
#signal_stop_graceful ⇒ Object
should be called from signal(2) handler
716 717 718 719 |
# File 'lib/riser/server.rb', line 716 def signal_stop_graceful @dispatcher.signal_stop_graceful if @dispatcher nil end |
#start(server_socket) ⇒ Object
should be executed on the main thread sharing the stack with signal(2) handlers
787 788 789 790 791 792 793 794 795 796 797 798 799 800 |
# File 'lib/riser/server.rb', line 787 def start(server_socket) unless (@dispatcher) then setup(server_socket) end @before_start.call(server_socket) begin @dispatcher.start(server_socket) ensure @after_stop.call end nil end |