Esempio n. 1
0
    def load(self, *args, **kargs):
        '''
        Loads application packages.
        '''

        packaging.load('deltapy.event_system')

        # It has to be a difference between application initialize event, which is fired when
        # loading packages got completed, and its start event, which is when application is
        # fully loaded and configured, and of course, ready to serve.
        event_system_services.register_event('application.initialize',
                                             self._initialize_requirements_)
        event_system_services.register_event('application.start',
                                             self._start_requirements_)
        event_system_services.register_event('application.stop',
                                             self._stop_requirements_)

        # Loading packages
        current_package = get_package_of('deltapy')
        packaging.load(current_package)

        # Setting application status to ready
        self._set_status_(Application.StatusEnum.READY)

        import deltapy.application.commands

        current_package = get_package_of(self.get_name())
        packaging.load(current_package)
        print ">> Application[%s] loaded." % self.get_name()

        # Application is initializing.
        event_system_services.fire('application.initialize')
Esempio n. 2
0
    def terminate(self, *args):
        '''
        Terminates the application.
        '''

        print ">> Terminating application[%s]... " % self.get_name()

        # Forcing termination after 12 seconds.
        signal.alarm(12)

        event_system_services.fire('application.stop')
        self._set_status_(Application.StatusEnum.TERMINATED)

        sys.exit(0)
Esempio n. 3
0
    def run(self, *args, **kargs):
        '''
        Runs the application.
        '''

        # Getting application instance name
        self.__instance_name = kargs.get('instance_name', None)

        # Getting options
        self.__options.update(kargs.get('options', self.__options))

        self.context['__app_options__'] = self.__options

        #Setting process name.
        self._set_process_title()

        self._set_status_(Application.StatusEnum.LOADING)
        print ">> Loading application[%s]." % self.get_name()
        self.load(*args, **kargs)

        # Application is satrting.
        event_system_services.fire('application.start')

        # Getting parent information
        parent_info = kargs.get('parent_info', None)

        # Connecting to parent application, If the parent application
        # is determined.
        if parent_info:
            # Connecting to parent application...
            parent_name = parent_info.get('name', None)
            parent_ticket = parent_info.get('ticket', None)
            if not parent_ticket:
                raise ApplicationException(
                    'Parent application ticket is not determined.')

            print ">> Connecting to parent application[%s]." % (parent_name)

            # Getting listener information
            parent_listener_info = kargs.get('listener_info', None)

            # Creating the parent proxy
            self.parent_proxy = \
                communication.create_proxy_by_ticket(parent_ticket,
                                                     self.get_name(),
                                                     **parent_listener_info)

            import deltapy.security.authentication.services as authentication_services
            # Creating a ticket for parent application
            ticket = authentication_services.internal_login(parent_name,
                                                            force=True)

            # Getting listener parameters
            listener_params = communication.get_listener_params(
                communication.get_default_listener().get_name())

            # Enlisting this application on parent application.
            self.parent_proxy.execute('app.enlist', self.get_name(),
                                      self.get_instance_name(), parent_name,
                                      ticket, dict(listener_params))

        self._set_status_(Application.StatusEnum.RUNNING)

        signal.signal(signal.SIGTERM, self.terminate)
Esempio n. 4
0
def fire(event_name, *args, **kwargs):
    '''
    Fires specified event using given parameters. 
    @param event_name: event name
    '''
    return event_system.fire(event_name, *args, **kwargs)
 def new_func(*args, **kwds):
     return event_services.fire(event_name, *args, **kwds)