class RSwim::Node

Public Class Methods

new(my_host, seed_hosts) click to toggle source
# File lib/rswim/node.rb, line 7
def initialize(my_host, seed_hosts)
  @my_host = my_host
  @directory = Directory.new
  @my_id = @directory.id(@my_host)
  @deserializer = Integration::Deserializer.new(@directory, @my_id)
  @serializer = Integration::Serializer.new(@directory)
  @pipe = RSwim::Pipe.simple
  seed_ids = seed_hosts.map { |host| @directory.id(host) }
  @agent = RSwim::Agent::SleepBased.new(@pipe, @my_id, seed_ids)
end
udp(my_host, seed_hosts, port) click to toggle source
# File lib/rswim/node.rb, line 18
def self.udp(my_host, seed_hosts, port)
  Integration::Udp::Node.new(my_host, seed_hosts, port)
end

Public Instance Methods

start() click to toggle source

blocks until interrupted

# File lib/rswim/node.rb, line 30
def start
  logger.info 'starting node'
  before_start
  @agent.run
rescue StandardError => e
  logger.debug("Error: #{e}")
end
subscribe(&block) click to toggle source
# File lib/rswim/node.rb, line 22
def subscribe(&block)
  @agent.subscribe do |id, status|
    host = @directory.host(id)
    block.call(host, status)
  end
end

Protected Instance Methods

before_start() click to toggle source
# File lib/rswim/node.rb, line 40
def before_start
  raise 'must be implemented in subclass'
end
logger() click to toggle source
# File lib/rswim/node.rb, line 44
def logger
  @_logger ||= begin
    RSwim::Logger.new(self.class, STDERR)
  end
end