Class: Msnav::Holder

Inherits:
Object
  • Object
show all
Defined in:
lib/msnav/server.rb

Overview

The msnav daemon: WEBrick serving the coderag daemon's navigation API.

The Holder is the single source of index state (graph + navigator), replaced atomically when the shared DB's index_generation moves — a host-side coderag index or a peer daemon's rebuild hot-reloads every msnav on the hub within a second, requests always see a consistent index.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cfg, service_root: nil, service_name: nil) ⇒ Holder

Returns a new instance of Holder.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/msnav/server.rb', line 17

def initialize(cfg, service_root: nil, service_name: nil)
  @cfg = cfg
  # service scope: this daemon's container sees ONE service's source at
  # this path (msnav never extracts from it — the scope only names which
  # indexed service this window holds, for the extension's path mapping)
  @service_root = service_root
  @service_name = service_name
  @store = Store.new(cfg.db_path)
  # coderag no longer carries window state at all — the registry is
  # msnav-owned, in a sidecar DB inside the same shared storage dir, so
  # every msnav daemon on the hub (one per container) routes opens
  # through the mount exactly like before
  @windows_store = WindowsStore.new(cfg.storage_dir + "msnav-windows.db")
  @windows = WindowRegistry.new(@windows_store)
  @mutex = Mutex.new
  @generation = 0
  @db_generation = @store.index_generation
  @navigator = load_navigator
end

Instance Attribute Details

#cfgObject (readonly)

Returns the value of attribute cfg.



14
15
16
# File 'lib/msnav/server.rb', line 14

def cfg
  @cfg
end

#service_nameObject (readonly)

Returns the value of attribute service_name.



14
15
16
# File 'lib/msnav/server.rb', line 14

def service_name
  @service_name
end

#service_rootObject (readonly)

Returns the value of attribute service_root.



14
15
16
# File 'lib/msnav/server.rb', line 14

def service_root
  @service_root
end

#storeObject (readonly)

Returns the value of attribute store.



14
15
16
# File 'lib/msnav/server.rb', line 14

def store
  @store
end

#windowsObject (readonly)

Returns the value of attribute windows.



14
15
16
# File 'lib/msnav/server.rb', line 14

def windows
  @windows
end

#windows_storeObject (readonly)

Returns the value of attribute windows_store.



14
15
16
# File 'lib/msnav/server.rb', line 14

def windows_store
  @windows_store
end

Instance Method Details

#generationObject



59
60
61
# File 'lib/msnav/server.rb', line 59

def generation
  @mutex.synchronize { @generation }
end

#maybe_reloadObject

Follower path: hot-swap the navigator when another daemon (or a host reindex) moved the persisted generation. True when a reload happened.



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/msnav/server.rb', line 65

def maybe_reload
  gen = @store.index_generation
  return false if gen == @db_generation
  nav = load_navigator
  @mutex.synchronize do
    @navigator = nav
    @generation += 1
    @db_generation = gen
  end
  warn "msnav: index changed in the shared DB — reloaded (generation #{gen})"
  true
end


55
56
57
# File 'lib/msnav/server.rb', line 55

def navigator
  @mutex.synchronize { @navigator }
end

#scopeObject

A service-scoped daemon's identity: the container path holding the service and its canonical (host) location from the shared DB — the exact path mapping the editor extension needs, with no folder-name guessing (mounts like /app carry no service name).



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/msnav/server.rb', line 41

def scope
  return nil unless @service_root
  base = @service_name ||
         File.basename(File.expand_path(@service_root))
  @store.services.each do |name, dirname, canonical_root|
    next unless dirname == base
    return { "service" => name, "dirname" => dirname,
             "service_root" => @service_root.to_s,
             "root" => canonical_root }
  end
  { "service" => nil, "dirname" => base,
    "service_root" => @service_root.to_s, "root" => nil }
end