Class: MaZMQ::Proxy
- Inherits:
-
Object
show all
- Includes:
- Backend
- Defined in:
- lib/ma-zmq/proxy.rb,
lib/ma-zmq/proxy/backend.rb,
lib/ma-zmq/proxy/balancer.rb
Defined Under Namespace
Modules: Backend
Classes: Balancer
Instance Method Summary
collapse
Methods included from Backend
#on_read, #on_timeout, #timeout
Constructor Details
#initialize ⇒ Proxy
7
8
9
10
11
12
13
14
15
|
# File 'lib/ma-zmq/proxy.rb', line 7
def initialize
@balancer = MaZMQ::Proxy::Balancer.new
super
end
|
Instance Method Details
#addresses ⇒ Object
48
49
50
|
# File 'lib/ma-zmq/proxy.rb', line 48
def addresses
@sockets.collect{|s| s.addresses}.flatten
end
|
#close ⇒ Object
42
43
44
45
46
|
# File 'lib/ma-zmq/proxy.rb', line 42
def close
@sockets.each do |s|
s.close
end
end
|
#connect(protocol, address, port) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/ma-zmq/proxy.rb', line 29
def connect(protocol, address, port)
return false if addresses.include? "#{protocol}://#{address}:#{port.to_s}"
index = super(protocol, address, port)
@balancer.add(index)
index
end
|
#current_socket ⇒ Object
52
53
54
|
# File 'lib/ma-zmq/proxy.rb', line 52
def current_socket
@sockets[@balancer.current]
end
|
#disconnect(index) ⇒ Object
37
38
39
40
|
# File 'lib/ma-zmq/proxy.rb', line 37
def disconnect(index)
@balancer.remove(index)
super(index)
end
|
#send_string(msg) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/ma-zmq/proxy.rb', line 17
def send_string(msg)
@current = current_socket
return false if @current.is_a? NilClass
case @current.state
when :idle
@current.send_string(msg)
else
return false
end
@balancer.next
end
|