fairy 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +674 -0
- data/Makefile +116 -0
- data/README +15 -0
- data/bin/fairy +582 -0
- data/bin/fairy-cat +74 -0
- data/bin/fairy-cp +128 -0
- data/bin/fairy-rm +122 -0
- data/bin/subcmd/controller +41 -0
- data/bin/subcmd/inspector +81 -0
- data/bin/subcmd/master +43 -0
- data/bin/subcmd/node +47 -0
- data/bin/subcmd/processor +54 -0
- data/doc/programming-interface.html +240 -0
- data/doc/programming-interface.rd +300 -0
- data/etc/fairy.conf.tmpl +118 -0
- data/ext/simple_hash/extconf.rb +4 -0
- data/ext/simple_hash/simple_hash.c +42 -0
- data/fairy.gemspec +60 -0
- data/lib/fairy/client/addins.rb +20 -0
- data/lib/fairy/client/barrier.rb +29 -0
- data/lib/fairy/client/basic-group-by.rb +52 -0
- data/lib/fairy/client/cat.rb +41 -0
- data/lib/fairy/client/direct-product.rb +51 -0
- data/lib/fairy/client/equijoin.rb +79 -0
- data/lib/fairy/client/exec.rb +54 -0
- data/lib/fairy/client/filter.rb +62 -0
- data/lib/fairy/client/find.rb +35 -0
- data/lib/fairy/client/group-by.rb +194 -0
- data/lib/fairy/client/here.rb +84 -0
- data/lib/fairy/client/inject.rb +70 -0
- data/lib/fairy/client/input-file.rb +53 -0
- data/lib/fairy/client/input-iota.rb +49 -0
- data/lib/fairy/client/input-local-file.rb +188 -0
- data/lib/fairy/client/input-varray.rb +30 -0
- data/lib/fairy/client/input.rb +42 -0
- data/lib/fairy/client/io-filter.rb +26 -0
- data/lib/fairy/client/junction.rb +31 -0
- data/lib/fairy/client/map.rb +34 -0
- data/lib/fairy/client/merge-group-by.rb +71 -0
- data/lib/fairy/client/output-file.rb +64 -0
- data/lib/fairy/client/output-local-file.rb +60 -0
- data/lib/fairy/client/output-null.rb +47 -0
- data/lib/fairy/client/output-varray.rb +50 -0
- data/lib/fairy/client/output.rb +29 -0
- data/lib/fairy/client/roma-put.rb +62 -0
- data/lib/fairy/client/roma.rb +156 -0
- data/lib/fairy/client/seg-join.rb +61 -0
- data/lib/fairy/client/seg-map.rb +78 -0
- data/lib/fairy/client/seg-shuffle.rb +35 -0
- data/lib/fairy/client/seg-split.rb +27 -0
- data/lib/fairy/client/seg-zip.rb +60 -0
- data/lib/fairy/client/select.rb +38 -0
- data/lib/fairy/client/sort.rb +48 -0
- data/lib/fairy/client/sort18.rb +56 -0
- data/lib/fairy/client/sort19.rb +61 -0
- data/lib/fairy/client/there.rb +47 -0
- data/lib/fairy/client/top_n_into_roma.rb +34 -0
- data/lib/fairy/client/wc.rb +92 -0
- data/lib/fairy/controller.rb +1103 -0
- data/lib/fairy/logger.rb +107 -0
- data/lib/fairy/master/addins.rb +20 -0
- data/lib/fairy/master/atom.rb +17 -0
- data/lib/fairy/master/c-barrier.rb +283 -0
- data/lib/fairy/master/c-basic-group-by.rb +250 -0
- data/lib/fairy/master/c-cat.rb +159 -0
- data/lib/fairy/master/c-direct-product.rb +203 -0
- data/lib/fairy/master/c-exec.rb +68 -0
- data/lib/fairy/master/c-filter.rb +422 -0
- data/lib/fairy/master/c-find.rb +138 -0
- data/lib/fairy/master/c-group-by.rb +64 -0
- data/lib/fairy/master/c-here.rb +80 -0
- data/lib/fairy/master/c-inject.rb +119 -0
- data/lib/fairy/master/c-input-file.rb +46 -0
- data/lib/fairy/master/c-input-iota.rb +66 -0
- data/lib/fairy/master/c-input-local-file.rb +117 -0
- data/lib/fairy/master/c-input-varray.rb +53 -0
- data/lib/fairy/master/c-input.rb +24 -0
- data/lib/fairy/master/c-inputtable.rb +31 -0
- data/lib/fairy/master/c-inputtable18.rb +36 -0
- data/lib/fairy/master/c-inputtable19.rb +35 -0
- data/lib/fairy/master/c-io-filter.rb +28 -0
- data/lib/fairy/master/c-junction.rb +54 -0
- data/lib/fairy/master/c-map.rb +27 -0
- data/lib/fairy/master/c-merge-group-by.rb +241 -0
- data/lib/fairy/master/c-output-file.rb +84 -0
- data/lib/fairy/master/c-output-local-file.rb +19 -0
- data/lib/fairy/master/c-output-null.rb +45 -0
- data/lib/fairy/master/c-output-varray.rb +57 -0
- data/lib/fairy/master/c-output.rb +20 -0
- data/lib/fairy/master/c-seg-join.rb +141 -0
- data/lib/fairy/master/c-seg-map.rb +26 -0
- data/lib/fairy/master/c-seg-shuffle.rb +87 -0
- data/lib/fairy/master/c-seg-split.rb +110 -0
- data/lib/fairy/master/c-seg-zip.rb +132 -0
- data/lib/fairy/master/c-select.rb +27 -0
- data/lib/fairy/master/c-sort.rb +108 -0
- data/lib/fairy/master/c-there.rb +57 -0
- data/lib/fairy/master/c-wc.rb +232 -0
- data/lib/fairy/master/job-interpriter.rb +19 -0
- data/lib/fairy/master/scheduler.rb +24 -0
- data/lib/fairy/master.rb +329 -0
- data/lib/fairy/node/addins.rb +19 -0
- data/lib/fairy/node/p-barrier.rb +95 -0
- data/lib/fairy/node/p-basic-group-by.rb +252 -0
- data/lib/fairy/node/p-direct-product.rb +153 -0
- data/lib/fairy/node/p-exec.rb +30 -0
- data/lib/fairy/node/p-filter.rb +363 -0
- data/lib/fairy/node/p-find.rb +111 -0
- data/lib/fairy/node/p-group-by.rb +1534 -0
- data/lib/fairy/node/p-here.rb +21 -0
- data/lib/fairy/node/p-identity.rb +24 -0
- data/lib/fairy/node/p-inject.rb +127 -0
- data/lib/fairy/node/p-input-file.rb +108 -0
- data/lib/fairy/node/p-input-iota.rb +39 -0
- data/lib/fairy/node/p-input-local-file.rb +61 -0
- data/lib/fairy/node/p-input-varray.rb +26 -0
- data/lib/fairy/node/p-io-filter.rb +28 -0
- data/lib/fairy/node/p-map.rb +40 -0
- data/lib/fairy/node/p-merger-group-by.rb +48 -0
- data/lib/fairy/node/p-output-file.rb +104 -0
- data/lib/fairy/node/p-output-local-file.rb +14 -0
- data/lib/fairy/node/p-output-null.rb +32 -0
- data/lib/fairy/node/p-output-varray.rb +41 -0
- data/lib/fairy/node/p-seg-join.rb +82 -0
- data/lib/fairy/node/p-seg-map.rb +34 -0
- data/lib/fairy/node/p-seg-split.rb +61 -0
- data/lib/fairy/node/p-seg-zip.rb +79 -0
- data/lib/fairy/node/p-select.rb +40 -0
- data/lib/fairy/node/p-single-exportable.rb +90 -0
- data/lib/fairy/node/p-sort.rb +195 -0
- data/lib/fairy/node/p-task.rb +113 -0
- data/lib/fairy/node/p-there.rb +44 -0
- data/lib/fairy/node/p-wc.rb +266 -0
- data/lib/fairy/node.rb +187 -0
- data/lib/fairy/processor.rb +510 -0
- data/lib/fairy/share/base-app.rb +114 -0
- data/lib/fairy/share/block-source.rb +234 -0
- data/lib/fairy/share/conf.rb +396 -0
- data/lib/fairy/share/debug.rb +21 -0
- data/lib/fairy/share/encoding.rb +17 -0
- data/lib/fairy/share/fast-tempfile.rb +93 -0
- data/lib/fairy/share/file-place.rb +176 -0
- data/lib/fairy/share/hash-1.rb +20 -0
- data/lib/fairy/share/hash-md5.rb +28 -0
- data/lib/fairy/share/hash-murmur.rb +69 -0
- data/lib/fairy/share/hash-rb18.rb +20 -0
- data/lib/fairy/share/hash-simple-hash.rb +28 -0
- data/lib/fairy/share/inspector.rb +16 -0
- data/lib/fairy/share/lc/exceptions.rb +82 -0
- data/lib/fairy/share/lc/ja/exceptions.rb +81 -0
- data/lib/fairy/share/locale.rb +17 -0
- data/lib/fairy/share/log.rb +215 -0
- data/lib/fairy/share/pool-dictionary.rb +53 -0
- data/lib/fairy/share/port-marshaled-queue.rb +347 -0
- data/lib/fairy/share/port.rb +1697 -0
- data/lib/fairy/share/reference.rb +45 -0
- data/lib/fairy/share/stdout.rb +56 -0
- data/lib/fairy/share/tr.rb +16 -0
- data/lib/fairy/share/varray.rb +147 -0
- data/lib/fairy/share/vfile.rb +183 -0
- data/lib/fairy/version.rb +8 -0
- data/lib/fairy.rb +206 -0
- data/sample/grep.rb +46 -0
- data/sample/ping.rb +19 -0
- data/sample/sort.rb +102 -0
- data/sample/wordcount.rb +61 -0
- data/spec/README +12 -0
- data/spec/fairy1_spec.rb +31 -0
- data/spec/fairy2_spec.rb +42 -0
- data/spec/fairy3_spec.rb +126 -0
- data/spec/fairy4_spec.rb +63 -0
- data/spec/fairy5_spec.rb +45 -0
- data/spec/fairy6_spec.rb +52 -0
- data/spec/fairy7_spec.rb +58 -0
- data/spec/fairy8_spec.rb +48 -0
- data/spec/mkdat.rb +148 -0
- data/spec/run_all.sh +65 -0
- data/test/testc.rb +7111 -0
- data/tools/cap_recipe/Capfile +144 -0
- data/tools/cap_recipe/cluster.yml.sample +14 -0
- data/tools/fairy_perf_graph.rb +444 -0
- data/tools/git-tag +44 -0
- data/tools/log-analysis.rb +62 -0
- data/tools/svn-ls-diff +38 -0
- data/tools/svn-tags +37 -0
- metadata +298 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "simple_hash"
|
7
|
+
|
8
|
+
module Fairy
|
9
|
+
module HValueGenerator
|
10
|
+
module SimpleHash
|
11
|
+
def SimpleHash.value(key)
|
12
|
+
case key
|
13
|
+
when String
|
14
|
+
Fairy::SimpleHash.hash(key)
|
15
|
+
else
|
16
|
+
ERR::Raise ERR::NoImpliment, "non-string key(#{key.inspect})"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
# module_function :hash
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.create_seed;end
|
23
|
+
def self.new(seed)
|
24
|
+
SimpleHash
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "e2mmap"
|
7
|
+
|
8
|
+
module Fairy
|
9
|
+
|
10
|
+
class BreakCreateNode<Exception;end
|
11
|
+
class AbortCreateNode<Exception;end
|
12
|
+
|
13
|
+
module ERR
|
14
|
+
extend Exception2MessageMapper
|
15
|
+
|
16
|
+
def_exception :CantAcceptBlock,
|
17
|
+
"Can't accept block"
|
18
|
+
def_exception :NodeNotArrived,
|
19
|
+
"Node don't arrived host(%s)"
|
20
|
+
def_exception :NoExistProcessorWithObject,
|
21
|
+
"No Exists Processor within object(%s)"
|
22
|
+
|
23
|
+
def_exception :NoSuchMode,
|
24
|
+
"No such mode(%s)"
|
25
|
+
def_exception :UnrecognizedOption,
|
26
|
+
"Unrecognized option(%s)"
|
27
|
+
|
28
|
+
def_exception :AlreadyAssignedVarriable,
|
29
|
+
"Already assigned varriable(%s)"
|
30
|
+
|
31
|
+
def_exception :NoAssignedVarriable,
|
32
|
+
"No assigned varriable(%s)"
|
33
|
+
|
34
|
+
def_exception :NoSupportClass,
|
35
|
+
"No support class(%s)"
|
36
|
+
|
37
|
+
def_exception :NoVFile,
|
38
|
+
"Not a vfile(%s)"
|
39
|
+
|
40
|
+
def_exception :IllegalVFile,
|
41
|
+
"Illegal vfile"
|
42
|
+
|
43
|
+
def_exception :NoImpliment,
|
44
|
+
"Yet, no impliment(%s)"
|
45
|
+
|
46
|
+
def_exception :NoSupportRubyEncoding,
|
47
|
+
"Ruby(%s) isn't support Encoding"
|
48
|
+
|
49
|
+
def_exception :NoTmpDir,
|
50
|
+
"No exists fairy tmp dir(CONF.TMP_DIR=%s)"
|
51
|
+
|
52
|
+
def_exception :NoLogDir,
|
53
|
+
"No exists fairy log dir(CONF.LOG_FILE=%s)"
|
54
|
+
|
55
|
+
def_exception :CantExecSubcmd,
|
56
|
+
"Can't execute subcommand(%s)"
|
57
|
+
|
58
|
+
module INTERNAL
|
59
|
+
extend Exception2MessageMapper
|
60
|
+
|
61
|
+
def_exception :NoSuchDefiledUserLevelFilter,
|
62
|
+
"No such defined user level filter(%s)"
|
63
|
+
|
64
|
+
def_exception :CantDefExport,
|
65
|
+
"Should have Service name except class(%s)"
|
66
|
+
def_exception :NoRegisterService,
|
67
|
+
"No register service(%s)"
|
68
|
+
|
69
|
+
def_exception :UndefinedPolicy, "Undefined policy(%s)"
|
70
|
+
|
71
|
+
def_exception :UndefinedBackendClass, "Undefined Backend Class"
|
72
|
+
def_exception :UndefinedNodeClass, "Undefined Node Class"
|
73
|
+
|
74
|
+
def_exception :ShouldDefineSubclass, "Should define subclass"
|
75
|
+
|
76
|
+
def_exception :ShouldNotSetInput, "Should not set input(%s)"
|
77
|
+
|
78
|
+
def_exception :MarshalQueueNotEmpty, "Marshal queue no empty"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
# encoding: UTF-8
|
3
|
+
#
|
4
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
5
|
+
#
|
6
|
+
|
7
|
+
require "e2mmap"
|
8
|
+
|
9
|
+
module Fairy
|
10
|
+
extend Exception2MessageMapper
|
11
|
+
|
12
|
+
class BreakCreateNode<Exception;end
|
13
|
+
class AbortCreateNode<Exception;end
|
14
|
+
|
15
|
+
module ERR
|
16
|
+
extend Exception2MessageMapper
|
17
|
+
|
18
|
+
def_exception :CantAcceptBlock,
|
19
|
+
"ブロックは受け付けられません"
|
20
|
+
def_exception :NodeNotArrived,
|
21
|
+
"%s のホスト上でnodeが立ち上がっていません"
|
22
|
+
def_exception :NoExistProcessorWithObject,
|
23
|
+
"%s の存在するプロセッサは存在しません"
|
24
|
+
def_exception :NoSuchMode,
|
25
|
+
"そのモードはありません(%s)"
|
26
|
+
|
27
|
+
def_exception :UnrecognizedOption,
|
28
|
+
"そのオプションは分かりません(%s)"
|
29
|
+
|
30
|
+
def_exception :AlreadyAssignedVarriable,
|
31
|
+
"すでに変数(%s)は登録されています"
|
32
|
+
def_exception :NoAssignedVarriable,
|
33
|
+
"すでに変数(%s)は登録されていません"
|
34
|
+
|
35
|
+
def_exception :NoSupportClass,
|
36
|
+
"そのクラスはサポートしていません(%s)"
|
37
|
+
|
38
|
+
def_exception :NoVFile,
|
39
|
+
"VFileではありません(%s)"
|
40
|
+
def_exception :IllegalVFile,
|
41
|
+
"指定が間違っています"
|
42
|
+
|
43
|
+
def_exception :NoImpliment,
|
44
|
+
"まだ出来ていません(%s)"
|
45
|
+
|
46
|
+
def_exception :NoSupportRubyEncoding,
|
47
|
+
"Ruby(%s)ではエンコーディングの指定はできません"
|
48
|
+
|
49
|
+
def_exception :NoTmpDir,
|
50
|
+
"fairy用のテンポラリディレクトリが存在しません(CONF.TMP_DIR=%s)"
|
51
|
+
|
52
|
+
def_exception :NoLogDir,
|
53
|
+
"fairy用のログディレクトリが存在しません(CONF.LOG_FILE=%s)"
|
54
|
+
|
55
|
+
def_exception :CantExecSubcmd,
|
56
|
+
"サブコマンドが実行できません(%s)"
|
57
|
+
|
58
|
+
module INTERNAL
|
59
|
+
extend Exception2MessageMapper
|
60
|
+
|
61
|
+
def_exception :NoSuchDefiledUserLevelFilter,
|
62
|
+
"ユーザーレベルフィルタ(%s)は定義されていません"
|
63
|
+
def_exception :CantDefExport,
|
64
|
+
"クラス以外を登録するときにはサービス名が必要です(%s)"
|
65
|
+
def_exception :NoRegisterService,
|
66
|
+
"サービス名が登録されていません(%s)"
|
67
|
+
|
68
|
+
def_exception :UndefinedPolicy, "未サポートのポリシー(%s)"
|
69
|
+
|
70
|
+
def_exception :UndefinedBackendClass, "Backend Classが定義されていません"
|
71
|
+
def_exception :UndefinedNodeClass, "Node Classが定義されていません"
|
72
|
+
|
73
|
+
def_exception :ShouldDefineSubclass, "サブクラスで定義してください"
|
74
|
+
|
75
|
+
def_exception :ShouldNotSetInput, "インプットフィルタ(%s)にはinputを設定出来ません"
|
76
|
+
|
77
|
+
def_exception :MarshalQueueNotEmpty, "Marshal queue は Emptyでなくてはなりません"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'irb/src_encoding'
|
8
|
+
require "irb/magic-file"
|
9
|
+
rescue LoadError
|
10
|
+
end
|
11
|
+
require "irb/locale"
|
12
|
+
|
13
|
+
module Fairy
|
14
|
+
LC_MESSAGES = IRB::Locale.new
|
15
|
+
LC_MESSAGES.load(CONF.LIB+"/fairy/share/exceptions.rb")
|
16
|
+
end
|
17
|
+
|
@@ -0,0 +1,215 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
require "thread"
|
7
|
+
require "stringio"
|
8
|
+
|
9
|
+
require "forwardable"
|
10
|
+
|
11
|
+
require "deep-connect/future"
|
12
|
+
|
13
|
+
module Fairy
|
14
|
+
class Log
|
15
|
+
|
16
|
+
LEVELS = [:FATAL, :ERROR, :WARN, :INFO, :VERBOSE, :DEBUG]
|
17
|
+
MESSAGE_LEVEL = CONF.LOG_LEVEL
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@logger = nil
|
21
|
+
@host = `hostname`.chomp
|
22
|
+
@type = $0
|
23
|
+
@pid = nil
|
24
|
+
|
25
|
+
@export_thread = nil
|
26
|
+
|
27
|
+
@mutex = Mutex.new
|
28
|
+
|
29
|
+
@puts_mutex = Mutex.new
|
30
|
+
|
31
|
+
@buffer = []
|
32
|
+
@buffer_mutex = Mutex.new
|
33
|
+
@buffer_cv = ConditionVariable.new
|
34
|
+
|
35
|
+
set_local_output_dev
|
36
|
+
|
37
|
+
start_exporter
|
38
|
+
end
|
39
|
+
|
40
|
+
def start_exporter
|
41
|
+
@export_thread = Thread.start {
|
42
|
+
loop do
|
43
|
+
buf = nil
|
44
|
+
@buffer_mutex.synchronize do
|
45
|
+
while @buffer.empty?
|
46
|
+
@buffer_cv.wait(@buffer_mutex)
|
47
|
+
end
|
48
|
+
buf = @buffer.dup
|
49
|
+
@buffer.clear
|
50
|
+
end
|
51
|
+
@logger.messages(buf)
|
52
|
+
end
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def set_local_output_dev(dev = CONF.LOG_LOCAL_OUTPUT_DEV)
|
57
|
+
case dev
|
58
|
+
when nil
|
59
|
+
@LOCAL_OUTPUT_DEV = nil
|
60
|
+
when String, Symbol
|
61
|
+
begin
|
62
|
+
@LOCAL_OUTPUT_DEV = eval(dev.to_s)
|
63
|
+
rescue
|
64
|
+
Log::warn(self, "Can't set local output dev")
|
65
|
+
Log::warn(self, "Use old local output dev")
|
66
|
+
end
|
67
|
+
else
|
68
|
+
@LOCAL_OUTPUT_DEV = dev
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
@the_log = Log.new unless @the_log
|
73
|
+
|
74
|
+
class<<self
|
75
|
+
extend Forwardable
|
76
|
+
|
77
|
+
def_delegator :@the_log, :set_local_output_dev
|
78
|
+
|
79
|
+
def method_added(method)
|
80
|
+
(class<<self;self;end).def_delegator :@the_log, method
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
attr_accessor :logger
|
85
|
+
attr_reader :host
|
86
|
+
attr_accessor :type
|
87
|
+
attr_accessor :pid
|
88
|
+
attr_accessor :LOCAL_OUTPUT_DEV
|
89
|
+
|
90
|
+
def stop_export
|
91
|
+
@export_thread.exit
|
92
|
+
end
|
93
|
+
|
94
|
+
def log(sender, str = nil, &block)
|
95
|
+
bt = caller(0).select{|l| /fairy.*(share\/log)|__FORWARDABLE__|forwardable/ !~ l}
|
96
|
+
bt.first =~ /\/([^\/]*\.rb):([0-9]+):in `(.*)'$/
|
97
|
+
file_name = $1
|
98
|
+
line_no = $2
|
99
|
+
method = $3
|
100
|
+
|
101
|
+
if sender.kind_of?(String)
|
102
|
+
str = sender
|
103
|
+
sender_type = "[UNDEF]"
|
104
|
+
else
|
105
|
+
begin
|
106
|
+
sender_type = sender.log_id
|
107
|
+
rescue
|
108
|
+
sender_type = sender.class.name.sub(/Fairy::/, "")
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
time = Time.now
|
113
|
+
prefix = time.strftime("%Y/%m/%d %H:%M:%S")
|
114
|
+
prefix.concat sprintf(".%06d %s ", time.usec, @host)
|
115
|
+
mes = sprintf("%s%s%s %s[%s] %s#%s: ",
|
116
|
+
@type,
|
117
|
+
@pid ? "\##{@pid}": "",
|
118
|
+
Thread.current["name"] ? Thread.current["name"]: "",
|
119
|
+
file_name, line_no,
|
120
|
+
sender_type, method)
|
121
|
+
if block_given?
|
122
|
+
sio = StringIO.new(mes, "a+")
|
123
|
+
yield sio
|
124
|
+
else
|
125
|
+
mes.concat str
|
126
|
+
end
|
127
|
+
mes.chomp!
|
128
|
+
|
129
|
+
if @LOCAL_OUTPUT_DEV
|
130
|
+
@puts_mutex.synchronize do
|
131
|
+
begin
|
132
|
+
@LOCAL_OUTPUT_DEV.local_stdout.puts mes
|
133
|
+
rescue
|
134
|
+
@LOCAL_OUTPUT_DEV.puts mes
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
if @logger
|
140
|
+
@buffer_mutex.synchronize do
|
141
|
+
@buffer.push prefix+mes
|
142
|
+
@buffer_cv.signal
|
143
|
+
end
|
144
|
+
else
|
145
|
+
$stdout.puts "****Loggerが設定されていません****"
|
146
|
+
end
|
147
|
+
end
|
148
|
+
#alias stdout_puts puts
|
149
|
+
alias puts log
|
150
|
+
|
151
|
+
# Log::log(sender, format, args...)
|
152
|
+
# Log::log(format, args,...)
|
153
|
+
def logf(sender, format=nil, *args)
|
154
|
+
log(sender, sprintf(format, *args))
|
155
|
+
end
|
156
|
+
alias printf logf
|
157
|
+
|
158
|
+
# Log::log_exception(sender, exception, level = :WARN)
|
159
|
+
# Log::log_exception(exception, level = :WARN)
|
160
|
+
def log_exception(sender = $!, exception=$!)
|
161
|
+
if sender.kind_of?(Exception)
|
162
|
+
exception = sender
|
163
|
+
sender = "UNDEF"
|
164
|
+
end
|
165
|
+
log(sender) do |sio|
|
166
|
+
sio.puts "#{exception.message}: #{exception.class}"
|
167
|
+
for l in exception.backtrace
|
168
|
+
sio.puts l
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
def log_backtrace(sender = nil)
|
174
|
+
log(sender) do |sio|
|
175
|
+
for l in caller(0)
|
176
|
+
sio.puts l
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def nop(*args); end
|
182
|
+
|
183
|
+
range = LEVELS[0..LEVELS.index(MESSAGE_LEVEL)]
|
184
|
+
if range
|
185
|
+
for level in range
|
186
|
+
method = level.id2name.downcase
|
187
|
+
alias_method method, :log
|
188
|
+
alias_method method+"f", :logf
|
189
|
+
alias_method method+"_exception", :log_exception
|
190
|
+
alias_method method+"_backtrace", :log_backtrace
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
range = LEVELS[LEVELS.index(MESSAGE_LEVEL)+1.. -1]
|
195
|
+
if range
|
196
|
+
for level in range
|
197
|
+
method = level.id2name.downcase
|
198
|
+
alias_method method, :nop
|
199
|
+
alias_method method+"f", :nop
|
200
|
+
alias_method method+"_exception", :nop
|
201
|
+
alias_method method+"_backtrace", :nop
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
if MESSAGE_LEVEL == :DEBUG
|
206
|
+
def debug_p(*objs)
|
207
|
+
for o in objs
|
208
|
+
log(self, o.inspect)
|
209
|
+
end
|
210
|
+
end
|
211
|
+
else
|
212
|
+
def debug_p(*args);end
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
#
|
3
|
+
# Copyright (C) 2007-2010 Rakuten, Inc.
|
4
|
+
#
|
5
|
+
|
6
|
+
module Fairy
|
7
|
+
class PoolDictionary
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@pool = {}
|
11
|
+
@pool_mutex = Mutex.new
|
12
|
+
@pool_cv = ConditionVariable.new
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :pool_mutex
|
16
|
+
attr_reader :pool_cv
|
17
|
+
|
18
|
+
def def_variable(vname, value = nil)
|
19
|
+
@pool_mutex.synchronize do
|
20
|
+
if @pool.key?(vname)
|
21
|
+
ERR::Raise ERR::AlreadyAssignedVarriable, vname
|
22
|
+
end
|
23
|
+
case value
|
24
|
+
when DeepConnect::Reference
|
25
|
+
@pool[vname] = value.dc_deep_copy
|
26
|
+
else
|
27
|
+
@pool[vname] = value
|
28
|
+
end
|
29
|
+
|
30
|
+
instance_eval "def #{vname}; self[:#{vname}]; end"
|
31
|
+
instance_eval "def #{vname}=(v); self[:#{vname}]=v; end"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
def [](name)
|
35
|
+
@pool_mutex.synchronize do
|
36
|
+
ERR::Raise NoAssignedVarriable, name unless @pool.key?(name)
|
37
|
+
@pool[name]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def []=(name, value)
|
42
|
+
@pool_mutex.synchronize do
|
43
|
+
ERR::Raise NoAssignedVarriable, name unless @pool.key?(name)
|
44
|
+
case value
|
45
|
+
when DeepConnect::Reference
|
46
|
+
@pool[name] = value.dc_deep_copy
|
47
|
+
else
|
48
|
+
@pool[name] = value
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|