Class: TaskJuggler::ProjectBrokerIface

Inherits:
Object
  • Object
show all
Includes:
MessageHandler
Defined in:
lib/taskjuggler/daemon/ProjectBroker.rb

Overview

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

Instance Method Summary collapse

Methods included from MessageHandler

#critical, #debug, #error, #fatal, #info, #warning

Constructor Details

#initialize(broker) ⇒ ProjectBrokerIface

Returns a new instance of ProjectBrokerIface.



488
489
490
# File 'lib/taskjuggler/daemon/ProjectBroker.rb', line 488

def initialize(broker)
  @broker = broker
end

Instance Method Details

#apiVersion(authKey, version) ⇒ Object

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



497
498
499
500
501
# 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) ⇒ Object



527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
# 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) ⇒ Object



558
559
560
561
562
563
# 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) ⇒ Object



552
553
554
555
556
# File 'lib/taskjuggler/daemon/ProjectBroker.rb', line 552

def getProjectList(authKey)
  return false unless @broker.checkKey(authKey, 'getProjectList')

  trap { @broker.getProjectList }
end

#trapObject

This function catches all unhandled exceptions in the passed block.



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# 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) ⇒ Object



565
566
567
568
569
# 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