Module: TaskJuggler::ProcessIntercom
Instance Method Summary
collapse
#critical, #debug, #error, #fatal, #info, #warning
Instance Method Details
#checkKey(authKey, command) ⇒ Object
129
130
131
132
133
134
135
136
137
138
139
|
# File 'lib/taskjuggler/daemon/ProcessIntercom.rb', line 129
def checkKey(authKey, command)
if authKey == @authKey
debug('', "Accepted authentication key for command '#{command}'")
else
warning('auth_key_rejected',
"Rejected wrong authentication key #{authKey}" +
"for command '#{command}'")
return false
end
true
end
|
#connect(stdout, stderr, stdin, silent) ⇒ Object
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
# File 'lib/taskjuggler/daemon/ProcessIntercom.rb', line 94
def connect(stdout, stderr, stdin, silent)
@clientConnection.lock
debug('', 'Rerouting ProjectServer standard IO to client')
@stdout = $stdout
@stderr = $stderr
@stdin = $stdin
$stdout = stdout if stdout
$stderr = stderr if stdout
$stdin = stdin if stdin
Log.silent = silent
Term::ANSIColor.coloring = !silent
debug('', 'IO is now routed to the client')
true
end
|
#disconnect ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/taskjuggler/daemon/ProcessIntercom.rb', line 113
def disconnect
debug('', 'Restoring IO')
Log.silent = true
$stdout = @stdout if @stdout
$stderr = @stderr if @stderr
$stdin = @stdin if @stdin
debug('', 'Standard IO has been restored')
@clientConnection.unlock
true
end
|
#generateAuthKey ⇒ Object
125
126
127
|
# File 'lib/taskjuggler/daemon/ProcessIntercom.rb', line 125
def generateAuthKey
rand(1000000000).to_s
end
|
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/taskjuggler/daemon/ProcessIntercom.rb', line 72
def initIntercom
@authKey = generateAuthKey
@terminate = false
@clientConnection = Mutex.new
@timeLock = Monitor.new
@timerStart = nil
end
|
#restartTimer ⇒ Object
This function must be called after each client interaction to restart the client connection timer.
143
144
145
146
147
148
|
# File 'lib/taskjuggler/daemon/ProcessIntercom.rb', line 143
def restartTimer
@timeLock.synchronize do
debug('', 'Reseting client connection timer')
@timerStart = Time.new
end
end
|
#startTerminator ⇒ Object
This method starts a new thread and waits for the @terminate variable to be true. If that happens, it waits for the @clientConnection lock or forces an exit after the timeout has been reached. It shuts down the DRb server.
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
|
# File 'lib/taskjuggler/daemon/ProcessIntercom.rb', line 164
def startTerminator
Thread.new do
loop do
if @terminate
restartTimer
while @clientConnection.locked? && !timerExpired? do
sleep 1
end
if timerExpired?
warning('drb_timeout_shutdown',
'Shutting down DRb server due to timeout')
else
debug('', 'Shutting down the DRb server')
end
DRb.stop_service
break
else
sleep 1
end
end
end
end
|
#terminate ⇒ Object
89
90
91
92
|
# File 'lib/taskjuggler/daemon/ProcessIntercom.rb', line 89
def terminate
debug('', 'Terminating on external request')
@terminate = true
end
|
#timerExpired? ⇒ Boolean
Check if the client interaction timer has already expired.
151
152
153
154
155
156
157
158
|
# File 'lib/taskjuggler/daemon/ProcessIntercom.rb', line 151
def timerExpired?
res = nil
@timeLock.synchronize do
res = (Time.new > @timerStart + 2 * 60)
end
res
end
|