lib/ernie.rb in ernie-2.1.0 vs lib/ernie.rb in ernie-2.2.0
- old
+ new
@@ -4,12 +4,15 @@
class Ernie
class << self
attr_accessor :mods, :current_mod, :log
attr_accessor :auto_start
+ attr_accessor :count, :virgin_procline
end
+ self.count = 0
+ self.virgin_procline = $0
self.mods = {}
self.current_mod = nil
self.log = Logger.new(STDOUT)
self.log.level = Logger::FATAL
self.auto_start = true
@@ -115,28 +118,33 @@
# Start the processing loop.
#
# Loops forever
def self.start
+ self.procline('starting')
self.log.info("(#{Process.pid}) Starting")
self.log.debug(self.mods.inspect)
input = IO.new(3)
output = IO.new(4)
input.sync = true
output.sync = true
loop do
+ self.procline('waiting')
iruby = self.read_berp(input)
+ self.count += 1
+
unless iruby
puts "Could not read BERP length header. Ernie server may have gone away. Exiting now."
self.log.info("(#{Process.pid}) Could not read BERP length header. Ernie server may have gone away. Exiting now.")
exit!
end
if iruby.size == 4 && iruby[0] == :call
mod, fun, args = iruby[1..3]
+ self.procline("#{mod}:#{fun}(#{args})")
self.log.info("-> " + iruby.inspect)
begin
res = self.dispatch(mod, fun, args)
oruby = t[:reply, res]
self.log.debug("<- " + oruby.inspect)
@@ -152,24 +160,39 @@
self.log.error(e.backtrace.join("\n"))
write_berp(output, oruby)
end
elsif iruby.size == 4 && iruby[0] == :cast
mod, fun, args = iruby[1..3]
+ self.procline("#{mod}:#{fun}(#{args})")
self.log.info("-> " + [:cast, mod, fun, args].inspect)
begin
self.dispatch(mod, fun, args)
rescue Object => e
# ignore
end
write_berp(output, t[:noreply])
else
+ self.procline("invalid request")
self.log.error("-> " + iruby.inspect)
oruby = t[:error, t[:server, 0, "Invalid request: #{iruby.inspect}"]]
self.log.error("<- " + oruby.inspect)
write_berp(output, oruby)
end
end
end
+
+ def self.procline(msg)
+ $0 = "ernie handler #{VERSION} (ruby) - #{self.virgin_procline} - [#{self.count}] #{msg}"[0..159]
+ end
+
+ def self.version
+ yml = YAML.load(File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION.yml])))
+ "#{yml[:major]}.#{yml[:minor]}.#{yml[:patch]}"
+ rescue
+ 'unknown'
+ end
+
+ VERSION = self.version
end
class Ernie::ServerError < StandardError; end
class Ernie::Mod