Class: ExcADG::VTracker

Inherits:
Object
  • Object
show all
Defined in:
lib/excadg/vtracker.rb

Overview

tracker for Vertex-es graph: it’s hooked by Broker to register dependencies polling (and other) events and make an actual graph of vertices with states in runtime

it’s not possible to do this in other way, because vertices can be spawned:

  • in any order => code is not guaranteed to know the full graph (even static one)

  • dynamically => there is no central place but Broker that’s aware of all vertices

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeVTracker

Returns a new instance of VTracker.



16
17
18
19
# File 'lib/excadg/vtracker.rb', line 16

def initialize
  @graph = RGL::DirectedAdjacencyGraph.new
  @by_state = {}
end

Instance Attribute Details

#by_stateObject (readonly)

Returns the value of attribute by_state.



14
15
16
# File 'lib/excadg/vtracker.rb', line 14

def by_state
  @by_state
end

#graphObject (readonly)

Returns the value of attribute graph.



14
15
16
# File 'lib/excadg/vtracker.rb', line 14

def graph
  @graph
end

Instance Method Details

#get_deps(vertex) ⇒ Object

get all vertex’s dependencies

Parameters:

  • vertex (Vertex)

    vertex to lookup known dependencies for



43
44
45
# File 'lib/excadg/vtracker.rb', line 43

def get_deps vertex
  @graph.adjacent_vertices vertex
end

#track(vertex, deps = []) ⇒ Object

register the vertex and its new known deps in the @graph and by_state cache

Parameters:

  • vertice

    vertice that requested info about deps

  • deps (defaults to: [])

    list of dependencies as supplied by Request::GetStateData



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/excadg/vtracker.rb', line 24

def track vertex, deps = []
  Assertions.is_a? vertex, Vertex
  Assertions.is_a? deps, Array

  @graph.add_vertex vertex
  add_to_states_cache vertex, vertex.state

  deps.each { |raw_dep|
    # it could be not a Vertex, so do a lookup through data store
    next unless Broker.instance.data_store[raw_dep]

    dep_data = Broker.instance.data_store[raw_dep]
    add_to_states_cache dep_data.vertex, dep_data.state
    @graph.add_edge vertex, dep_data.vertex
  }
end