Sha256: 518a0407671adc5e2bed9afc8648c0d029f040241ebb94d31d2accb8634e2ff9

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

#if false
require 'service.rb'
require 'crypt.rb'
require 'drb'

DRb.start_service

class NetworkLookupApp<Service
  attr_reader :mid
  def initialize(cluster,options)
    super(cluster,options,:networkLookup)
    provides(:networkLookup)
    @mid=rand
    @registered=[]
  end
  
  def register(info)
    begin
      getMaster.register(info)
      @registered<<info
    rescue Errno::ECONNREFUSED
      log("Cannot register, because cannot connect to master")
    end
  end
  
  def unregister(info)
    @registered.delete(info)
    getMaster.unregister(info) if @registered.member?(info)
  end
  
  def stop
    #Thread.new{
    #  @registered.each{|info|getMaster.unregister(info)}
    #}
  end
  
  def getServers
    getAllServers-@registered
  end
  
  def getAllServers
    begin
      getMaster.clients
    rescue
      []
    end
  end
  
  private
  def getMaster
    puts "req"
    
    # TODO: use list of master-servers
    
    server_uri="druby://127.0.0.1:#{MasterApp::MASTER_SERVICE_PORT}"
    drb=DRbObject.new_with_uri(server_uri)
    drb 
  end
end

#end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
appswarm-0.0.1 apps/network_lookup/network_lookup.rb