コード例 #1
0
    def __init__(self,conn_obj):
        super(PartnerEndpoint,self).__init__(conn_obj)

        setattr(
            self,
            util.partner_endpoint_msg_call_func_name('test_partner_write'),
            self.test_partner_write)
コード例 #2
0
    def __init__(self,endpoint_a,*args):
        test_util.DummyEndpoint.__init__(self,*args)

        self.endpoint_a = endpoint_a
        
        setattr(
            self,
            util.partner_endpoint_msg_call_func_name('receive_message_for_a'),
            self.receive_message_for_a)
    def __init__(self,conn_obj):
        test_util.DummyEndpoint.__init__(self,conn_obj)

        # 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.partner_endpoint_msg_call_func_name('sequence_block'),
            self.sequence_block)
コード例 #4
0
ファイル: emit_endpoints.py プロジェクト: bmistree/Waldo
def emit_message_receive(
    message_receive_node,next_to_call_node,endpoint_name,ast_root,
    fdep_dict,emit_ctx):
    '''
    @param {AstNode or None} next_to_call_node --- If AstNode, then
    has label AST_MESSAGE_RECEIVE_FUNCTION.  If None, means that this
    is the last message receive node in sequence and should tell other
    side to issue a block call with target None.
    '''

    msg_recv_node_name_node = message_receive_node.children[1]
    msg_recv_name = msg_recv_node_name_node.value
    
    emit_ctx.in_message_receive = True
    emit_ctx.message_seq_return_txt = '\nreturn '

    msg_receive_txt = emit_private_method_interface(
        message_receive_node,endpoint_name,ast_root,fdep_dict,emit_ctx,
        lib_util.partner_endpoint_msg_call_func_name)
    msg_receive_txt += '\n'
    
    emit_ctx.in_message_receive = False
    emit_ctx.message_seq_return_txt = ''

    ## Ends by telling the opposite side what to do next
    next_to_call_txt = 'None'
    if next_to_call_node != None:
        # the name of the next sequence block to execute, as it
        # appears in the source Waldo text, ie, before mangling.
        next_sequence_block_src_name = next_to_call_node.children[1].value

        # note that we must wait on receiving a response from the other
        # side before we can continue on, or the original sender may
        # return too early. We should not wait on the last message that we
        # send however, because, we do not expect any response to it.
        # (Ie, if next_to_call_txt == 'None', then do not wait.)
        
        next_to_call_txt = '"' + lib_util.partner_endpoint_msg_call_func_name(
            next_sequence_block_src_name) + '"'

    next_sequence_txt = '''

_context.hide_partner_call(
    self,_active_event,%s,False)
''' % (next_to_call_txt)

    msg_receive_txt += emit_utils.indent_str(next_sequence_txt)
    return msg_receive_txt
コード例 #5
0
    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)
コード例 #6
0
    def handle_first_sequence_msg_from_partner(
        self,msg,name_of_block_to_exec_next):
        '''        
        ASSUMES ALREADY WITHIN LOCK

        @param {PartnerMessageRequestSequenceBlock.proto} msg ---

        @param {string} name_of_block_to_exec_next --- the name of the
        sequence block to execute next.

        @returns {Executing event}
        
        means that the other side has generated a first message create
        a new context to execute that message and do so in a new
        thread.
        '''
        ### FIGURE OUT WHAT TO EXECUTE NEXT

        #### DEBUG
        if name_of_block_to_exec_next == None:
            util.logger_assert(
                'Error in _ActiveEvent.  Should not receive the ' +
                'beginning of a sequence message without some ' +
                'instruction for what to do next.')
        #### END DEBUG

        block_to_exec_internal_name = util.partner_endpoint_msg_call_func_name(
            name_of_block_to_exec_next)

        #### MAYBE DEBUG
        # ("maybe" because we also may want to throw a Waldo error
        # for this instead of just asserting out.)
        if not hasattr(
            self.event_parent.local_endpoint,block_to_exec_internal_name):
            util.logger_assert(
                'Error in _ActiveEvent.  Received a request to ' +
                'perform an unknown sequence step.')
        #### END MAYBE DEBUG

        to_exec = getattr(self.event_parent.local_endpoint,block_to_exec_internal_name)

        ### SET UP CONTEXT FOR EXECUTING
        seq_local_var_store = waldoVariableStore._VariableStore(
            self.event_parent.local_endpoint._host_uuid)

        # FIXME: eventually, want to remove pickle-ing here
        seq_local_var_store.incorporate_deltas(
            self,msg.sequence_local_var_store_deltas)

        
        evt_ctx = _ExecutingEventContext(
            # already incorporated deltas for global_var_store
            # above.
            self.event_parent.local_endpoint._global_var_store,
            seq_local_var_store)

        evt_ctx.set_to_reply_with(msg.reply_with_uuid.data)

        # used to actually start execution of context thread at end
        # of loop.  must start event outside of locks.  That way,
        # if the exec event leads to and endpoint call, etc., we
        # don't block waiting on its return.
        exec_event = _ExecutingEvent(
            to_exec,self,evt_ctx,
            None # using None here means that we do not need to
                 # bother with waiting for modified peered-s to
                 # update.
            )

        return exec_event
コード例 #7
0
ファイル: emit_endpoints.py プロジェクト: harrison8989/Waldo
def emit_message_receive(message_receive_node, next_to_call_node, endpoint_name, ast_root, fdep_dict, emit_ctx):
    """
    @param {AstNode or None} next_to_call_node --- If AstNode, then
    has label AST_MESSAGE_RECEIVE_FUNCTION.  If None, means that this
    is the last message receive node in sequence and should tell other
    side to issue a block call with target None.
    """

    msg_recv_node_name_node = message_receive_node.children[1]
    msg_recv_name = msg_recv_node_name_node.value

    emit_ctx.in_message_receive = True
    emit_ctx.message_seq_return_txt = "\nreturn "

    msg_receive_txt = emit_private_method_interface(
        message_receive_node, endpoint_name, ast_root, fdep_dict, emit_ctx, lib_util.partner_endpoint_msg_call_func_name
    )
    msg_receive_txt += "\n"

    emit_ctx.in_message_receive = False
    emit_ctx.message_seq_return_txt = ""

    ## Ends by telling the opposite side what to do next
    next_to_call_txt = "None"
    if next_to_call_node != None:
        # the name of the next sequence block to execute, as it
        # appears in the source Waldo text, ie, before mangling.
        next_sequence_block_src_name = next_to_call_node.children[1].value

        next_to_call_txt = '"' + lib_util.partner_endpoint_msg_call_func_name(next_sequence_block_src_name) + '"'

    # note that we must wait on receiving a response from the other
    # side before we can continue on, or the original sender may
    # return too early. We should not wait on the last message that we
    # send however, because, we do not expect any response to it.
    # (Ie, if next_to_call_txt == 'None', then do not wait.)
    next_sequence_txt = """

_threadsafe_queue = %s.Queue()
_active_event.issue_partner_sequence_block_call(
    _context,%s,_threadsafe_queue,False)
# must wait on the result of the call before returning

if %s != None:
    # means that we have another sequence item to execute next

    _queue_elem = _threadsafe_queue.get()


""" % (
        emit_utils.library_transform("Queue"),
        next_to_call_txt,
        next_to_call_txt,
    )

    next_sequence_txt += """

    if isinstance(_queue_elem,%s):
        # back everything out: 
        raise %s()

    _context.set_to_reply_with(_queue_elem.reply_with_msg_field)

    # apply changes to sequence variables.  Note: that
    # the system has already applied deltas for global data.
    _context.sequence_local_store.incorporate_deltas(
        _active_event,_queue_elem.sequence_local_var_store_deltas)

    # send more messages
    _to_exec_next = _queue_elem.to_exec_next_name_msg_field
    if _to_exec_next != None:
        # means that we do not have any additional functions to exec
        _to_exec = getattr(self,_to_exec_next)
        _to_exec(_active_event,_context)

""" % (
        emit_utils.library_transform("BackoutBeforeReceiveMessageResult"),
        emit_utils.library_transform("BackoutException"),
    )

    msg_receive_txt += emit_utils.indent_str(next_sequence_txt)
    return msg_receive_txt