Class: DatTCP::ServerSpy
- Inherits:
-
Object
- Object
- DatTCP::ServerSpy
- Defined in:
- lib/dat-tcp/server_spy.rb
Instance Attribute Summary collapse
-
#backlog_size ⇒ Object
readonly
Returns the value of attribute backlog_size.
-
#client_file_descriptors ⇒ Object
readonly
Returns the value of attribute client_file_descriptors.
-
#file_descriptor ⇒ Object
readonly
Returns the value of attribute file_descriptor.
-
#halt_called ⇒ Object
Returns the value of attribute halt_called.
-
#ip ⇒ Object
readonly
Returns the value of attribute ip.
-
#listen_called ⇒ Object
Returns the value of attribute listen_called.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#num_workers ⇒ Object
readonly
Returns the value of attribute num_workers.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#pause_called ⇒ Object
Returns the value of attribute pause_called.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
-
#shutdown_timeout ⇒ Object
readonly
Returns the value of attribute shutdown_timeout.
-
#start_called ⇒ Object
Returns the value of attribute start_called.
-
#stop_called ⇒ Object
Returns the value of attribute stop_called.
-
#stop_listen_called ⇒ Object
Returns the value of attribute stop_listen_called.
-
#waiting_for_halt ⇒ Object
readonly
Returns the value of attribute waiting_for_halt.
-
#waiting_for_pause ⇒ Object
readonly
Returns the value of attribute waiting_for_pause.
-
#waiting_for_stop ⇒ Object
readonly
Returns the value of attribute waiting_for_stop.
-
#worker_class ⇒ Object
readonly
Returns the value of attribute worker_class.
-
#worker_params ⇒ Object
readonly
Returns the value of attribute worker_params.
Instance Method Summary collapse
- #halt(wait = false) ⇒ Object
-
#initialize(worker_class, options = nil) ⇒ ServerSpy
constructor
A new instance of ServerSpy.
- #listen(*args) ⇒ Object
- #listening? ⇒ Boolean
- #pause(wait = false) ⇒ Object
- #running? ⇒ Boolean
- #start(passed_client_fds = nil) ⇒ Object
- #stop(wait = false) ⇒ Object
- #stop_listen ⇒ Object
Constructor Details
#initialize(worker_class, options = nil) ⇒ ServerSpy
Returns a new instance of ServerSpy.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/dat-tcp/server_spy.rb', line 18 def initialize(worker_class, = nil) @worker_class = worker_class if !@worker_class.kind_of?(Class) || !@worker_class.include?(DatTCP::Worker) raise ArgumentError, "worker class must include `#{DatTCP::Worker}`" end server_ns = DatTCP::Server @options = || {} @backlog_size = @options[:backlog_size] || server_ns::DEFAULT_BACKLOG_SIZE @shutdown_timeout = @options[:shutdown_timeout] || server_ns::DEFAULT_SHUTDOWN_TIMEOUT @num_workers = (@options[:num_workers] || server_ns::DEFAULT_NUM_WORKERS).to_i @logger = @options[:logger] @worker_params = @options[:worker_params] @ip = nil @port = nil @file_descriptor = nil @client_file_descriptors = [] @waiting_for_pause = nil @waiting_for_stop = nil @waiting_for_halt = nil @listen_called = false @stop_listen_called = false @start_called = false @pause_called = false @stop_called = false @halt_called = false end |
Instance Attribute Details
#backlog_size ⇒ Object (readonly)
Returns the value of attribute backlog_size.
9 10 11 |
# File 'lib/dat-tcp/server_spy.rb', line 9 def backlog_size @backlog_size end |
#client_file_descriptors ⇒ Object (readonly)
Returns the value of attribute client_file_descriptors.
12 13 14 |
# File 'lib/dat-tcp/server_spy.rb', line 12 def client_file_descriptors @client_file_descriptors end |
#file_descriptor ⇒ Object (readonly)
Returns the value of attribute file_descriptor.
11 12 13 |
# File 'lib/dat-tcp/server_spy.rb', line 11 def file_descriptor @file_descriptor end |
#halt_called ⇒ Object
Returns the value of attribute halt_called.
16 17 18 |
# File 'lib/dat-tcp/server_spy.rb', line 16 def halt_called @halt_called end |
#ip ⇒ Object (readonly)
Returns the value of attribute ip.
11 12 13 |
# File 'lib/dat-tcp/server_spy.rb', line 11 def ip @ip end |
#listen_called ⇒ Object
Returns the value of attribute listen_called.
14 15 16 |
# File 'lib/dat-tcp/server_spy.rb', line 14 def listen_called @listen_called end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
10 11 12 |
# File 'lib/dat-tcp/server_spy.rb', line 10 def logger @logger end |
#num_workers ⇒ Object (readonly)
Returns the value of attribute num_workers.
10 11 12 |
# File 'lib/dat-tcp/server_spy.rb', line 10 def num_workers @num_workers end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/dat-tcp/server_spy.rb', line 9 def @options end |
#pause_called ⇒ Object
Returns the value of attribute pause_called.
15 16 17 |
# File 'lib/dat-tcp/server_spy.rb', line 15 def pause_called @pause_called end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
11 12 13 |
# File 'lib/dat-tcp/server_spy.rb', line 11 def port @port end |
#shutdown_timeout ⇒ Object (readonly)
Returns the value of attribute shutdown_timeout.
9 10 11 |
# File 'lib/dat-tcp/server_spy.rb', line 9 def shutdown_timeout @shutdown_timeout end |
#start_called ⇒ Object
Returns the value of attribute start_called.
14 15 16 |
# File 'lib/dat-tcp/server_spy.rb', line 14 def start_called @start_called end |
#stop_called ⇒ Object
Returns the value of attribute stop_called.
16 17 18 |
# File 'lib/dat-tcp/server_spy.rb', line 16 def stop_called @stop_called end |
#stop_listen_called ⇒ Object
Returns the value of attribute stop_listen_called.
15 16 17 |
# File 'lib/dat-tcp/server_spy.rb', line 15 def stop_listen_called @stop_listen_called end |
#waiting_for_halt ⇒ Object (readonly)
Returns the value of attribute waiting_for_halt.
13 14 15 |
# File 'lib/dat-tcp/server_spy.rb', line 13 def waiting_for_halt @waiting_for_halt end |
#waiting_for_pause ⇒ Object (readonly)
Returns the value of attribute waiting_for_pause.
13 14 15 |
# File 'lib/dat-tcp/server_spy.rb', line 13 def waiting_for_pause @waiting_for_pause end |
#waiting_for_stop ⇒ Object (readonly)
Returns the value of attribute waiting_for_stop.
13 14 15 |
# File 'lib/dat-tcp/server_spy.rb', line 13 def waiting_for_stop @waiting_for_stop end |
#worker_class ⇒ Object (readonly)
Returns the value of attribute worker_class.
8 9 10 |
# File 'lib/dat-tcp/server_spy.rb', line 8 def worker_class @worker_class end |
#worker_params ⇒ Object (readonly)
Returns the value of attribute worker_params.
10 11 12 |
# File 'lib/dat-tcp/server_spy.rb', line 10 def worker_params @worker_params end |
Instance Method Details
#halt(wait = false) ⇒ Object
86 87 88 89 |
# File 'lib/dat-tcp/server_spy.rb', line 86 def halt(wait = false) @waiting_for_halt = wait @halt_called = true end |
#listen(*args) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/dat-tcp/server_spy.rb', line 57 def listen(*args) case args.size when 2 @ip, @port = args when 1 @file_descriptor = args.first end @listen_called = true end |
#listening? ⇒ Boolean
49 50 51 |
# File 'lib/dat-tcp/server_spy.rb', line 49 def listening? @listen_called && !@stop_listen_called end |
#pause(wait = false) ⇒ Object
76 77 78 79 |
# File 'lib/dat-tcp/server_spy.rb', line 76 def pause(wait = false) @waiting_for_pause = wait @pause_called = true end |
#running? ⇒ Boolean
53 54 55 |
# File 'lib/dat-tcp/server_spy.rb', line 53 def running? @start_called && !(@pause_called || @stop_called || @halt_called) end |
#start(passed_client_fds = nil) ⇒ Object
71 72 73 74 |
# File 'lib/dat-tcp/server_spy.rb', line 71 def start(passed_client_fds = nil) @client_file_descriptors = passed_client_fds || [] @start_called = true end |
#stop(wait = false) ⇒ Object
81 82 83 84 |
# File 'lib/dat-tcp/server_spy.rb', line 81 def stop(wait = false) @waiting_for_stop = wait @stop_called = true end |
#stop_listen ⇒ Object
67 68 69 |
# File 'lib/dat-tcp/server_spy.rb', line 67 def stop_listen @stop_listen_called = true end |