Class: SoldierOfCode::DejaVu::Recorder
- Inherits:
-
Object
- Object
- SoldierOfCode::DejaVu::Recorder
- Defined in:
- lib/deja-vu/recorder.rb
Instance Attribute Summary collapse
-
#identifier ⇒ Object
@@writing = {} unless defined? @@writing.
Instance Method Summary collapse
- #export(to_file_named) ⇒ Object
- #identifier_change(new_identifier) ⇒ Object
-
#initialize(opt) ⇒ Recorder
constructor
A new instance of Recorder.
- #record(env, resp, req, start_time, end_time, identifier) ⇒ Object
Constructor Details
#initialize(opt) ⇒ Recorder
Returns a new instance of Recorder.
14 15 16 17 18 19 |
# File 'lib/deja-vu/recorder.rb', line 14 def initialize(opt) @identifier = opt['cookie_name'] @opt = opt @foo = Time.new.to_i end |
Instance Attribute Details
#identifier ⇒ Object
@@writing = {} unless defined? @@writing
def self.writing?(file_name)
@@writing[file_name]
end
12 13 14 |
# File 'lib/deja-vu/recorder.rb', line 12 def identifier @identifier end |
Instance Method Details
#export(to_file_named) ⇒ Object
21 22 23 |
# File 'lib/deja-vu/recorder.rb', line 21 def export(to_file_named) # TODO -- IMPLEMENT THIS end |
#identifier_change(new_identifier) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/deja-vu/recorder.rb', line 120 def identifier_change(new_identifier) DejaVuNS.transaction do # puts "#{__FILE__}:#{__LINE__} #{Thread.current} IDENTIFIER CHANGE" recording = DejaVuNS::Recording.find_by_identifier(@identifier) if recording # puts "#{__FILE__}:#{__LINE__} #{Thread.current} IDENTIFIER CHANGE HERE" @identifier = new_identifier recording. = new_identifier # puts "#{__FILE__}:#{__LINE__} #{Thread.currentta} IDENTIFIER CHANGE HERE #{recording.cookie}" end end end |
#record(env, resp, req, start_time, end_time, identifier) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/deja-vu/recorder.rb', line 28 def record(env, resp, req, start_time, end_time, identifier) # status, headers, body # resp[0], resp[1], resp[2] # 1. try to locate the recording recording = nil # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} INSIDE RECORD - STARTING TXN" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" DejaVuNS.transaction do #puts "#{__FILE__}:#{__LINE__} #{Thread.current} JUST INSIDE" recording = DejaVuNS::Recording.find_by_identifier(@identifier) #puts "#{__FILE__}:#{__LINE__} #{Thread.current} RECORDING FOUND: #{recording.pid}" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} #{recording.class.name}" # 1.b if not found then create a new one unless recording #puts "#{__FILE__}:#{__LINE__} #{Thread.current} " recording = DejaVuNS.root.new_recording(DejaVuNS.pid_from_string(@identifier||identifier)) recording. = req.[@identifier||identifier] recording.stamp = Time.new.to_i recording.agent = env['HTTP_USER_AGENT'] recording.ip = env['REMOTE_ADDR'] #puts "#{__FILE__}:#{__LINE__} #{Thread.current} " end # 2. create a new record # puts "#{__FILE__}:#{__LINE__} #{Thread.current} #{recording.class.name}" #puts "#{__FILE__}:#{__LINE__} #{Thread.current} " record = recording.new_record("#{Time.new.to_i}") #puts "#{__FILE__}:#{__LINE__} #{Thread.current} " record.stamp = "#{Time.new.to_i}" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} " record.status = "#{resp[0]}" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} " record.httpmethod = env['REQUEST_METHOD'] # puts "#{__FILE__}:#{__LINE__} #{Thread.current} " record.url = "#{env['rack.url_scheme']}://#{env['HTTP_HOST']}#{env['REQUEST_URI']}" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} " record.request_time = ("#{end_time.to_i}.#{end_time.usec}".to_f - "#{start_time.to_i}.#{start_time.usec}".to_f).to_s # puts "#{__FILE__}:#{__LINE__} #{Thread.current} " # 3. add the body etc elements resp[1].each do |k, v| h = record.new_header h.name = k h.value = v end # puts "#{__FILE__}:#{__LINE__} #{Thread.current} " record.new_body().content = "<![CDATA[#{resp[2]}]]>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} " if req.post? && env['CONTENT_TYPE'] =~ %r|\Amultipart/form-data.*boundary=\"?([^\";,]+)\"?|n # its multipart # <multipart-reference name="" file-path=""/> # can I grab it off the env object? puts "#{__FILE__}:#{__LINE__} #{Thread.current} NOT IMPLEMENTED - MULTIPART" else # puts "#{__FILE__}:#{__LINE__} #{Thread.current} " # safe param recording req.params.each do |k,v| p = record.new_param() p.name = k p.value = v end # puts "#{__FILE__}:#{__LINE__} #{Thread.current} " end # puts "#{__FILE__}:#{__LINE__} #{Thread.current} ABOUT TO PRINT XML" STDOUT.flush # puts "#{__FILE__}:#{__LINE__} #{Thread.current} #{recording.pp_xml}" end # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} DONE TXN" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" # puts "#{__FILE__}:#{__LINE__} #{Thread.current} >>>>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>" end |