Class: Riser::SocketServer

Inherits:
Object
  • Object
show all
Defined in:
lib/riser/server.rb

Constant Summary collapse

NO_CALL =

:nodoc:

proc{}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeSocketServer

Returns a new instance of SocketServer.



644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
# File 'lib/riser/server.rb', line 644

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_secondsObject

Returns the value of attribute accept_polling_timeout_seconds.



664
665
666
# File 'lib/riser/server.rb', line 664

def accept_polling_timeout_seconds
  @accept_polling_timeout_seconds
end

#process_numObject

Returns the value of attribute process_num.



665
666
667
# File 'lib/riser/server.rb', line 665

def process_num
  @process_num
end

#process_queue_polling_timeout_secondsObject

Returns the value of attribute process_queue_polling_timeout_seconds.



667
668
669
# File 'lib/riser/server.rb', line 667

def process_queue_polling_timeout_seconds
  @process_queue_polling_timeout_seconds
end

#process_queue_sizeObject

Returns the value of attribute process_queue_size.



666
667
668
# File 'lib/riser/server.rb', line 666

def process_queue_size
  @process_queue_size
end

#process_send_io_polling_timeout_secondsObject

Returns the value of attribute process_send_io_polling_timeout_seconds.



668
669
670
# File 'lib/riser/server.rb', line 668

def process_send_io_polling_timeout_seconds
  @process_send_io_polling_timeout_seconds
end

#thread_numObject

Returns the value of attribute thread_num.



669
670
671
# File 'lib/riser/server.rb', line 669

def thread_num
  @thread_num
end

#thread_queue_polling_timeout_secondsObject

Returns the value of attribute thread_queue_polling_timeout_seconds.



671
672
673
# File 'lib/riser/server.rb', line 671

def thread_queue_polling_timeout_seconds
  @thread_queue_polling_timeout_seconds
end

#thread_queue_sizeObject

Returns the value of attribute thread_queue_size.



670
671
672
# File 'lib/riser/server.rb', line 670

def thread_queue_size
  @thread_queue_size
end

Instance Method Details

#after_stop(&block) ⇒ Object

:yields:



703
704
705
706
# File 'lib/riser/server.rb', line 703

def after_stop(&block)      # :yields:
  @after_stop = block
  nil
end

#at_fork(&block) ⇒ Object

:yields:



678
679
680
681
# File 'lib/riser/server.rb', line 678

def at_fork(&block)         # :yields:
  @at_fork = block
  nil
end

#at_stat(&block) ⇒ Object

:yields: stat_info



688
689
690
691
# File 'lib/riser/server.rb', line 688

def at_stat(&block)         # :yields: stat_info
  @at_stat = block
  nil
end

#at_stop(&block) ⇒ Object

:yields: stop_state



683
684
685
686
# File 'lib/riser/server.rb', line 683

def at_stop(&block)         # :yields: stop_state
  @at_stop = block
  nil
end

#before_start(&block) ⇒ Object

:yields: server_socket



673
674
675
676
# File 'lib/riser/server.rb', line 673

def before_start(&block)    # :yields: server_socket
  @before_start = block
  nil
end

#dispatch(&block) ⇒ Object

:yields: socket



708
709
710
711
# File 'lib/riser/server.rb', line 708

def dispatch(&block)        # :yields: socket
  @dispatch = block
  nil
end

#postprocess(&block) ⇒ Object

:yields:



698
699
700
701
# File 'lib/riser/server.rb', line 698

def postprocess(&block)     # :yields:
  @postprocess = block
  nil
end

#preprocess(&block) ⇒ Object

:yields:



693
694
695
696
# File 'lib/riser/server.rb', line 693

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.



739
740
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
# File 'lib/riser/server.rb', line 739

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



726
727
728
729
# File 'lib/riser/server.rb', line 726

def signal_stat_get(reset: true)
  @dispatcher.signal_stat_get(reset: reset) if @dispatcher
  nil
end

#signal_stat_stopObject

should be called from signal(2) handler



732
733
734
735
# File 'lib/riser/server.rb', line 732

def signal_stat_stop
  @dispatcher.signal_stat_stop if @dispatcher
  nil
end

#signal_stop_forcedObject

should be called from signal(2) handler



720
721
722
723
# File 'lib/riser/server.rb', line 720

def signal_stop_forced
  @dispatcher.signal_stop_forced if @dispatcher
  nil
end

#signal_stop_gracefulObject

should be called from signal(2) handler



714
715
716
717
# File 'lib/riser/server.rb', line 714

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



785
786
787
788
789
790
791
792
793
794
795
796
797
798
# File 'lib/riser/server.rb', line 785

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