Ejemplo n.º 1
0
    def create_client_configuration(self, uuid):
        '''
        Return information to pass to the client so it can configure its expectations accordingly.
        This is built from the input of various components in the thywill system, and the provided
        additional_parameters.
        
        :Parameters:
            - uuid: a string ID for this client
            
        :Return:
            ClientConfiguration object
        '''

        # create a client configuration object. The additional parameters
        # dictionary is used to add in the uuid for a specific client.
        config = DjangoClientConfiguration(uuid)

        # add data from this component
        self._bootstrap_client(uuid, config)

        # add data from the other components; ordering should be such that
        # the application interface component is last, as that gives it a chance
        # to see what else is set.
        LogComponent.factory()._bootstrap_client(uuid, config)
        PushComponent.factory()._bootstrap_client(uuid, config)
        DatabaseComponent.factory()._bootstrap_client(uuid, config)
        ApplicationInterfaceComponent.factory()._bootstrap_client(uuid, config)

        return config
Ejemplo n.º 2
0
    def create_client_configuration(self, uuid):
        """
        Return information to pass to the client so it can configure its expectations accordingly.
        This is built from the input of various components in the thywill system, and the provided
        additional_parameters.
        
        :Parameters:
            - uuid: a string ID for this client
            
        :Return:
            ClientConfiguration object
        """

        # create a client configuration object. The additional parameters
        # dictionary is used to add in the uuid for a specific client.
        config = DjangoClientConfiguration(uuid)

        # add data from this component
        self._bootstrap_client(uuid, config)

        # add data from the other components; ordering should be such that
        # the application interface component is last, as that gives it a chance
        # to see what else is set.
        LogComponent.factory()._bootstrap_client(uuid, config)
        PushComponent.factory()._bootstrap_client(uuid, config)
        DatabaseComponent.factory()._bootstrap_client(uuid, config)
        ApplicationInterfaceComponent.factory()._bootstrap_client(uuid, config)

        return config
Ejemplo n.º 3
0
    def push_to_client(self, uuid, message):
        '''
        Push a message to a particular client via a STOMP server
        
        :Parameters:
            - uuid: The unique client identifier ID
            - message: A StompMessage object
        '''

        # TODO add a listener to connection to get confirmation of delivery?
        # TODO connection pool strategy
        # stomp.py docs: http://code.google.com/p/stomppy
        LogComponent.debug([
            'OrbitedStompComponent.push_to_client', self.stomp_hostname,
            self.stomp_port, uuid, message
        ])
        conn = stomp.Connection([(self.stomp_hostname, self.stomp_port)])
        conn.start()
        conn.connect()
        conn.send(message=message.contents,
                  destination=uuid,
                  type='textMessage',
                  ack='auto')
        conn.disconnect(
        )  # or conn.stop() - different behavior if there are listeners
Ejemplo n.º 4
0
def thywill(request):
    '''
    Deliver the basic thywill framing page, immediately prior to bootstrap.
    
    :Parameters:
        - request: HttpRequest
        
    :Return:
        HttpResponse
    '''
    uuid = __ensure_uuid(request)
    config = ClientInterfaceComponent.factory().create_client_configuration(uuid)
    context = Context({
        'config': config.to_dict(),
        'config_json': config.to_json(True),
    })
    LogComponent.debug(['django.requests.thywill', 'initial client page load', uuid, config.to_dict()])
    return HttpResponse(get_template('thywill.html').render(context))
Ejemplo n.º 5
0
    def push_to_client(self, uuid, message):
        """
        Push a message to a particular client via a STOMP server
        
        :Parameters:
            - uuid: The unique client identifier ID
            - message: A StompMessage object
        """

        # TODO add a listener to connection to get confirmation of delivery?
        # TODO connection pool strategy
        # stomp.py docs: http://code.google.com/p/stomppy
        LogComponent.debug(
            ["OrbitedStompComponent.push_to_client", self.stomp_hostname, self.stomp_port, uuid, message]
        )
        conn = stomp.Connection([(self.stomp_hostname, self.stomp_port)])
        conn.start()
        conn.connect()
        conn.send(message=message.contents, destination=uuid, type="textMessage", ack="auto")
        conn.disconnect()  # or conn.stop() - different behavior if there are listeners
Ejemplo n.º 6
0
def send(request):
    '''
    AJAX response: Send a client-originated message into the currently active application.
    
    :Parameters:
        - request: HttpRequest
            
    :Return:
        HttpResponse
    '''
    uuid = __ensure_uuid(request)
    if 'message' in request.POST:
        message = request.POST['message']
        LogComponent.debug(['django.requests.send', 'AJAX message from client', uuid, message])
        ApplicationInterfaceComponent.factory().client_message_received(uuid, message)
    else:
        LogComponent.debug(['django.requests.send', 'Invalid POST request', uuid, request.POST])
    
    # TODO return confirmation of some sort?
    
    
    return HttpResponse()
Ejemplo n.º 7
0
 def client_message_received(self, uuid, raw_message):
     '''
     Notify the application of a client message received by the receive component
     '''
     LogComponent.debug(['LocalPythonComponent.client_message_received', uuid, raw_message])
     self.app_interface_module.message_from_client(uuid, raw_message);
Ejemplo n.º 8
0
 def send_message_to_client(self, uuid, raw_message):
     '''
     Send a message to a specific client.
     '''
     LogComponent.debug(['LocalPythonComponent.send_message_to_client', uuid, raw_message])
     PushComponent.factory().push_raw_message_to_client(uuid, raw_message)