示例#1
0
    def __init__(
        self,local_endpoint,endpoint_making_call,
        event_uuid,priority,func_name,result_queue,*args):
        '''
        @param {_Endpoint object} local_endpoint --- The endpoint
        which was requested to backout.  (Ie, the endpoint on which
        this action will take place.)

        For other @params, @see, _EndpointServiceThread._endpointCall.
        '''        
        self.local_endpoint = local_endpoint
        self.endpoint_making_call = endpoint_making_call
        self.event_uuid = event_uuid
        self.priority = priority
        self.func_name = func_name
        self.result_queue = result_queue
        self.args = args

        if not hasattr(
            self.local_endpoint,
            util.endpoint_call_func_name(self.func_name)):
            
            self.to_exec = None
            self.result_queue.put(
                waldoCallResults._NoMethodEndpointCallError(
                    func_name))

        else:
            self.to_exec = getattr(
                self.local_endpoint,
                util.endpoint_call_func_name(self.func_name))
    def __init__(self):
        DummyEndpoint.__init__(self)

        # when dispatching to partner, we request the function name as
        # it would appear in the Waldo source file.  However, the
        # compiler mangles it into another name.  The call below
        # ensures that that the mangled name exists.
        setattr(
            self,
            util.endpoint_call_func_name('endpoint_func'),
            self.endpoint_func)
        setattr(
            self,
            util.endpoint_call_func_name('endpoint_middle_func'),
            self.endpoint_middle_func)
    def __init__(self,*args):
        test_util.DummyEndpoint.__init__(self,*args)

        # adding data for a
        self.alpha_name = 'alpha'
        self._global_var_store.add_var(
            self.alpha_name,
            wVariables.WaldoNumVariable(
                self.alpha_name,self._host_uuid,
                False,1))

        setattr(
            self,
            util.endpoint_call_func_name('update_alpha'),
            self.update_alpha)
        setattr(
            self,
            util.endpoint_call_func_name('update_alpha_and_send_message'),
            self.update_alpha_and_send_message)
    def __init__(self,*args):
        test_util.DummyEndpoint.__init__(self,*args)

        # adding data for b
        self.beta_name = 'beta'
        self._global_var_store.add_var(
            self.beta_name,
            wVariables.WaldoNumVariable(
                self.beta_name,self._host_uuid,
                False,1))
        setattr(
            self,
            util.endpoint_call_func_name('update_beta'),
            self.update_beta)
        setattr(
            self,
            util.partner_endpoint_msg_call_func_name('update_beta_when_receive_message'),
            self.update_beta_when_receive_message)
示例#5
0
def emit_public_method_interface(
    public_method_node,endpoint_name,ast_root,fdep_dict,emit_ctx):
    '''
    @param {AstNode} public_method_node --- An AstNode with label
    AST_PUBLIC_FUNCTION
    '''
    method_name_node = public_method_node.children[0]
    method_name = method_name_node.value

    method_arg_names = get_method_arg_names(public_method_node)
    # turns the array of argnames above into a single string of csv
    # arg names
    comma_sep_arg_names = reduce (
        lambda x, y : x + ',' + y,
        method_arg_names,'')

    public_header = '''
def %s(self%s, **kwargs):
''' % (method_name, comma_sep_arg_names)

    # wait until ready initialization for node has completed before
    # continuing
    public_body = '''
# ensure that both sides have completed their onCreate calls
# before continuing
self._block_ready()
'''
    
    #### Deep copy non-external args
    # non_ext_arg_names is an array of strings
    non_ext_arg_names = get_non_external_arg_names_from_func_node(
        public_method_node)
                
    # do not need to copy arguments in: each function call does so on
    # its own.

    # Each element in this list is an index for a return parameter
    # that should be de-waldo-ified before returning.  We pass this
    # argument to the internal function that the internal function
    # knows which returns need to be de-waldo-ified before being
    # returned and which do not.
    list_return_external_positions = (
        get_external_return_positions_from_func_node(public_method_node))

    #### create a root event + ctx for event, call internal, and reurn
    internal_method_name = lib_util.endpoint_call_func_name(method_name)
    public_body += '''
_root_retrier = None
while True:  # FIXME: currently using infinite retry
    _root_event = _root_retrier
    if _root_event is None:
        _root_event = self._act_event_map.create_root_event()

    _ctx = %s(
        self._global_var_store,
        # not using sequence local store
        %s(self._host_uuid))

    _retry_cb = kwargs.get('retry_cb',None)

    # call internal function... note True as last param tells internal
    # version of function that it needs to de-waldo-ify all return
    # arguments (while inside transaction) so that this method may
    # return them....if it were false, might just get back refrences
    # to Waldo variables, and de-waldo-ifying them outside of the
    # transaction might return over-written/inconsistent values.
    try:
        _to_return = self.%s(_root_event,_ctx %s,%s)
    except Exception as _ex:
        _root_event.put_exception(_ex)

    # try committing root event

    _root_event.begin_first_phase_commit()
    _commit_resp = _root_event.event_parent.event_complete_queue.get()
    if (isinstance(_commit_resp,%s) or
        isinstance(_commit_resp,%s)):
        # means it isn't a backout message: we're done
        return _to_return
    elif isinstance(_commit_resp,%s):
        # backout got called: that means that we must remove the retry
        # event that we generated when backing out from active event map
        self._act_event_map.remove_event(_root_event.retry_event)

        raise %s()

    # event was backed out.  we have a retry event
    _root_retrier = _root_event.retry_event

    if _retry_cb is not None:
        if not _retry_cb(self):
            # user canceled event in retry callback.  unschedule retry
            # event.
            self._act_event_map.remove_event(_root_retrier.uuid,False)
            raise %s()

''' % (emit_utils.library_transform('ExecutingEventContext'),
       emit_utils.library_transform('VariableStore'),
       internal_method_name,
       comma_sep_arg_names,
       str(list_return_external_positions),
       emit_utils.library_transform('CompleteRootCallResult'),
       emit_utils.library_transform('NetworkFailureCallResult'),
       emit_utils.library_transform('StopRootCallResult'),
       emit_utils.library_transform('StoppedException'),
       emit_utils.library_transform('RetryCanceledException')
       )

    return public_header + emit_utils.indent_str(public_body)
示例#6
0
def emit_public_method_interface(public_method_node, endpoint_name, ast_root, fdep_dict, emit_ctx):
    """
    @param {AstNode} public_method_node --- An AstNode with label
    AST_PUBLIC_FUNCTION
    """
    method_name_node = public_method_node.children[0]
    method_name = method_name_node.value

    method_arg_names = get_method_arg_names(public_method_node)
    # turns the array of argnames above into a single string of csv
    # arg names
    comma_sep_arg_names = reduce(lambda x, y: x + "," + y, method_arg_names, "")

    public_header = """
def %s(self%s):
""" % (
        method_name,
        comma_sep_arg_names,
    )

    # wait until ready initialization for node has completed before
    # continuing
    public_body = """
# ensure that both sides have completed their onCreate calls
# before continuing
self._block_ready()
"""

    #### Deep copy non-external args
    # non_ext_arg_names is an array of strings
    non_ext_arg_names = get_non_external_arg_names_from_func_node(public_method_node)

    # do not need to copy arguments in: each function call does so on
    # its own.

    # Each element in this list is an index for a return parameter
    # that should be de-waldo-ified before returning.  We pass this
    # argument to the internal function that the internal function
    # knows which returns need to be de-waldo-ified before being
    # returned and which do not.
    list_return_external_positions = get_external_return_positions_from_func_node(public_method_node)

    #### create a root event + ctx for event, call internal, and reurn
    internal_method_name = lib_util.endpoint_call_func_name(method_name)
    public_body += """
while True:  # FIXME: currently using infinite retry 
    _root_event = self._act_event_map.create_root_event()
    _ctx = %s(
        self._global_var_store,
        # not using sequence local store
        %s(self._host_uuid))

    # call internal function... note True as last param tells internal
    # version of function that it needs to de-waldo-ify all return
    # arguments (while inside transaction) so that this method may
    # return them....if it were false, might just get back refrences
    # to Waldo variables, and de-waldo-ifying them outside of the
    # transaction might return over-written/inconsistent values.
    try:
        _to_return = self.%s(_root_event,_ctx %s,%s)
    except %s:
        pass

    # try committing root event
    _root_event.request_commit()
    _commit_resp = _root_event.event_complete_queue.get()
    if isinstance(_commit_resp,%s):
        # means it isn't a backout message: we're done
        return _to_return
    elif isinstance(_commit_resp,%s):
        raise %s()

""" % (
        emit_utils.library_transform("ExecutingEventContext"),
        emit_utils.library_transform("VariableStore"),
        internal_method_name,
        comma_sep_arg_names,
        str(list_return_external_positions),
        emit_utils.library_transform("BackoutException"),
        emit_utils.library_transform("CompleteRootCallResult"),
        emit_utils.library_transform("StopRootCallResult"),
        emit_utils.library_transform("StoppedException"),
    )

    return public_header + emit_utils.indent_str(public_body)