Class: Pwrake::NBIO::Handler

Inherits:
Object
  • Object
show all
Defined in:
lib/pwrake/nbio.rb

Overview


Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(reader, writer, hostname = nil) ⇒ Handler

Returns a new instance of Handler.



471
472
473
474
475
476
477
478
# File 'lib/pwrake/nbio.rb', line 471

def initialize(reader,writer,hostname=nil)
  @writer = writer
  @reader = reader
  @host = hostname
  @reader.host = @host
  @writer.host = @host
  @exited = false
end

Instance Attribute Details

#hostObject (readonly)

Returns the value of attribute host.



479
480
481
# File 'lib/pwrake/nbio.rb', line 479

def host
  @host
end

#readerObject (readonly)

Returns the value of attribute reader.



479
480
481
# File 'lib/pwrake/nbio.rb', line 479

def reader
  @reader
end

#writerObject (readonly)

Returns the value of attribute writer.



479
480
481
# File 'lib/pwrake/nbio.rb', line 479

def writer
  @writer
end

Class Method Details

.exit(hdl_set) ⇒ Object



539
540
541
542
543
544
545
# File 'lib/pwrake/nbio.rb', line 539

def self.exit(hdl_set)
  hdl_set.each do |hdl|
    Fiber.new do
      hdl.exit
    end.resume
  end
end

.kill(hdl_set, sig) ⇒ Object



531
532
533
534
535
536
537
# File 'lib/pwrake/nbio.rb', line 531

def self.kill(hdl_set,sig)
  hdl_set.each do |hdl|
    Fiber.new do
      hdl.put_kill(sig)
    end.resume
  end
end

Instance Method Details

#exitObject



498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
# File 'lib/pwrake/nbio.rb', line 498

def exit
  iow = @writer.io
  Log.debug "Handler#exit iow=#{iow.inspect}" if defined? Log
  if @exited
    Log.debug "Handler<##{object_id}#exit multiple called" if defined? Log
    bt = caller.join("\n ")
    Log.debug "Handler#exit bt=\n #{bt}" if defined? Log
    return
  end
  @exited = true
  exit_msg = "exited"
  #return if iow.closed?
  @writer.put_line "exit"
  Log.debug "Handler#exit: end: @writer.put_line \"exit\"" if defined? Log
  #
  if @reader.class == Reader # MultiReader not work
    while line = @reader.get_line
      # here might receive "retire:0" from branch...
      line.chomp!
      Log.debug "Handler#exit: #{line} host=#{@host}" if defined? Log
      return if line == exit_msg
    end
  end
rescue Errno::EPIPE => e
  Log.error "Errno::EPIPE in #{self.class}.exit iow=#{iow.inspect}\n"+
    e.backtrace.join("\n") if defined? Log
end

#get_lineObject



481
482
483
# File 'lib/pwrake/nbio.rb', line 481

def get_line
  @reader.get_line
end

#haltObject



526
527
528
529
# File 'lib/pwrake/nbio.rb', line 526

def halt
  @writer.halt
  @reader.halt
end

#put_exitObject



494
495
496
# File 'lib/pwrake/nbio.rb', line 494

def put_exit
  @writer.put_line "exit"
end

#put_kill(sig = "INT") ⇒ Object



489
490
491
492
# File 'lib/pwrake/nbio.rb', line 489

def put_kill(sig="INT")
  @writer.io.write("kill:#{sig}\n")
  @writer.io.flush
end

#put_line(s) ⇒ Object



485
486
487
# File 'lib/pwrake/nbio.rb', line 485

def put_line(s)
  @writer.put_line(s)
end