From c8d68f41b1b38ec6035abc9fc3de41eb7e6bd4c0 Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Wed, 31 Mar 2010 00:31:00 +0200 Subject: [PATCH] bin/bos* removed. Status-informations every 5 seconds added --- bin/box.rb | 67 --------------------------------- bin/box2.rb | 87 ------------------------------------------- bin/box3.rb | 22 ----------- lib/logan/inc/main.rb | 12 +++++- 4 files changed, 11 insertions(+), 177 deletions(-) delete mode 100755 bin/box.rb delete mode 100755 bin/box2.rb delete mode 100755 bin/box3.rb diff --git a/bin/box.rb b/bin/box.rb deleted file mode 100755 index 7515402..0000000 --- a/bin/box.rb +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/ruby - -require 'thread' - -class Box - attr_reader :_, :emited - alias db emited - alias persistent emited - attr_accessor :emited - - def initialize db, _ - @_, @emited = _, db - end - - def emit k, v - @emited[k] = v - end - - def do code - instance_eval code, self.class.to_s, 0 - end -end - -require 'sbdb' - -class Persistent - include Enumerable - def initialize( db) @db, @cursor = db, db.cursor end - def emit( k, v) @db[k] = v end - alias push emit - alias put emit - alias []= emit - def get( k) @db[k] end - alias [] get - alias fetch get - def inspect() "#<%s:0x%016x>" % [ self.class, self.object_id ] end - def each &e - e ? @cursor.each( &e) : Enumerator.new( self, :each) - end - def to_hash - h = {} - each {|k, v| h[ k] = v } - h - end -end - -#Persistent.freeze - -r = nil -Dir.mkdir 'logs' rescue Errno::EEXIST -SBDB::Env.new 'logs', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION do |logs| - db = Persistent.new logs['test', :type => SBDB::Btree, :flags => SBDB::CREATE] - $stdout.print "(0)$ " - STDIN.each_with_index do |l, i| - r = Thread.new do - l.untaint - $SAFE = 4 - b = Box.new db, r - begin - b.do( l) - rescue Object - $! - end - end.value - $stdout.print "=> #{r.inspect}\n(#{i+1})$ " - end -end diff --git a/bin/box2.rb b/bin/box2.rb deleted file mode 100755 index dd02b06..0000000 --- a/bin/box2.rb +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/ruby - -require 'sbdb' - -module Sandbox - def self.run *paras, &exe - exe = paras.shift unless exe - box = paras.shift || Class - Thread.new do - $SAFE = 4 - this = box.new *paras - begin - [:value, this.instance_eval( exe, "Sandbox")] - rescue Object - [:exception, $!] - end - end.value - end - - def self.create_class *paras, &exe - exe = paras.shift unless exe - run Class, *paras do - eval exe - self - end - end - alias new_class create_class -end - -class Box - attr_reader :_, :db - - def initialize db, _ - @_, @db = _, db - end - - def put( key, val) @db[key] = val end - def get( key) @db[key] end -end - -class ClassBuilder -end - -class Emit - def initialize( db) @db = db end - def emit( key, val) @db[key] = val end - def inspect() "#<%s:0x%016x>" % [ self.class, self.object_id ] end -end - -class Persistent < Emit - include Enumerable - def initialize db, cursor - super db - @cursor = cursor - end - alias put emit - alias []= emit - def get( key) @db[key] end - alias [] get - alias fetch get - def each &exe - exe ? @cursor.each( &exe) : Enumerator.new( self, :each) - end - def to_hash - rh = {} - each {|key, val| rh[ key] = val } - rh - end -end - -_ = nil -Dir.mkdir 'logs' rescue Errno::EEXIST -SBDB::Env.new 'logs', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION do |logs| - db = logs['test', :type => SBDB::Btree, :flags => SBDB::CREATE] - db = Persistent.new db, db.cursor - $stdout.print "(0)$ " - STDIN.each_with_index do |line, i| - ret = Sandbox.run line, Box, db, _ - if :value == ret.first - _ = ret.last - $stdout.puts "=> #{ret.last.inspect}" - else - $stdout.puts ret.last.inspect - end - $stdout.print "(#{i+1})$ " - end -end diff --git a/bin/box3.rb b/bin/box3.rb deleted file mode 100755 index beae5a7..0000000 --- a/bin/box3.rb +++ /dev/null @@ -1,22 +0,0 @@ -#!/usr/bin/ruby - -require 'sbdb' -require 'safebox' - -_ = nil -Dir.mkdir 'logs' rescue Errno::EEXIST -SBDB::Env.new 'logs', SBDB::CREATE | SBDB::Env::INIT_TRANSACTION do |logs| - db = logs['test', :type => SBDB::Btree, :flags => SBDB::CREATE] - db = Safebox::Persistent.new db, db.cursor - $stdout.print "(0)$ " - STDIN.each_with_index do |line, i| - ret = Safebox.run line, Safebox::Box, db, _ - if :value == ret.first - _ = ret.last - $stdout.puts "=> #{ret.last.inspect}" - else - $stdout.puts ret.last.inspect - end - $stdout.print "(#{i+1})$ " - end -end diff --git a/lib/logan/inc/main.rb b/lib/logan/inc/main.rb index e849d4d..f5578ad 100644 --- a/lib/logan/inc/main.rb +++ b/lib/logan/inc/main.rb @@ -74,8 +74,18 @@ module LogAn::Inc LogAn::Inc::FileParser::Base.store = LogAn::Inc::SID0.store = stores end + # Select-framework + @select = LogAn::Inc::Select.new + status = lambda do + @select.at Time.now+5, &status + $stderr.puts "#{Time.now.strftime"%H:%M:%S"}|INFO|Statistic|#{@select.inspect}" + @conf[:stores].source.source.flush! + end + status.call + # Prepare Inc-server - create server - @serv = LogAn::Inc::Server.new :sock => TCPServer.new( *@conf[:server]), :config => @conf[:configs] + @serv = LogAn::Inc::Server.new :sock => TCPServer.new( *@conf[:server]), :config => @conf[:configs], :select => @select + $stderr.puts @serv.inspect # Shutdown on signals @sigs[:INT] = @sigs[:TERM] = method( :shutdown)