예제 #1
0
 def __init__(self, participant):
     self.participant = participant
     self.conversation_monitor = ConversationMonitor()
     self.message_adapter = AMQPConversationMessageAdapter()
     self.invitations = {}
     self.gateway = ExchangeGateway()
     self.monitor_enabled = True
예제 #2
0
class ExternalMonitor(object):
    DEFAULT_MONITOR_PORT = 5673
    messageAdapter = AMQPConversationMessageAdapter()
    protocolProvider = DefaultProtocolProvider()

    def __init__(self, host, port):
        self.monitor = Monitor(self.protocolProvider)
        self.connection = pika.BlockingConnection(
            pika.ConnectionParameters(host='localhost'))
        self.channel = self.connection.channel()

    def add_conversation(self, convID, protocolID, initiatre):
        self.monitor.on_create_conversation(convID, protocolID)
        roles = self.protocolProvider.get_roles_by_protocolID(protocolID)

        for role in roles:
            # 3.1 create queues with queue_name = role, this are queue for the invitations
            invitationQueueName = Invitation.invitation_queue_name(
                convID, role)
            self.channel.queue_declare(queue=invitationQueueName)
            self.channel.basic_consume(self.on_receive_invitation,
                                       queue=invitationQueueName,
                                       no_ack=True)
            self.channel.start_consuming()

    def on_receive_invitation(self, msg):
        invitation = self.messageAdapter(msg)
        self.monitor.on_incoming_invitations(invitation)
        self.monitor.on_accept_invitation(invitation)
        # Start listening on this participant queue
        #invitationQueueName = invitation.getQueueName()
        self.channel.basic_consume(self.on_receive_msg,
                                   queue=invitation.getQueueName)

    def on_receive_msg(self, msg):
        convMsg = self.messageAdapter.to_conversation_msg(msg)
        try:
            if (convMsg.LocalType == LocalType.RESV):
                self.monitor.check_incoming_msg(convMsg)
            else:
                self.monitor.check_outgoing_msg(convMsg)
            self.forwardMessage(msg, )
        except Exception:
            self.process_wrong_message(convMsg)

    def forward_message(self, exchangeName, routingKey, msg):
        self.channel.basic_publish(exchange=exchangeName,
                                   routing_key=routingKey,
                                   body=msg)

    def process_wrong_message(self, convMsg):
        print "Help. I receive wrong message."

    def set_message_adapter(self, messageAdapter):
        self.messageAdapter = messageAdapter
예제 #3
0
 def __init__(self, role, 
              participant, 
              participants_config = None, 
              is_monitorable = False):
     # Participant attributes
     self.role = str.lower(role)
     self.participant = str.lower(participant)
     
     # Communication related 
     #self.cid = str(uuid.uuid4())
     self.adapter = AMQPConversationMessageAdapter()
     self.invitation_queue =  self.participant 
     
     #Protocol related
     self.participants_description = participants_config if participants_config else None
     self.protocol = None
     interrupt_msg = None
     interrup_callback = None
     #TODO: Fix me!!!
     self.is_monitorable = is_monitorable
     self.configure_invitation_bindings()
예제 #4
0
    def __init__(self,
                 cid,
                 role,
                 participant,
                 interactions,
                 lt_file,
                 start_conversation=None):
        # Participant attributes
        self.role = str.lower(role)
        self.participant = str.lower(participant)
        self.cid = cid
        self.lt_file = lt_file

        # Communication related
        self.adapter = AMQPConversationMessageAdapter()
        #self.queue_name = str.lower("%s_%s" %(self.participant,self.role))
        self.invitation_queue = self.participant
        self.interactions = interactions
        self.messages = self.create_messages_from_interactions(interactions)
        self.next_interaction = 0

        #If this is the conversation initiator
        self.start_conversation = start_conversation
        self.conversation = None
예제 #5
0
 def setUp(self):
     self.message_adapter = AMQPConversationMessageAdapter()