Sha256: 0da218ff69b8f6c6570180305df491e6ce1efb3e673940e997334006768a8673
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
require 'application.rb' require 'drb/drb' class NetService<Application include DRbUndumped attr_reader :valid def initialize(cluster,options) super @port=options[:port] @uri="druby://127.0.0.1:#{@port}" @drb=nil @valid=false end def shutdown assert{@valid} log "NetServer Shutting down service #{@uri}" @drb.stop_service if @drb @thread.kill if @thread log "NetServer Shut down service #{@uri}" assert { NetService::checkPort(@port) } end def stop shutdown end def run assert{@drb.nil?} @thread=Thread.new { begin loop do begin this=self log "NetServer starting #{@uri}" @drb=DRb.start_service(@uri,this) log "NetServer started" @valid=true break rescue Errno::EADDRINUSE=>e log "#{self.class} could not be started - port blocked" sleep(20) end end loop do cron sleep(10) end rescue Exception=>e pp e.backtrace #pp caller end } end def cron end def self.checkPort(port) begin p=TCPServer.new('127.0.0.1',port) p.close return true rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR, Errno::EAFNOSUPPORT,Errno::EADDRINUSE return false end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
appswarm-0.0.1 | lib/appswarm/net_service.rb |