Class: ASIR::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/asir/application.rb

Overview

Ugly workaround JRuby’s lack of fork().

Defined Under Namespace

Classes: Spawn

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeApplication

Returns a new instance of Application.



8
9
10
11
# File 'lib/asir/application.rb', line 8

def initialize
  @inc = [ ]
  @name_to_spawn = { }
end

Instance Attribute Details

#incObject

Returns the value of attribute inc.



6
7
8
# File 'lib/asir/application.rb', line 6

def inc
  @inc
end

#verboseObject

Returns the value of attribute verbose.



6
7
8
# File 'lib/asir/application.rb', line 6

def verbose
  @verbose
end

Instance Method Details

#in_spawn?Boolean

class

Returns:

  • (Boolean)


87
88
89
90
91
92
93
94
95
# File 'lib/asir/application.rb', line 87

def in_spawn?
  return @in_spawn unless @in_spawn.nil?
  @in_spawn = false
  $stderr.puts "#{$$} ARGV = #{ARGV.inspect}" if verbose
  if ARGV.size >= 1 and ARGV[0] =~ /^--asir-spawn=(.*)/
    @in_spawn = $1.to_sym
  end
  @in_spawn
end

#mainObject



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/asir/application.rb', line 97

def main
  if in_spawn?
    begin
      name = @in_spawn
      if tmp = ARGV[1]
        out = "#{tmp}.out"
        run = "#{tmp}.run"
        $stdout = $stderr = File.open(out, "w")
        STDOUT.reopen($stdout); STDERR.reopen($stderr)
        File.open(run, "w") { | fh | fh.puts $$ }
      end
      spawn = @name_to_spawn[name]
      raise "#{$$} #{self} Cannot find spawn name #{name.inspect}" unless spawn
      spawn.blk.call
    ensure
      Process.exit!(0)
    end
  end
  yield if block_given?
end

#spawn(name, &blk) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/asir/application.rb', line 13

def spawn name, &blk
  name = name.to_sym
  spawn = Spawn.new
  @name_to_spawn[spawn.name = name] = spawn
  spawn.app = self
  spawn.blk = blk
  spawn
end