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):
|
2017-07-10 07:08:10 +02:00
|
|
|
def __init__(self, num=0):
|
|
|
|
threading.Thread.__init__(self, name="ReceiveQueue_%i" %(num))
|
2017-05-25 23:04:33 +02:00
|
|
|
self.initStop()
|
2017-07-10 07:08:10 +02:00
|
|
|
self.name = "ReceiveQueue_%i" % (num)
|
|
|
|
logger.info("init receive queue thread %i", num)
|
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:
|
2017-07-08 06:54:25 +02:00
|
|
|
dest = receiveDataQueue.get(block=True, timeout=1)
|
2017-07-06 19:45:36 +02:00
|
|
|
except Queue.Empty:
|
|
|
|
continue
|
|
|
|
|
|
|
|
if self._stopped:
|
|
|
|
break
|
2017-07-08 06:54:25 +02:00
|
|
|
|
2017-07-06 19:45:36 +02:00
|
|
|
# cycle as long as there is data
|
|
|
|
# methods should return False if there isn't enough data, or the connection is to be aborted
|
2017-07-08 06:54:25 +02:00
|
|
|
|
2017-07-08 07:33:29 +02:00
|
|
|
# state_* methods should return False if there isn't enough data,
|
|
|
|
# or the connection is to be aborted
|
2017-07-08 06:54:25 +02:00
|
|
|
|
|
|
|
try:
|
2017-07-08 18:02:47 +02:00
|
|
|
BMConnectionPool().getConnectionByAddr(dest).process()
|
|
|
|
# KeyError = connection object not found
|
|
|
|
# AttributeError = state isn't implemented
|
2017-07-08 07:33:29 +02:00
|
|
|
except (KeyError, AttributeError):
|
2017-07-08 06:54:25 +02:00
|
|
|
pass
|
2017-07-10 07:08:10 +02:00
|
|
|
receiveDataQueue.task_done()
|