From: Christopher Aldridge Date: 2005-08-10T08:59:00+09:00 Subject: Re: drb server using file/tail to read file, and update client? Thank you for your response.. This was exactly what I did before asking and I feel like it's hacky.. Do you have an example of the latter instead of the former? Perhaps something with tuplespace/rinda? Here's the code I've been using in case anyone can use it: def Execute(global, system) Thread.new do begin DRb.start_service global['clientConnectionString'], EbdnxClient.new DRb.thread.join rescue DRb::DRbBadURI puts "rescued" Vars.new.session(global) begin DRb.start_service global['clientConnectionString'], EbdnxClient.new DRb.thread.join rescue DRb::DRbBadURI puts "Couldnt bind for monitoring. Exiting." exit 0 end end end sleep 2 begin DRbObject.new(nil, system['connectionString']).Execute(global, system) puts "client> server received job. pending status.." rescue puts "Could not connect to #{system['connectionString']}\ntrying again in 2 seconds..." sleep2 begin DRbObject.new(nil, system['connectionString']).Execute(global, system) rescue puts "Unable to connect to server #{system['connectionString']}" exit 0 end end if system['authFailure'] == "true" puts "Authentication Failure" exit 1 end DRbObject.new(nil, system['connectionString']).Monitor(global, system) if global['output'] != "quiet" end def Monitor(global, system) begin ebdnxLogStructure = "whatever.txt" if File.exists?("B:/LOGS/" + ebdnxLogStructure) == false sleep 7 if File.exists?("B:/LOGS/" + ebdnxLogStructure) == false puts "log file still not found. sleeping 5 and forcing continue." sleep 5 else puts "log file found" end end File::Tail::Logfile.open("B:/LOGS/" + ebdnxLogStructure, :rewind => 5) do |log| log.tail { |line| if /<\/ebdnx>/.match(line) begin StatusToClient.new.Update(line, global) rescue DRb::DRbConnError puts "server> completed." break end else StatusToClient.new.Update(line, global) end } end rescue puts "server> unable to tail log: B:/LOGS/" + ebdnxLogStructure end end Obviously these are implemented in classes but Id like to see a way of updating the client without having start a new drb service(on the client). Is this possible? Thank you!! On 8/9/05, Ryan Leavengood wrote: > Christopher Aldridge said: > > > > Any suggestions or am I doing it the only way it can be done? > > If I understand your problem correctly, the issue is that you now have to > constantly poll the server to see if there are more lines, when really > what you want is to have the server tell the clients of the new lines. > > So your options are either to code the clients so they also have a DRb > server, which the server connects to when outputting lines from the log > file, or possible to use Rinda and a Tuplespace. > > Here is an example of the former: > > Server: > > require 'drb/drb' > > class TailServer > def initialize > @clients = [] > end > > def register(uri) > puts "Client registered at: #{uri}" > @clients << DRbObject.new(nil, uri) > end > > def sendline(line) > puts "Sending line: #{line}" > @clients.each do |c| > c.addline(line) > end > end > end > > ts = TailServer.new > DRb.start_service('druby://localhost:3456', ts) > > # Obviously the code below needs to be replaced with code > # that actually tails the log file > i = 0 > loop do > sleep(5) > ts.sendline("This is line #{i}.") > i+=1 > end > DRb.thread.join > > Client: > > require 'drb/drb' > > class TailClient > def addline(line) > puts line > end > end > > # nil in the first parameter opens a random port > DRb.start_service(nil, TailClient.new) > server = DRbObject.new(nil, 'druby://localhost:3456') > server.register(DRb.uri) > DRb.thread.join > __END__ > > Ryan > >