Class: Applitools::Connectivity::UniversalServerControl

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/applitools/universal_sdk/universal_server_control.rb

Constant Summary collapse

DEFAULT_SERVER_IP =
'127.0.0.1'
EXECUTABLE_FILEPATH =
Applitools::Connectivity::UniversalServerGemFinder.executable_filepath

Instance Method Summary collapse

Constructor Details

#initializeUniversalServerControl

Returns a new instance of UniversalServerControl.



13
14
15
16
17
18
19
20
21
# File 'lib/applitools/universal_sdk/universal_server_control.rb', line 13

def initialize
  @control_pipe = nil
  @port_pipe = nil
  @usdk_pid = nil
  @monitoring_thread = nil
  @port = nil
  start_server_with_pipe
  @sockets = []
end

Instance Method Details

#new_server_socket_connectionObject



27
28
29
30
31
32
33
34
35
# File 'lib/applitools/universal_sdk/universal_server_control.rb', line 27

def new_server_socket_connection
  begin
    socket = TCPSocket.new(DEFAULT_SERVER_IP, @port)
    @sockets.push(socket)
    socket
  rescue Errno::ECONNREFUSED
    nil
  end
end

#server_portObject



23
24
25
# File 'lib/applitools/universal_sdk/universal_server_control.rb', line 23

def server_port
  @port
end

#server_running?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
# File 'lib/applitools/universal_sdk/universal_server_control.rb', line 37

def server_running?
  return false if @monitoring_thread.nil?
  monitoring_result = @monitoring_thread.join(1)
  monitoring_result.nil?
end

#stop_serverObject



43
44
45
46
47
48
# File 'lib/applitools/universal_sdk/universal_server_control.rb', line 43

def stop_server
  return if @control_pipe.nil?
  @control_pipe.close_write
  @sockets.each {|socket| socket.close unless socket.closed? }
  sleep(1)
end

#to_sObject

for test & debug



50
51
52
# File 'lib/applitools/universal_sdk/universal_server_control.rb', line 50

def to_s # for test & debug
  "SDKServer(port=#{@port}; pid=#{@usdk_pid})"
end