class TaskJuggler::ProjectBrokerIface

This class is the DRb interface for ProjectBroker. We only want to expose these methods for remote access.

Public Class Methods

new(broker) click to toggle source
# File lib/taskjuggler/daemon/ProjectBroker.rb, line 488
def initialize(broker)
  @broker = broker
end

Public Instance Methods

apiVersion(authKey, version) click to toggle source

Check the authentication key and the client/server version match. The following return values can be generated: 0 : authKey does not match 1 : client and server versions match -1 : client and server versions don’t match

# File lib/taskjuggler/daemon/ProjectBroker.rb, line 497
def apiVersion(authKey, version)
  return 0 unless @broker.checkKey(authKey, 'apiVersion')

  version == 1 ? 1 : -1
end
command(authKey, cmd, args) click to toggle source
# File lib/taskjuggler/daemon/ProjectBroker.rb, line 527
def command(authKey, cmd, args)
  return false unless @broker.checkKey(authKey, cmd)

  trap do
    case cmd
    when :status
      @broker.status
    when :stop
      @broker.stop
    when :addProject
      # To pass the DRbObject as separate arguments we need to convert it
      # into a real Array again.
      @broker.addProject(*Array.new(args))
    when :removeProject
      @broker.removeProject(args)
    when :getProject
      @broker.getProject(args)
    when :update
      @broker.update
    else
      fatal('unknown_command', 'Unknown command #{cmd} called')
    end
  end
end
getProject(authKey, id) click to toggle source
# File lib/taskjuggler/daemon/ProjectBroker.rb, line 558
def getProject(authKey, id)
  return false unless @broker.checkKey(authKey, 'getProject')

  debug('', "PID: #{id} Class: #{id.class}")
  trap { @broker.getProject(id) }
end
getProjectList(authKey) click to toggle source
# File lib/taskjuggler/daemon/ProjectBroker.rb, line 552
def getProjectList(authKey)
  return false unless @broker.checkKey(authKey, 'getProjectList')

  trap { @broker.getProjectList }
end
trap() { || ... } click to toggle source

This function catches all unhandled exceptions in the passed block.

# File lib/taskjuggler/daemon/ProjectBroker.rb, line 504
def trap
  begin
    yield
  rescue => e
    # TjRuntimeError exceptions are simply passed through.
    if e.is_a?(TjRuntimeError)
      raise TjRuntimeError, $!
    end

    # Any exception here is a fata error. We try hard to terminate the DRb
    # thread and then exit the program.
    begin
      fatal('pb_crash_trap', "#{e}\n#{e.backtrace.join("\n")}\n\n" +
            "#{'*' * 79}\nYou have triggered a bug in " +
            "#{AppConfig.softwareName} version #{AppConfig.version}!\n" +
            "Please see the user manual on how to get this bug fixed!\n" +
            "#{'*' * 79}\n")
    rescue RuntimeError
      @broker.stop
    end
  end
end
updateState(authKey, projectKey, id, status, modified) click to toggle source
# File lib/taskjuggler/daemon/ProjectBroker.rb, line 565
def updateState(authKey, projectKey, id, status, modified)
  return false unless @broker.checkKey(authKey, 'updateState')

  trap { @broker.updateState(projectKey, id, status, modified) }
end