Class: Invoker::IPC::UnixClient

Inherits:
Object
  • Object
show all
Defined in:
lib/invoker/ipc/unix_client.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.send_command(command, message_arguments = {}, &block) ⇒ Object



39
40
41
# File 'lib/invoker/ipc/unix_client.rb', line 39

def self.send_command(command, message_arguments = {}, &block)
  new.send_command(command, message_arguments, &block)
end

Instance Method Details

#send_and_receive(command, message = {}) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/invoker/ipc/unix_client.rb', line 16

def send_and_receive(command, message = {})
  response = nil
  message_object = get_message_object(command, message)
  open_client_socket(false) do |socket|
    send_json_message(socket, message_object)
    socket.flush
    response = Invoker::IPC.message_from_io(socket)
  end
  response
end

#send_and_wait(command, message = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/invoker/ipc/unix_client.rb', line 27

def send_and_wait(command, message = {})
  begin
    socket = Socket.unix(Invoker::IPC::Server::SOCKET_PATH)
  rescue
    abort("Invoker does not seem to be running".colorize(:red))
  end
  message_object = get_message_object(command, message)
  send_json_message(socket, message_object)
  socket.flush
  socket
end

#send_command(command, message = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/invoker/ipc/unix_client.rb', line 4

def send_command(command, message = {})
  message_object = get_message_object(command, message)
  open_client_socket do |socket|
    send_json_message(socket, message_object)
    socket.flush
    if block_given?
      response_object = Invoker::IPC.message_from_io(socket)
      yield response_object
    end
  end
end