Class: Applitools::EyesUniversal::UniversalServerControl

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

Constant Summary collapse

DEFAULT_SERVER_IP =
'127.0.0.1'
DEFAULT_SERVER_HOST =
'localhost'
EXECUTABLE_FILEPATH =
Applitools::EyesUniversal::UniversalServerGemFinder.executable_filepath

Instance Method Summary collapse

Constructor Details

#initializeUniversalServerControl

Returns a new instance of UniversalServerControl.



15
16
17
18
19
20
21
22
23
# File 'lib/applitools/eyes_universal/universal_server_control.rb', line 15

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



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/applitools/eyes_universal/universal_server_control.rb', line 29

def new_server_socket_connection
  begin
    # socket = TCPSocket.new(DEFAULT_SERVER_IP, @port)
    socket = Addrinfo.tcp(DEFAULT_SERVER_HOST, @port).connect
    @sockets.push(socket)
    socket
  rescue Errno::ECONNREFUSED => e
    puts e
    nil
  end
end

#server_portObject



25
26
27
# File 'lib/applitools/eyes_universal/universal_server_control.rb', line 25

def server_port
  @port
end

#server_running?Boolean

Returns:

  • (Boolean)


41
42
43
44
45
# File 'lib/applitools/eyes_universal/universal_server_control.rb', line 41

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

#stop_serverObject



47
48
49
50
51
52
# File 'lib/applitools/eyes_universal/universal_server_control.rb', line 47

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



54
55
56
# File 'lib/applitools/eyes_universal/universal_server_control.rb', line 54

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