Class: Service
Instance Attribute Summary
Attributes inherited from Application
#cluster, #running
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Application
#appswarmBaseDir, #config, #getApp, #getAppDataPath, #getAppDataPaths, #getAppDataWritePath, #getAppDir, getAppDir, #getAppId, #getAppName, #getService, #info, #log, #monitor, protect, provides, #provides?, providing, #providingAPIs, #quit, #quit?, requirements, requires, #retrieveConfig, #shortName, #startup, #warning, #withApp, #withAppFork
Constructor Details
#initialize(cluster, options, name) ⇒ Service
Returns a new instance of Service.
39
40
41
42
43
44
|
# File 'lib/appswarm/service.rb', line 39
def initialize(cluster,options,name)
super(cluster,options)
@name=name
@cronMutex=Mutex.new
provides(name)
end
|
Class Method Details
.event(name, arity = nil) ⇒ Object
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/appswarm/service.rb', line 5
def self.event(name,arity=nil)
name=name.to_s
onName="on"+name[0..0].upcase+name[1..-1]
isName="is"+name[0..0].upcase+name[1..-1]
assert{not self.respond_to?(onName)}
@@eventArity||={}
if arity
@@eventArity[name]=arity
end
self.module_eval("
def #{onName}(&block)
assert{block_given?}
if @@eventArity[:#{name}]
assert{@@eventArity[:#{name}]==block.arity}
end
@eventReceivers||={}
@eventReceivers[:#{name}]||=[]
@eventReceivers[:#{name}] << block
end
private
def #{isName}(*args)
if @@eventArity[:#{name}]
assert{@@eventArity[:#{name}]==args.length}
end
@eventReceivers||={}
@eventReceivers[:#{name}]||=[]
@eventReceivers[:#{name}].each{|b|
b.call(*args)
}
end
")
end
|
Instance Method Details
#cron ⇒ Object
72
73
74
|
# File 'lib/appswarm/service.rb', line 72
def cron
end
|
#cronTime ⇒ Object
46
47
48
|
# File 'lib/appswarm/service.rb', line 46
def cronTime
@options[:cronTime]||10
end
|
#run ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/appswarm/service.rb', line 50
def run
@threads << Thread.new {
while not quit?
begin
runCron
rescue Object=>e
log e
log e.backtrace if e.is_a?(Exception)
end
sleep(cronTime)
end
}
end
|
#runCron ⇒ Object
66
67
68
69
70
|
# File 'lib/appswarm/service.rb', line 66
def runCron
@cronMutex.synchronize {
cron
}
end
|
#stop ⇒ Object
63
64
65
|
# File 'lib/appswarm/service.rb', line 63
def stop
super
end
|