'Completes the request by calling the state method.
NOTE - we expect the state method to be suitably decorated with a
StateHandler (otherwise this will raise because the prototypes
are different)
Args:
method: The name of the state method to call.
request: A RequestState protobuf.
responses: A list of GrrMessages responding to the request.
event: A threading.Event() instance to signal completion of this request.
direct_response: A flow.Responses() object can be provided to avoid
creation of one.'

def RunStateMethod(self, method, request=None, responses=None, event=None, direct_response=None):

    client_id = None
    try:
        self.context.current_state = method
        if (request and responses):
            client_id = (request.client_id or self.runner_args.client_id)
            logging.debug('%s    Running    %s    with    %d    responses    from    %s', self.session_id, method, len(responses), client_id)
        else:
            logging.debug('%s    Running    state    method    %s', self.session_id, method)
        self.flow_obj.HeartBeat()
        try:
            method = getattr(self.flow_obj, method)
        except AttributeError:
            raise FlowRunnerError(('Flow    %s    has    no    state    method    %s' % (self.flow_obj.__class__.__name__, method)))
        method(direct_response=direct_response, request=request, responses=responses)
        if self.sent_replies:
            self.ProcessRepliesWithOutputPlugins(self.sent_replies)
            self.sent_replies = []
    except Exception as e:
        stats.STATS.IncrementCounter('grr_flow_errors')
        stats.STATS.IncrementCounter('flow_errors', fields=[self.flow_obj.Name()])
        logging.exception('Flow    %s    raised    %s.', self.session_id, e)
        self.Error(traceback.format_exc(), client_id=client_id)
    finally:
        if event:
            event.set()
