def __init__(self, queue): """ Initializes the protocol factory Args: queue: the incoming data queue to use by all protocol instances """ self.protocol = _CygnusCloudProtocol self.__queue = queue self.__connections = GenericThreadSafeList()
class _CygnusCloudProtocolFactory(Factory): """ Protocol factory. These objects are used to create protocol instances within the Twisted Framework, and store all the data shared by multiple protocol instances. """ def __init__(self, queue): """ Initializes the protocol factory Args: queue: the incoming data queue to use by all protocol instances """ self.protocol = _CygnusCloudProtocol self.__queue = queue self.__connections = GenericThreadSafeList() def buildProtocol(self, addr): """ Builds a protocol, stores a pointer to it and finally returns it. This method is called inside Twisted code. """ instance = _CygnusCloudProtocol(self) self.__connections.append(instance) return instance def removeConnection(self, connection): self.__connections.remove(connection) def isDisconnected(self): return self.__connections.getSize() == 0 def sendPacket(self, packet): """ Returns the last built instance Args: None Returns: the last built protocol instance """ i = 0 while (i < self.__connections.getSize()) : self.__connections[i].sendPacket(packet) i += 1 def disconnect(self): i = 0 while i < self.__connections.getSize() : p = self.__connections[i] p.disconnect() i += 1 def onPacketReceived(self, p): """ Returns the incoming packages queue Args: None Returns: The incoming packages queue """ p = _Packet._deserialize(p) self.__queue.queue(p.getPriority(), p)
class _CygnusCloudProtocolFactory(Factory): """ Protocol factory. These objects are used to create protocol instances within the Twisted Framework, and store all the data shared by multiple protocol instances. """ def __init__(self, queue): """ Initializes the protocol factory Args: queue: the incoming data queue to use by all protocol instances """ self.protocol = _CygnusCloudProtocol self.__queue = queue self.__connections = GenericThreadSafeList() def buildProtocol(self, addr): """ Builds a protocol, stores a pointer to it and finally returns it. This method is called inside Twisted code. """ instance = _CygnusCloudProtocol(self) self.__connections.append(instance) return instance def removeConnection(self, connection): self.__connections.remove(connection) def isDisconnected(self): return self.__connections.getSize() == 0 def sendPacket(self, packet): """ Returns the last built instance Args: None Returns: the last built protocol instance """ i = 0 while (i < self.__connections.getSize()): self.__connections[i].sendPacket(packet) i += 1 def disconnect(self): i = 0 while i < self.__connections.getSize(): p = self.__connections[i] p.disconnect() i += 1 def onPacketReceived(self, p): """ Returns the incoming packages queue Args: None Returns: The incoming packages queue """ p = _Packet._deserialize(p) self.__queue.queue(p.getPriority(), p)