Class: DatTCP::ServerSpy

Inherits:
Object
  • Object
show all
Defined in:
lib/dat-tcp/server_spy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = 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          = 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_sizeObject (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_descriptorsObject (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_descriptorObject (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_calledObject

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

#ipObject (readonly)

Returns the value of attribute ip.



11
12
13
# File 'lib/dat-tcp/server_spy.rb', line 11

def ip
  @ip
end

#listen_calledObject

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

#loggerObject (readonly)

Returns the value of attribute logger.



10
11
12
# File 'lib/dat-tcp/server_spy.rb', line 10

def logger
  @logger
end

#num_workersObject (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

#optionsObject (readonly)

Returns the value of attribute options.



9
10
11
# File 'lib/dat-tcp/server_spy.rb', line 9

def options
  @options
end

#pause_calledObject

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

#portObject (readonly)

Returns the value of attribute port.



11
12
13
# File 'lib/dat-tcp/server_spy.rb', line 11

def port
  @port
end

#shutdown_timeoutObject (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_calledObject

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_calledObject

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_calledObject

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_haltObject (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_pauseObject (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_stopObject (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_classObject (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_paramsObject (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

Returns:

  • (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

Returns:

  • (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_listenObject



67
68
69
# File 'lib/dat-tcp/server_spy.rb', line 67

def stop_listen
  @stop_listen_called = true
end