class DCell::Node
A node in a DCell
cluster
Constants
- NODE_DISCOVERY_TIMEOUT
Attributes
addr[R]
id[R]
Public Class Methods
new(id, addr)
click to toggle source
# File lib/dcell/node.rb, line 40 def initialize(id, addr) @id, @addr = id, addr @socket = nil @heartbeat = nil # Total hax to accommodate the new Celluloid::FSM API attach self end
Public Instance Methods
actors()
click to toggle source
List all registered actors on this node
# File lib/dcell/node.rb, line 96 def actors request = Message::List.new(Thread.mailbox) send_message request response = receive do |msg| msg.respond_to?(:request_id) && msg.request_id == request.id end abort response.value if response.is_a? ErrorResponse response.value end
Also aliased as: all
find(name)
click to toggle source
Find an actor registered with a given name on this node
# File lib/dcell/node.rb, line 81 def find(name) request = Message::Find.new(Thread.mailbox, name) send_message request response = receive(NODE_DISCOVERY_TIMEOUT) do |msg| msg.respond_to?(:request_id) && msg.request_id == request.id end return nil if response.nil? abort response.value if response.is_a? ErrorResponse response.value end
Also aliased as: []
handle_heartbeat()
click to toggle source
Handle an incoming heartbeat for this node
# File lib/dcell/node.rb, line 128 def handle_heartbeat transition :connected transition :partitioned, :delay => self.class.heartbeat_timeout end
inspect()
click to toggle source
Friendlier inspection
# File lib/dcell/node.rb, line 134 def inspect "#<DCell::Node[#{@id}] @addr=#{@addr.inspect}>" end
send_heartbeat()
click to toggle source
Send a heartbeat message after the given interval
# File lib/dcell/node.rb, line 122 def send_heartbeat send_message DCell::Message::Heartbeat.new @heartbeat = after(self.class.heartbeat_rate) { send_heartbeat } end
send_message(message)
click to toggle source
Send a message to another DCell
node
# File lib/dcell/node.rb, line 110 def send_message(message) begin message = Marshal.dump(message) rescue => ex abort ex end socket << message end
Also aliased as: <<
shutdown()
click to toggle source
# File lib/dcell/node.rb, line 58 def shutdown transition :shutdown @socket.close if @socket end
socket()
click to toggle source
Obtain the node's 0MQ socket
# File lib/dcell/node.rb, line 64 def socket return @socket if @socket @socket = Celluloid::ZMQ::PushSocket.new begin @socket.connect addr rescue IOError @socket.close @socket = nil raise end transition :connected @socket end
update_client_address( addr )
click to toggle source
# File lib/dcell/node.rb, line 49 def update_client_address( addr ) @addr = addr send_heartbeat end
update_server_address(addr)
click to toggle source
# File lib/dcell/node.rb, line 54 def update_server_address(addr) @addr = addr end