Class Index [+]

Quicksearch

TaskJuggler::ProcessIntercom

Public Instance Methods

checkKey(authKey, command) click to toggle source
     # File lib/daemon/ProcessIntercom.rb, line 98
 98:     def checkKey(authKey, command)
 99:       if authKey == @authKey
100:         @log.debug("Accepted authentication key for command '#{command}'")
101:       else
102:         @log.warning("Rejected wrong authentication key #{authKey}" +
103:                      "for command '#{command}'")
104:         return false
105:       end
106:       true
107:     end
connect(stdout, stderr, stdin, silent) click to toggle source
    # File lib/daemon/ProcessIntercom.rb, line 64
64:     def connect(stdout, stderr, stdin, silent)
65:       # Set the client lock.
66:       @clientConnection.lock
67:       @log.debug('Rerouting ProjectServer standard IO to client')
68:       # Make sure that all output to STDOUT and STDERR is sent to the client.
69:       # Input is read from the client STDIN.  We save a copy of the old file
70:       # handles so we can restore then later again.
71:       @stdout = $stdout
72:       @stderr = $stderr
73:       @stdin = $stdin
74:       $stdout = stdout if stdout
75:       $stderr = stderr if stdout
76:       $stdin = stdin if stdin
77:       @log.debug('IO is now routed to the client')
78:       Log.silent = silent
79:       true
80:     end
disconnect() click to toggle source
    # File lib/daemon/ProcessIntercom.rb, line 82
82:     def disconnect
83:       @log.debug('Restoring IO')
84:       Log.silent = true
85:       $stdout = @stdout if @stdout
86:       $stderr = @stderr if @stderr
87:       $stdin = @stdin if @stdin
88:       @log.debug('Standard IO has been restored')
89:       # Release the client lock
90:       @clientConnection.unlock
91:       true
92:     end
generateAuthKey() click to toggle source
    # File lib/daemon/ProcessIntercom.rb, line 94
94:     def generateAuthKey
95:       rand(1000000000).to_s
96:     end
initIntercom() click to toggle source
    # File lib/daemon/ProcessIntercom.rb, line 41
41:     def initIntercom
42:       # This is the authentication key that clients will need to provide to
43:       # execute DRb methods.
44:       @authKey = generateAuthKey
45: 
46:       @log = LogFile.instance
47:       # This flag will be set to true by DRb method calls to terminate the
48:       # process.
49:       @terminate = false
50: 
51:       # This mutex is locked while a client is connected.
52:       @clientConnection = Mutex.new
53:       # This lock protects the @timerStart
54:       @timeLock = Monitor.new
55:       # The time stamp of the last client interaction.
56:       @timerStart = nil
57:     end
restartTimer() click to toggle source

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

     # File lib/daemon/ProcessIntercom.rb, line 111
111:     def restartTimer
112:       @timeLock.synchronize do
113:         @log.debug('Reseting client connection timer')
114:         @timerStart = Time.new
115:       end
116:     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/daemon/ProcessIntercom.rb, line 131
131:     def startTerminator
132:       Thread.new do
133:         loop do
134:           if @terminate
135:             # We wait for the client to propery disconnect. In case this does
136:             # not happen, we'll wait for the timeout and exit anyway.
137:             restartTimer
138:             while @clientConnection.locked? && !timerExpired? do
139:               sleep 1
140:             end
141:             if timerExpired?
142:               @log.warning('Shutting down DRb server due to timeout')
143:             else
144:               @log.debug('Shutting down DRb server')
145:             end
146:             DRb.stop_service
147:             break
148:           else
149:             sleep 1
150:           end
151:         end
152:       end
153:     end
terminate() click to toggle source
    # File lib/daemon/ProcessIntercom.rb, line 59
59:     def terminate
60:       @log.debug('Terminating on external request')
61:       @terminate = true
62:     end
timerExpired?() click to toggle source

Check if the client interaction timer has already expired.

     # File lib/daemon/ProcessIntercom.rb, line 119
119:     def timerExpired?
120:       res = nil
121:       @timeLock.synchronize do
122:         res = (Time.new > @timerStart + 2 * 60 * 60)
123:       end
124:       res
125:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.