def start
      @stopped = false
      return if @started
      @started = true
      @worker = Thread.new do
        QuartzTorrent.initThread("trackerclient")
        @logger.info "Worker thread starting"
        @event = :started
        trackerInterval = nil
        while ! @stopped
          begin
            response = nil

            driver = currentDriver

            if driver
              begin 
                @logger.debug "Sending request to tracker #{currentAnnounceUrl}"
                response = driver.request(@event)
                @event = nil
                trackerInterval = response.interval
              rescue
                addError $!
                @logger.info "Request failed due to exception: #{$!}"
                @logger.debug $!.backtrace.join("\n")
                changeToNextTracker
                next

                @alarms.raise Alarm.new(:tracker, "Tracker request failed: #{$!}") if @alarms
              end
            end

            if response && response.successful?
              @alarms.clear :tracker if @alarms
              # Replace the list of peers
              peersHash = {}
              @logger.info "Response contained #{response.peers.length} peers"

              if response.peers.length == 0
                @alarms.raise Alarm.new(:tracker, "Response from tracker contained no peers") if @alarms
              end

              response.peers.each do |p|
                peersHash[p] = 1
              end
              @peersMutex.synchronize do
                @peers = peersHash
              end
              if @peersChangedListeners.size > 0
                @peersChangedListeners.each{ |l| l.call }
              end
            else
              @logger.info "Response was unsuccessful from tracker: #{response.error}"
              addError response.error if response
              @alarms.raise Alarm.new(:tracker, "Unsuccessful response from tracker: #{response.error}") if @alarms && response
              changeToNextTracker
              next
            end

            # If we have no interval from the tracker yet, and the last request didn't error out leaving us with no peers,
            # then set the interval to 20 seconds.
            interval = trackerInterval
            interval = 20 if ! interval
            interval = 2 if response && !response.successful? && @peers.length == 0

            @logger.debug "Sleeping for #{interval} seconds"
            @sleeper.sleep interval 

          rescue
            @logger.warn "Unhandled exception in worker thread: #{$!}"
            @logger.warn $!.backtrace.join("\n")
            @sleeper.sleep 1
          end
        end
        @logger.info "Worker thread shutting down"
        @logger.info "Sending final update to tracker"
        begin
          driver = currentDriver
          driver.request(:stopped) if driver
        rescue
          addError $!
          @logger.debug "Request failed due to exception: #{$!}"
          @logger.debug $!.backtrace.join("\n")
        end
        @started = false
      end
    end
def start
      @stopped = false
      return if @started
      @started = true
      @worker = Thread.new do
        QuartzTorrent.initThread("trackerclient")
        @logger.info "Worker thread starting"
        @event = :started
        trackerInterval = nil
        while ! @stopped
          begin
            response = nil

            driver = currentDriver

            if driver
              begin 
                @logger.debug "Sending request to tracker #{currentAnnounceUrl}"
                response = driver.request(@event)
                @event = nil
                trackerInterval = response.interval
              rescue
                addError $!
                @logger.info "Request failed due to exception: #{$!}"
                @logger.debug $!.backtrace.join("\n")
                changeToNextTracker
                next

                @alarms.raise Alarm.new(:tracker, "Tracker request failed: #{$!}") if @alarms
              end
            end

            if response && response.successful?
              @alarms.clear :tracker if @alarms
              # Replace the list of peers
              peersHash = {}
              @logger.info "Response contained #{response.peers.length} peers"

              if response.peers.length == 0
                @alarms.raise Alarm.new(:tracker, "Response from tracker contained no peers") if @alarms
              end

              response.peers.each do |p|
                peersHash[p] = 1
              end
              @peersMutex.synchronize do
                @peers = peersHash
              end
              if @peersChangedListeners.size > 0
                @peersChangedListeners.each{ |l| l.call }
              end
            else
              @logger.info "Response was unsuccessful from tracker: #{response.error}"
              addError response.error if response
              @alarms.raise Alarm.new(:tracker, "Unsuccessful response from tracker: #{response.error}") if @alarms && response
              changeToNextTracker
              next
            end

            # If we have no interval from the tracker yet, and the last request didn't error out leaving us with no peers,
            # then set the interval to 20 seconds.
            interval = trackerInterval
            interval = 20 if ! interval
            interval = 2 if response && !response.successful? && @peers.length == 0

            @logger.debug "Sleeping for #{interval} seconds"
            @sleeper.sleep interval 

          rescue
            @logger.warn "Unhandled exception in worker thread: #{$!}"
            @logger.warn $!.backtrace.join("\n")
            @sleeper.sleep 1
          end
        end
        @logger.info "Worker thread shutting down"
        @logger.info "Sending final update to tracker"
        begin
          driver = currentDriver
          driver.request(:stopped) if driver
        rescue
          addError $!
          @logger.debug "Request failed due to exception: #{$!}"
          @logger.debug $!.backtrace.join("\n")
        end
        @started = false
      end
    end
Start the worker thread