Class: Distem::Events::Trace

Inherits:
Object
  • Object
show all
Defined in:
lib/distem/events/trace.rb

Overview

Event trace

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Trace) initialize

Returns a new instance of Trace



12
13
14
15
# File 'lib/distem/events/trace.rb', line 12

def initialize
  @event_list = []
  @mutex = Mutex.new
end

Instance Attribute Details

- (Object) event_list (readonly)

Array of all event associate to this trace - format : [[ date, event ], … ]



10
11
12
# File 'lib/distem/events/trace.rb', line 10

def event_list
  @event_list
end

Instance Method Details

- (Object) add_event(date, event)



24
25
26
27
28
# File 'lib/distem/events/trace.rb', line 24

def add_event(date, event)
  raise "Wrong type : Event expected, got #{event.class}" unless event.is_a?(Event)
  raise "Wrong type : date : Numeric expected, got #{date.class}" unless date.is_a?(Numeric)
  add_event_list([[date, event]])
end

- (Object) add_event_list(event_list)



17
18
19
20
21
22
# File 'lib/distem/events/trace.rb', line 17

def add_event_list(event_list)
  @mutex.synchronize do
    @event_list += event_list
    @event_list.sort!
  end
end

- (Object) clear



38
39
40
41
42
# File 'lib/distem/events/trace.rb', line 38

def clear
  @mutex.synchronize do
    @event_list.clear
  end
end

- (Object) pop_next_event



30
31
32
33
34
35
36
# File 'lib/distem/events/trace.rb', line 30

def pop_next_event
  next_event = nil
  @mutex.synchronize do
    next_event = @event_list.delete_at(0)
  end
  return next_event
end