2017-05-25 23:04:33 +02:00
|
|
|
import Queue
|
2017-06-21 12:16:33 +02:00
|
|
|
import sys
|
2017-05-25 23:04:33 +02:00
|
|
|
import threading
|
2017-05-27 19:09:21 +02:00
|
|
|
import time
|
2017-05-25 23:04:33 +02:00
|
|
|
|
2017-05-27 19:09:21 +02:00
|
|
|
import addresses
|
2017-05-25 23:04:33 +02:00
|
|
|
from bmconfigparser import BMConfigParser
|
|
|
|
from debug import logger
|
|
|
|
from helper_threading import StoppableThread
|
|
|
|
from inventory import Inventory
|
|
|
|
from network.connectionpool import BMConnectionPool
|
2017-05-27 19:09:21 +02:00
|
|
|
from network.bmproto import BMProto
|
2017-07-06 19:45:36 +02:00
|
|
|
from queues import receiveDataQueue
|
2017-05-25 23:04:33 +02:00
|
|
|
import protocol
|
2017-05-29 14:35:08 +02:00
|
|
|
import state
|
2017-05-25 23:04:33 +02:00
|
|
|
|
|
|
|
class ReceiveQueueThread(threading.Thread, StoppableThread):
|
|
|
|
def __init__(self):
|
|
|
|
threading.Thread.__init__(self, name="ReceiveQueueThread")
|
|
|
|
self.initStop()
|
|
|
|
self.name = "ReceiveQueueThread"
|
2017-05-29 00:24:07 +02:00
|
|
|
logger.info("init receive queue thread")
|
2017-05-25 23:04:33 +02:00
|
|
|
|
|
|
|
def run(self):
|
2017-05-29 14:35:08 +02:00
|
|
|
while not self._stopped and state.shutdown == 0:
|
2017-07-06 19:45:36 +02:00
|
|
|
try:
|
|
|
|
connection = receiveDataQueue.get(block=True, timeout=1)
|
|
|
|
receiveDataQueue.task_done()
|
|
|
|
except Queue.Empty:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if self._stopped:
|
|
|
|
break
|
|
|
|
# cycle as long as there is data
|
|
|
|
# methods should return False if there isn't enough data, or the connection is to be aborted
|
|
|
|
try:
|
|
|
|
while connection.process():
|
|
|
|
pass
|
|
|
|
except AttributeError:
|
|
|
|
# missing command
|
|
|
|
logger.error("Unknown state %s, ignoring", connection.state)
|
2017-05-27 19:09:21 +02:00
|
|
|
|
2017-05-25 23:04:33 +02:00
|
|
|
def stopThread(self):
|
|
|
|
super(ReceiveQueueThread, self).stopThread()
|