Class: Pantry::Communication::ReadingSocket

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

Overview

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

Direct Known Subclasses

ReceiveSocket, SubscribeSocket

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, security) ⇒ ReadingSocket

Returns a new instance of ReadingSocket.



13
14
15
16
17
18
# File 'lib/pantry/communication/reading_socket.rb', line 13

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

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



11
12
13
# File 'lib/pantry/communication/reading_socket.rb', line 11

def host
  @host
end

#portObject (readonly)

Returns the value of attribute port.



11
12
13
# File 'lib/pantry/communication/reading_socket.rb', line 11

def port
  @port
end

Instance Method Details

#add_listener(listener) ⇒ Object



20
21
22
# File 'lib/pantry/communication/reading_socket.rb', line 20

def add_listener(listener)
  @listener = listener
end

#build_socketObject



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

def build_socket
  raise "Implement the socket setup."
end

#has_source_header?Boolean

Some ZMQ socket types include the source as the first packet of a message. We need to know if the socket in question does this so we can properly build the Message coming in.

Returns:

  • (Boolean)


49
50
51
# File 'lib/pantry/communication/reading_socket.rb', line 49

def has_source_header?
  false
end

#openObject



24
25
26
27
28
29
30
31
32
# File 'lib/pantry/communication/reading_socket.rb', line 24

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

  @running = true
  self.async.process_messages
end

#open_socket(socket) ⇒ Object



38
39
40
# File 'lib/pantry/communication/reading_socket.rb', line 38

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

#shutdownObject



42
43
44
# File 'lib/pantry/communication/reading_socket.rb', line 42

def shutdown
  @running = false
end