Sha256: 5d8c5765f86ae0c08d8e4821496fba79df612efe69dda81cf7cc04ab014e7411

Contents?: true

Size: 905 Bytes

Versions: 1

Compression:

Stored size: 905 Bytes

Contents

require 'net_service.rb'


class MasterApp<NetService
  MASTER_SERVICE_PORT=9999
  EXPIRE_SECONDS=180
  
  def initialize(cluster,options)
    options[:port]||=MASTER_SERVICE_PORT
    super(cluster,options)
    @clients={}
    @clMutex=Mutex.new
  end
  def clients
    #log "reading clients #{@clients.length}"
    @clMutex.synchronize {
      pp @clients
      @clients.keys.select{|c|(Time.now-@clients[c])<EXPIRE_SECONDS}
    }
  end
  
  def info
    {:clients=>@clients.length}
  end
  
  def register(client)
    log "#{client} registered"
    @clMutex.synchronize {
      @clients[client]=Time.now
    }
    # TODO: checkClientExists
  end
  
  def unregister(client)
    log "#{client} removed"
    @clMutex.synchronize {
      @clients.delete(client)
    }
    # TODO: check Client wants to leave
  end
  
  def client
    pp self.class.included_modules
    pp self.pretty_inspect    
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

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