Class Index [+]

Quicksearch

TaskJuggler::ProcessIntercom

Public Instance Methods

checkKey(authKey, command) click to toggle source
     # File lib/taskjuggler/daemon/ProcessIntercom.rb, line 114
114:     def checkKey(authKey, command)
115:       if authKey == @authKey
116:         @log.debug("Accepted authentication key for command '#{command}'")
117:       else
118:         @log.warning("Rejected wrong authentication key #{authKey}" +
119:                      "for command '#{command}'")
120:         return false
121:       end
122:       true
123:     end
connect(stdout, stderr, stdin, silent) click to toggle source
    # File lib/taskjuggler/daemon/ProcessIntercom.rb, line 80
80:     def connect(stdout, stderr, stdin, silent)
81:       # Set the client lock.
82:       @clientConnection.lock
83:       @log.debug('Rerouting ProjectServer standard IO to client')
84:       # Make sure that all output to STDOUT and STDERR is sent to the client.
85:       # Input is read from the client STDIN.  We save a copy of the old file
86:       # handles so we can restore then later again.
87:       @stdout = $stdout
88:       @stderr = $stderr
89:       @stdin = $stdin
90:       $stdout = stdout if stdout
91:       $stderr = stderr if stdout
92:       $stdin = stdin if stdin
93:       @log.debug('IO is now routed to the client')
94:       Log.silent = silent
95:       true
96:     end
disconnect() click to toggle source
     # File lib/taskjuggler/daemon/ProcessIntercom.rb, line 98
 98:     def disconnect
 99:       @log.debug('Restoring IO')
100:       Log.silent = true
101:       $stdout = @stdout if @stdout
102:       $stderr = @stderr if @stderr
103:       $stdin = @stdin if @stdin
104:       @log.debug('Standard IO has been restored')
105:       # Release the client lock
106:       @clientConnection.unlock
107:       true
108:     end
generateAuthKey() click to toggle source
     # File lib/taskjuggler/daemon/ProcessIntercom.rb, line 110
110:     def generateAuthKey
111:       rand(1000000000).to_s
112:     end
initIntercom() click to toggle source
    # File lib/taskjuggler/daemon/ProcessIntercom.rb, line 57
57:     def initIntercom
58:       # This is the authentication key that clients will need to provide to
59:       # execute DRb methods.
60:       @authKey = generateAuthKey
61: 
62:       @log = LogFile.instance
63:       # This flag will be set to true by DRb method calls to terminate the
64:       # process.
65:       @terminate = false
66: 
67:       # This mutex is locked while a client is connected.
68:       @clientConnection = Mutex.new
69:       # This lock protects the @timerStart
70:       @timeLock = Monitor.new
71:       # The time stamp of the last client interaction.
72:       @timerStart = nil
73:     end
restartTimer() click to toggle source

This function must be called after each client interaction to restart the client connection timer.

     # File lib/taskjuggler/daemon/ProcessIntercom.rb, line 127
127:     def restartTimer
128:       @timeLock.synchronize do
129:         @log.debug('Reseting client connection timer')
130:         @timerStart = Time.new
131:       end
132:     end
startTerminator() click to toggle source

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.

     # File lib/taskjuggler/daemon/ProcessIntercom.rb, line 148
148:     def startTerminator
149:       Thread.new do
150:         loop do
151:           if @terminate
152:             # We wait for the client to propery disconnect. In case this does
153:             # not happen, we'll wait for the timeout and exit anyway.
154:             restartTimer
155:             while @clientConnection.locked? && !timerExpired? do
156:               sleep 1
157:             end
158:             if timerExpired?
159:               @log.warning('Shutting down DRb server due to timeout')
160:             else
161:               @log.debug('Shutting down DRb server')
162:             end
163:             DRb.stop_service
164:             break
165:           else
166:             sleep 1
167:           end
168:         end
169:       end
170:     end
terminate() click to toggle source
    # File lib/taskjuggler/daemon/ProcessIntercom.rb, line 75
75:     def terminate
76:       @log.debug('Terminating on external request')
77:       @terminate = true
78:     end
timerExpired?() click to toggle source

Check if the client interaction timer has already expired.

     # File lib/taskjuggler/daemon/ProcessIntercom.rb, line 135
135:     def timerExpired?
136:       res = nil
137:       @timeLock.synchronize do
138:         # We should see client interaction every 2 minutes.
139:         res = (Time.new > @timerStart + 2 * 60)
140:       end
141:       res
142:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.