Module: Dynflow::Listeners::Serialization

Included in:
Executors::RemoteViaSocket, Executors::RemoteViaSocket::Core, Socket
Defined in:
lib/dynflow/listeners/serialization.rb

Defined Under Namespace

Modules: Protocol

Instance Method Summary collapse

Instance Method Details

#dump(obj) ⇒ Object



47
48
49
# File 'lib/dynflow/listeners/serialization.rb', line 47

def dump(obj)
  MultiJson.dump(obj.to_hash)
end

#load(str) ⇒ Object



51
52
53
# File 'lib/dynflow/listeners/serialization.rb', line 51

def load(str)
  Protocol::Message.from_hash MultiJson.load(str)
end

#receive_message(io) ⇒ Object



66
67
68
69
70
71
72
73
74
# File 'lib/dynflow/listeners/serialization.rb', line 66

def receive_message(io)
  if (message = io.gets)
    load(message)
  else
    nil
  end
rescue IOError
  nil
end

#send_message(io, message, barrier = nil) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/dynflow/listeners/serialization.rb', line 55

def send_message(io, message, barrier = nil)
  barrier.lock if barrier
  io.puts dump(message)
  true
rescue SystemCallError => error
  @logger.warn "message could not be sent #{message} because #{error}"
  false
ensure
  barrier.unlock if barrier
end