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.
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 |
# File 'lib/riser/server.rb', line 669 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.
689 690 691 |
# File 'lib/riser/server.rb', line 689 def accept_polling_timeout_seconds @accept_polling_timeout_seconds end |
#process_num ⇒ Object
Returns the value of attribute process_num.
690 691 692 |
# File 'lib/riser/server.rb', line 690 def process_num @process_num end |
#process_queue_polling_timeout_seconds ⇒ Object
Returns the value of attribute process_queue_polling_timeout_seconds.
692 693 694 |
# File 'lib/riser/server.rb', line 692 def process_queue_polling_timeout_seconds @process_queue_polling_timeout_seconds end |
#process_queue_size ⇒ Object
Returns the value of attribute process_queue_size.
691 692 693 |
# File 'lib/riser/server.rb', line 691 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.
693 694 695 |
# File 'lib/riser/server.rb', line 693 def process_send_io_polling_timeout_seconds @process_send_io_polling_timeout_seconds end |
#thread_num ⇒ Object
Returns the value of attribute thread_num.
694 695 696 |
# File 'lib/riser/server.rb', line 694 def thread_num @thread_num end |
#thread_queue_polling_timeout_seconds ⇒ Object
Returns the value of attribute thread_queue_polling_timeout_seconds.
696 697 698 |
# File 'lib/riser/server.rb', line 696 def thread_queue_polling_timeout_seconds @thread_queue_polling_timeout_seconds end |
#thread_queue_size ⇒ Object
Returns the value of attribute thread_queue_size.
695 696 697 |
# File 'lib/riser/server.rb', line 695 def thread_queue_size @thread_queue_size end |
Instance Method Details
#after_stop(&block) ⇒ Object
:yields:
728 729 730 731 |
# File 'lib/riser/server.rb', line 728 def after_stop(&block) # :yields: @after_stop = block nil end |
#at_fork(&block) ⇒ Object
:yields:
703 704 705 706 |
# File 'lib/riser/server.rb', line 703 def at_fork(&block) # :yields: @at_fork = block nil end |
#at_stat(&block) ⇒ Object
:yields: stat_info
713 714 715 716 |
# File 'lib/riser/server.rb', line 713 def at_stat(&block) # :yields: stat_info @at_stat = block nil end |
#at_stop(&block) ⇒ Object
:yields: stop_state
708 709 710 711 |
# File 'lib/riser/server.rb', line 708 def at_stop(&block) # :yields: stop_state @at_stop = block nil end |
#before_start(&block) ⇒ Object
:yields: server_socket
698 699 700 701 |
# File 'lib/riser/server.rb', line 698 def before_start(&block) # :yields: server_socket @before_start = block nil end |
#dispatch(&block) ⇒ Object
:yields: socket
733 734 735 736 |
# File 'lib/riser/server.rb', line 733 def dispatch(&block) # :yields: socket @dispatch = block nil end |
#postprocess(&block) ⇒ Object
:yields:
723 724 725 726 |
# File 'lib/riser/server.rb', line 723 def postprocess(&block) # :yields: @postprocess = block nil end |
#preprocess(&block) ⇒ Object
:yields:
718 719 720 721 |
# File 'lib/riser/server.rb', line 718 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.
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 |
# File 'lib/riser/server.rb', line 764 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(&@at_fork) @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) @dispatcher.dispose(&NO_CALL) end nil end |
#signal_stat_get(reset: true) ⇒ Object
should be called from signal(2) handler
751 752 753 754 |
# File 'lib/riser/server.rb', line 751 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
757 758 759 760 |
# File 'lib/riser/server.rb', line 757 def signal_stat_stop @dispatcher.signal_stat_stop if @dispatcher nil end |
#signal_stop_forced ⇒ Object
should be called from signal(2) handler
745 746 747 748 |
# File 'lib/riser/server.rb', line 745 def signal_stop_forced @dispatcher.signal_stop_forced if @dispatcher nil end |
#signal_stop_graceful ⇒ Object
should be called from signal(2) handler
739 740 741 742 |
# File 'lib/riser/server.rb', line 739 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
808 809 810 811 812 813 814 815 816 817 818 819 820 821 |
# File 'lib/riser/server.rb', line 808 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 |