Class: Spring::Watcher::Polling
Instance Attribute Summary collapse
Attributes inherited from Abstract
#directories, #files, #latency, #root
Instance Method Summary
collapse
Methods inherited from Abstract
#debug, #mark_stale, #on_debug, #on_stale, #restart, #stale?, #synchronize
Constructor Details
#initialize(root, latency) ⇒ Polling
Returns a new instance of Polling.
8
9
10
11
12
|
# File 'lib/spring/watcher/polling.rb', line 8
def initialize(root, latency)
super
@mtime = 0
@poller = nil
end
|
Instance Attribute Details
#mtime ⇒ Object
Returns the value of attribute mtime.
6
7
8
|
# File 'lib/spring/watcher/polling.rb', line 6
def mtime
@mtime
end
|
Instance Method Details
#add ⇒ Object
24
25
26
27
|
# File 'lib/spring/watcher/polling.rb', line 24
def add(*)
check_stale if @poller
super
end
|
#check_stale ⇒ Object
14
15
16
17
18
19
20
21
22
|
# File 'lib/spring/watcher/polling.rb', line 14
def check_stale
@mutex.synchronize do
computed = compute_mtime
if mtime < computed
debug { "check_stale: mtime=#{mtime.inspect} < computed=#{computed.inspect}" }
mark_stale
end
end
end
|
#running? ⇒ Boolean
60
61
62
|
# File 'lib/spring/watcher/polling.rb', line 60
def running?
@poller && @poller.alive?
end
|
#start ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/spring/watcher/polling.rb', line 29
def start
debug { "start: poller=#{@poller.inspect}" }
unless @poller
@poller = Thread.new {
Thread.current.abort_on_exception = true
begin
until stale?
Kernel.sleep latency
check_stale
end
rescue Exception => e
debug do
"poller: aborted: #{e.class}: #{e}\n #{e.backtrace.join("\n ")}"
end
raise
ensure
@poller = nil
end
}
end
end
|
#stop ⇒ Object
52
53
54
55
56
57
58
|
# File 'lib/spring/watcher/polling.rb', line 52
def stop
debug { "stopping poller: #{@poller.inspect}" }
if @poller
@poller.kill
@poller = nil
end
end
|
#subjects_changed ⇒ Object
64
65
66
67
68
|
# File 'lib/spring/watcher/polling.rb', line 64
def subjects_changed
computed = compute_mtime
debug { "subjects_changed: mtime #{@mtime} -> #{computed}" }
@mtime = computed
end
|