示例#1
0
文件: agent.py 项目: eboladev/corpora
    def run(self):
        trace.info('Accepted client from {}:{}'.format(self.host, self.port))

        buf, request = '', ''
        response = None

        while True:
            try:
                response = self.queue.get_nowait()
            except Queue.Empty:
                pass

            if response:
                self.handle_response(response)
                response = None

            try:
                data = self.socket.recv(config.MESSAGING_BUFFER_SIZE)
                if data:
                    buf += data
                    end = buf.find('\n')
                    if end >= 0:
                        request = buf[:end].strip()
                        buf = buf[end + 2:]
                else:
                    break  # Connection closed
            except socket.timeout:
                pass

            if request:
                self.handle_request(request)
                request = ''

        self.socket.close()
        trace.info('Client {}:{} closed'.format(self.host, self.port))
示例#2
0
文件: agent.py 项目: rschiang/corpora
    def run(self):
        trace.info('Accepted client from {}:{}'.format(self.host, self.port))

        buf, request = '', ''
        response = None

        while True:
            try:
                response = self.queue.get_nowait()
            except Queue.Empty: pass

            if response:
                self.handle_response(response)
                response = None

            try:
                data = self.socket.recv(config.MESSAGING_BUFFER_SIZE)
                if data:
                    buf += data
                    end = buf.find('\n')
                    if end >= 0:
                        request = buf[:end].strip()
                        buf = buf[end+2:]
                else:
                    break   # Connection closed
            except socket.timeout: pass

            if request:
                self.handle_request(request)
                request = ''

        self.socket.close()
        trace.info('Client {}:{} closed'.format(self.host, self.port))
示例#3
0
文件: agent.py 项目: eboladev/corpora
 def handle_request(self, data):
     try:
         request = SMAPRequest(data, self)
         trace.info('Request', request.action.upper(), 'length', len(data))
     except (ValueError, KeyError):
         trace.info('Request length', len(data))
         self.queue.put(SMAPResponse('error', reason='bad_request'))
     else:
         routes.route_request(request)
示例#4
0
文件: agent.py 项目: rschiang/corpora
 def handle_request(self, data):
     try:
         request = SMAPRequest(data, self)
         trace.info('Request', request.action.upper(), 'length', len(data))
     except (ValueError, KeyError):
         trace.info('Request length', len(data))
         self.queue.put(SMAPResponse('error', reason='bad_request'))
     else:
         routes.route_request(request)
示例#5
0
    def __init__(self):
        super(MessagingService, self).__init__('messaging')

        self.counter = 0
        self.clients = []
        self.lock = Lock()

        s = socket.socket()
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        s.bind((config.MESSAGING_HOST, config.MESSAGING_PORT))
        s.listen(config.MESSAGING_MAX_PENDING_CLIENTS)
        self.socket = s

        trace.info('Listening on port', config.MESSAGING_PORT)
示例#6
0
文件: main.py 项目: rschiang/corpora
    def __init__(self):
        super(MessagingService, self).__init__('messaging')

        self.counter = 0
        self.clients = []
        self.lock = Lock()

        s = socket.socket()
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        s.bind((config.MESSAGING_HOST, config.MESSAGING_PORT))
        s.listen(config.MESSAGING_MAX_PENDING_CLIENTS)
        self.socket = s

        trace.info('Listening on port', config.MESSAGING_PORT)
示例#7
0
def run():
    threading.current_thread().name = 'main'
    trace.info('Starting Corpora.')

    app = threading.Event()
    def alive():
        return not app.is_set()

    for name in config.SERVICES:
        service = __import__(name).service
        service.alive = alive
        service.start()

    try:
        # Block until any key pressed
        sys.stdin.read()
    finally:
        trace.info('Shutting down.')
        app.set()
示例#8
0
文件: base.py 项目: eboladev/corpora
 def run(self):
     trace.info('Service started.')
     while self.alive():
         request = self.wait()
         self.handle(*request)
示例#9
0
文件: agent.py 项目: eboladev/corpora
 def handle_response(self, response):
     data = str(response) + '\n'
     trace.info('Response', response.status.upper(), 'length', len(data))
     self.socket.sendall(data)
示例#10
0
文件: agent.py 项目: rschiang/corpora
 def handle_response(self, response):
     data = str(response) + '\n'
     trace.info('Response', response.status.upper(), 'length', len(data))
     self.socket.sendall(data)
示例#11
0
def test__trace():
    trace.error("Here is the Error Information!!")
    trace.warning("Here is the Warning Information")
    trace.info("Here is the Trace Information")
    trace.debug("Here is the Debug Information")