コード例 #1
0
 def __init__(self, certificatesDirectory=None, createReactorThread=True):
     """
     Initializes the NetworkManager's state.
     Args:
         certificatesDirectory: the directory where the files server.crt and server.key are.
         createReactorThread: if True, a dedicated reactor thread will be created. If false,
         this thread won't be created.
     """
     createReactorThread = not reactor.running
     self.__connectionPool = GenericThreadSafeDictionary()
     self.__outgoingDataQueue = GenericThreadSafePriorityQueue()
     if (createReactorThread):
         self.__networkThread = _TwistedReactorThread()
     else:
         self.__networkThread = None
     self.__outgoingDataThread = _OutgoingDataThread(
         self.__outgoingDataQueue)
     self.__connectionThread = _ConnectionMonitoringThread(
         self.__connectionPool)
     self.__certificatesDirectory = certificatesDirectory
コード例 #2
0
 def __allocateConnectionResources(self, callbackObject):
     """
     Allocates the resources associated to a new connection (only if necessary) 
     Args:
         callbackObject: The object that will process all the incoming packages.
     Returns:
         a tuple (queue, thread), where queue and thread are the incoming data queue
         and the incoming data processing thread assigned to this new connection.
     """
     c = None
     for connection in self.__connectionPool.values():
         if (connection.getCallback() == callbackObject):
             # Everything is allocated. Let's reuse it.
             c = connection
             break
     if c != None:
         return (c.getQueue(), c.getThread())
     else:
         queue = GenericThreadSafePriorityQueue()
         thread = _IncomingDataThread(queue, callbackObject)
         return (queue, thread)