Class: Pantry::Communication::WritingSocket

Inherits:
Object
  • Object
show all
Includes:
Celluloid::ZMQ
Defined in:
lib/pantry/communication/writing_socket.rb

Overview

Base class of all sockets that write messages through ZMQ. Not meant for direct use, please use one of the subclasses for specific functionality.

Direct Known Subclasses

PublishSocket, SendSocket

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, security) ⇒ WritingSocket

Returns a new instance of WritingSocket.



12
13
14
15
16
# File 'lib/pantry/communication/writing_socket.rb', line 12

def initialize(host, port, security)
  @host     = host
  @port     = port
  @security = security
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



10
11
12
# File 'lib/pantry/communication/writing_socket.rb', line 10

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



10
11
12
# File 'lib/pantry/communication/writing_socket.rb', line 10

def port
  @port
end

Instance Method Details

#build_socketObject



26
27
28
# File 'lib/pantry/communication/writing_socket.rb', line 26

def build_socket
  raise "Implement the socket setup."
end

#closeObject



34
35
36
# File 'lib/pantry/communication/writing_socket.rb', line 34

def close
  @socket.close if @socket
end

#openObject



18
19
20
21
22
23
24
# File 'lib/pantry/communication/writing_socket.rb', line 18

def open
  @socket = build_socket
  Communication.configure_socket(@socket)
  @security.configure_socket(@socket)

  open_socket(@socket)
end

#open_socket(socket) ⇒ Object



30
31
32
# File 'lib/pantry/communication/writing_socket.rb', line 30

def open_socket(socket)
  raise "Connect / Bind the socket built in #build_socket"
end

#send_message(message) ⇒ Object



38
39
40
41
42
# File 'lib/pantry/communication/writing_socket.rb', line 38

def send_message(message)
  @socket.write(
    SerializeMessage.to_zeromq(message)
  )
end