コード例 #1
0
 def __init__(self, certificatesDirectory=None):
     """
     Initializes the NetworkManager's state.
     Args:
         certificatesDirectory: the directory where the files server.crt and server.key are.
     """
     self.__connectionPool = GenericThreadSafeDictionary()
     self.__outgoingDataQueue = GenericThreadSafePriorityQueue()
     if (not reactor.running):
         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)