def move(to_state)
      if !self.driver.in_driver_context?
        # Called from outside Driver. Send an async message to Driver.
        self.driver.message(:move, [to_state])
      else
        # Called from within Driver. Record original info.
        orig_to_state = to_state
        from_state = self.state

        # Log.
        msg = "#{self.name} move '#{from_state}' to '#{to_state}'"
        applog(self, :info, msg)

        # Cleanup from current state.
        self.driver.clear_events
        self.metrics[from_state].each { |m| m.disable }
        if to_state == :unmonitored
          self.metrics[nil].each { |m| m.disable }
        end

        # Perform action.
        self.action(to_state)

        # Enable simple mode.
        if [:start, :restart].include?(to_state) && self.metrics[to_state].empty?
          to_state = :up
        end

        # Move to new state.
        self.metrics[to_state].each { |m| m.enable }

        # If no from state, enable lifecycle metric.
        if from_state == :unmonitored
          self.metrics[nil].each { |m| m.enable }
        end

        # Set state.
        self.state = to_state

        # Broadcast to interested TriggerConditions.
        Trigger.broadcast(self, :state_change, [from_state, orig_to_state])

        # Log.
        msg = "#{self.name} moved '#{from_state}' to '#{to_state}'"
        applog(self, :info, msg)
      end

      self
    end
def move(to_state)
      if !self.driver.in_driver_context?
        # Called from outside Driver. Send an async message to Driver.
        self.driver.message(:move, [to_state])
      else
        # Called from within Driver. Record original info.
        orig_to_state = to_state
        from_state = self.state

        # Log.
        msg = "#{self.name} move '#{from_state}' to '#{to_state}'"
        applog(self, :info, msg)

        # Cleanup from current state.
        self.driver.clear_events
        self.metrics[from_state].each { |m| m.disable }
        if to_state == :unmonitored
          self.metrics[nil].each { |m| m.disable }
        end

        # Perform action.
        self.action(to_state)

        # Enable simple mode.
        if [:start, :restart].include?(to_state) && self.metrics[to_state].empty?
          to_state = :up
        end

        # Move to new state.
        self.metrics[to_state].each { |m| m.enable }

        # If no from state, enable lifecycle metric.
        if from_state == :unmonitored
          self.metrics[nil].each { |m| m.enable }
        end

        # Set state.
        self.state = to_state

        # Broadcast to interested TriggerConditions.
        Trigger.broadcast(self, :state_change, [from_state, orig_to_state])

        # Log.
        msg = "#{self.name} moved '#{from_state}' to '#{to_state}'"
        applog(self, :info, msg)
      end

      self
    end
Move to the given state.

 to_state - The Symbol representing the state to move to.

 Returns this Task.