Class: OFlow::Tracker

Inherits:
Object
  • Object
show all
Defined in:
lib/oflow/tracker.rb

Overview

A Tracker is used to track data through the system. They are attached to Boxes and are updated when they are received by Flows and Tasks.

Constant Summary collapse

@@machine =
self.get_machine()
@@pid =
Process.pid
@@last_nano =
0
@@nano_mutex =
Mutex.new()

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#idObject

The identifier of the Tracker.



30
31
32
# File 'lib/oflow/tracker.rb', line 30

def id
  @id
end

#trackObject

The Stamps that were placed in the Tracker as it is received.



32
33
34
# File 'lib/oflow/tracker.rb', line 32

def track
  @track
end

Class Method Details

.create(location, op = nil) ⇒ Object



34
35
36
37
38
# File 'lib/oflow/tracker.rb', line 34

def self.create(location, op=nil)
  t = Tracker.new(gen_id(), [Stamp.new(location, op).freeze()])
  t.track.freeze()
  t.freeze()
end

.get_machineObject

Gets the machine address. This is used for generating unique identifiers for the Tracker instances.



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/oflow/tracker.rb', line 11

def self.get_machine()
  machine = "unknown"
  Socket.ip_address_list.each do |addr|
    next unless addr.ip?
    next if addr.ipv6_linklocal?
    next if addr.ipv4_loopback? || addr.ipv6_loopback?
    next if addr.ipv4_multicast? || addr.ipv6_multicast?
    machine = addr.ip_address
    break
  end
  machine
end

Instance Method Details

#merge(t2) ⇒ Tracker

When a package is split and travels on more than one route the Tracker can be merged with this method. The returned Tracker contains both tracks.

Parameters:

Returns:

Raises:

  • (Exception)


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/oflow/tracker.rb', line 61

def merge(t2)
  raise Exception.new("Can not merge #{t2.id} into #{@id}. Different IDs.") if t2.id != @id
  comb = []
  s2 = t2.track.size
  for i in 0..@track.size
    break if s2 <= i
    unless @track[i] == t2.track[i]
      if @track[-1].location == t2.track[-1].location
        comb << [@track[i..-2], t2.track[i..-2]]
        comb << @track[-1]
      else
        comb << [@track[i..-1], t2.track[i..-1]]
      end
      break
    end
    comb << @track[i]
  end
  comb.freeze
  Tracker.new(@id, comb)
end

#receive(location, op) ⇒ Tracker

Returns an updated instance with a Stamp for the location, operation, and current time.

Parameters:

  • location (String)

    full name of Task where the Tracker was received

  • op (Symbol)

    operation that caused the Stamp to be created

Returns:



45
46
47
48
49
# File 'lib/oflow/tracker.rb', line 45

def receive(location, op)
  t = Tracker.new(@id, Array.new(@track) << Stamp.new(location, op).freeze())
  t.track.freeze()
  t.freeze()
end

#to_sObject Also known as: inspect

Returns a String representation of the Tracker.



52
53
54
# File 'lib/oflow/tracker.rb', line 52

def to_s()
  "Tracker{#{@id}, track: #{@track}}"
end