示例#1
0
 def read(self):
     read_data = self.socket.recv(BUFFER_SIZE)
     if read_data <= 0:
         self.close()
         return 0
     self.read_buffer.append(read_data)
     self._read_buffer_size += len(read_data)
     self.last_active_time = time.time()
     #here is the place where execute the business logic
     handler = Handler(self)
     handler.execute()
示例#2
0
def process(options):
    db = Database(user=options.user,
                  password=options.password,
                  host=options.host,
                  port=options.port,
                  db_name=options.db)

    handler = Handler(db)

    if options.operation:
        try:
            result = handler.execute(options)
            if result:
                print(result)
        except KeyError:
            print("Unknown operation '{}'".format(options.operation))
示例#3
0
    def handle_process(self, process, input_process=None):
        '''handle the individual process

        @params
        process - the name of the process to be handled
        input_process - the name of the input process that called
            this process
        '''

        # get the handler and instantiate it
        handler_class = self.pipeline.get_handler_class(process)
        if handler_class:
            try:
                handler = Common.create_from_class_path(handler_class)
            except ImportError:
                raise ImportError("Could not import handler class [%s]" % handler_class)

        else:
            handler = Handler()

        # pass the options to the handler
        options = self.pipeline.get_action_options(process)
        handler.set_options(options)
        
        # pass relevant information to the handler
        handler.set_process_name(process)
        handler.set_server(self.server)
        handler.set_pipeline(self.pipeline)
        handler.set_package(self.package)

        # if this is the first process (no input process, then the package
        # is the input 
        if not input_process:
            output = self.package.copy()
        else:
            # get input processes and hand over the delivery
            input_handler = self.handlers_dict.get(input_process)
            if input_handler:
                output = input_handler.get_output()
            else:
                output = {}

        # By default, inputs travel through
        handler.set_input( output )
        handler.set_output( output )


        # store the handler and execute
        self.handlers.append(handler)
        self.handlers_dict[process] = handler
        handler.execute()

        # process all of the output handlers.  First ask the current handler
        # for the next process
        output_processes = handler.get_next_processes()

        # if output processes is None, then stop this branch completely
        if output_processes == None:
            return

        # otherwise, use the pipeline
        if not output_processes:
            output_processes = self.pipeline.get_output_process_names(process)

        for output_process in output_processes:
            self.handle_process(output_process, process)