bin/bos* removed. Status-informations every 5 seconds added
This commit is contained in:
parent
c4d3e75223
commit
c8d68f41b1
4 changed files with 11 additions and 177 deletions
67
bin/box.rb
67
bin/box.rb
|
@ -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
|
87
bin/box2.rb
87
bin/box2.rb
|
@ -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
|
22
bin/box3.rb
22
bin/box3.rb
|
@ -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
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue