def __init__(self, dataprotocl=DataPackProtoc()): '''初始化 ''' protocols.ServerFactory.__init__(self) self.service = None self.connmanager = ConnectionManager() self.dataprotocl = dataprotocl
class LiberateFactory(protocols.ServerFactory): '''协议工厂''' protocol = LiberateProtocol def __init__(self, dataprotocl=DataPackProtoc()): '''初始化 ''' protocols.ServerFactory.__init__(self) self.service = None self.connmanager = ConnectionManager() self.dataprotocl = dataprotocl def setDataProtocl(self, dataprotocl): ''' ''' self.dataprotocl = dataprotocl def doConnectionMade(self, conn): '''当连接建立时的处理''' pass def doConnectionLost(self, conn): '''连接断开时的处理''' pass def addServiceChannel(self, service): '''添加服务通道''' self.service = service def doDataReceived(self, conn, commandID, data): '''数据到达时的处理''' response = self.service.callTarget(commandID, conn, data) return response def produceResult(self, command, response): '''产生客户端需要的最终结果 @param response: str 分布式客户端获取的结果 ''' return self.dataprotocl.pack(command, response) def loseConnection(self, connID): """主动端口与客户端的连接 """ self.connmanager.loseConnection(connID) def pushObject(self, topicID, msg, sendList): '''服务端向客户端推消息 @param topicID: int 消息的主题id号 @param msg: 消息的类容,protobuf结构类型 @param sendList: 推向的目标列表(客户端id 列表) ''' self.connmanager.pushObject(topicID, msg, sendList)
class LiberateFactory(protocols.ServerFactory): '''协议工厂''' protocol = LiberateProtocol def __init__(self,dataprotocl=DataPackProtoc()): '''初始化 ''' protocols.ServerFactory.__init__(self) self.service = None self.connmanager = ConnectionManager() self.dataprotocl = dataprotocl def setDataProtocl(self,dataprotocl): ''' ''' self.dataprotocl = dataprotocl def doConnectionMade(self,conn): '''当连接建立时的处理''' pass def doConnectionLost(self,conn): '''连接断开时的处理''' pass def addServiceChannel(self,service): '''添加服务通道''' self.service = service def doDataReceived(self,conn,commandID,data): '''数据到达时的处理''' response = self.service.callTarget(commandID,conn,data) return response def produceResult(self,command,response): '''产生客户端需要的最终结果 @param response: str 分布式客户端获取的结果 ''' return self.dataprotocl.pack(command,response) def loseConnection(self,connID): """主动端口与客户端的连接 """ self.connmanager.loseConnection(connID) def pushObject(self,topicID , msg, sendList): '''服务端向客户端推消息 @param topicID: int 消息的主题id号 @param msg: 消息的类容,protobuf结构类型 @param sendList: 推向的目标列表(客户端id 列表) ''' self.connmanager.pushObject(topicID, msg, sendList)
def __init__(self, dataprotocl=DataPackProtoc()): """初始化 """ protocols.ServerFactory.__init__(self) self.service = None self.connmanager = ConnectionManager() self.dataprotocl = dataprotocl
class LiberateFactory(protocols.ServerFactory): """协议工厂""" protocol = LiberateProtocol def __init__(self, dataprotocl=DataPackProtoc()): """初始化 """ protocols.ServerFactory.__init__(self) self.service = None self.connmanager = ConnectionManager() self.dataprotocl = dataprotocl def setDataProtocl(self, dataprotocl): """ """ self.dataprotocl = dataprotocl def doConnectionMade(self, conn): """当连接建立时的处理""" pass def doConnectionLost(self, conn): """连接断开时的处理""" pass def addServiceChannel(self, service): """添加服务通道""" self.service = service def doDataReceived(self, conn, commandID, data): """数据到达时的处理""" if commandID == 88: _id = conn.transport.sessionno connection = self.connmanager.getConnectionByID(_id) if connection: connection.set_time() print "+++++++++++++++++++++++++++++88++++++++++++++++++++++++" # return 'I am the 88 return.' response = self.service.callTarget(commandID, conn, data) return response def produceResult(self, command, response): """产生客户端需要的最终结果 @param response: str 分布式客户端获取的结果 """ return self.dataprotocl.pack(command, response) def loseConnection(self, connID): """主动端口与客户端的连接 """ self.connmanager.loseConnection(connID) def change_id(self, new_id, cur_id): return self.connmanager.change_id(new_id, cur_id) def kick(self, msg, pid): return self.connmanager.kick(msg, pid) def get_ipaddress(self, pid): return self.connmanager.get_ipaddress(pid) def pushObject(self, topicID, msg, sendList): """服务端向客户端推消息 @param topicID: int 消息的主题id号 @param msg: 消息的类容,protobuf结构类型 @param sendList: 推向的目标列表(客户端id 列表) """ logger.info("pushObject: %s to %s" % (topicID, sendList)) self.connmanager.pushObject(topicID, msg, sendList) def pushAllObject(self, topicID, msg): """服务端向所有连接客户端推消息 @param topicID: int 消息的主题id号 @param msg: 消息的类容,protobuf结构类型 """ logger.info("pushAllObject:topic_id: %s" % topicID) self.connmanager.pushAllObject(topicID, msg)
class LiberateFactory(protocols.ServerFactory): '''协议工厂''' protocol = LiberateProtocol def __init__(self, dataprotocl=DataPackProtoc()): '''初始化 ''' protocols.ServerFactory.__init__(self) self.service = None self.connmanager = ConnectionManager() self.dataprotocl = dataprotocl def setDataProtocl(self, dataprotocl): ''' ''' self.dataprotocl = dataprotocl def doConnectionMade(self, conn): '''当连接建立时的处理''' pass def doConnectionLost(self, conn): '''连接断开时的处理''' pass def addServiceChannel(self, service): '''添加服务通道''' self.service = service def doDataReceived(self, conn, commandID, data): '''数据到达时的处理''' if commandID == 88: connection = self.connmanager.getConnectionByID( conn.transport.sessionno) connection.set_time() print "+++++++++++++++++++++++++++++88++++++++++++++++++++++++++++++++++++++++" return 'I am the 88 return.' response = self.service.callTarget(commandID, conn, data) return response def produceResult(self, command, response): '''产生客户端需要的最终结果 @param response: str 分布式客户端获取的结果 ''' return self.dataprotocl.pack(command, response) def loseConnection(self, connID): """主动端口与客户端的连接 """ self.connmanager.loseConnection(connID) def change_id(self, new_id, cur_id): return self.connmanager.change_id(new_id, cur_id) def pushObject(self, topicID, msg, sendList): '''服务端向客户端推消息 @param topicID: int 消息的主题id号 @param msg: 消息的类容,protobuf结构类型 @param sendList: 推向的目标列表(客户端id 列表) ''' logger.info("pushObject: %s to %s" % (topicID, sendList)) self.connmanager.pushObject(topicID, msg, sendList)