def SetRequest(self, reqEl, sId): """Incoming request from network layer. After receiving a request an answer must be issued to network with method SendRequest from pNetworkInterface. reqEl - element with request from other owl id -- unique id generated by network """ pManager.manager.DebugStr('pRecommendationInterface '+ __version__ +': Got single request from network. Id: '+str(sId), 4) request = cRequest.cRequest() request.SetElement(reqEl) psi = pManager.manager.GetStatisticsInterface() lMatchingRules = psi.GetMatches(request.GetUrls()) if lMatchingRules: answer = cAnswer.cAnswer() answer.SetRules(lMatchingRules) answerEl = answer.GetElement() # Get NetworkInterface pNetIntf = pManager.manager.GetNetworkInterface() # send answer pManager.manager.DebugStr('pRecommendationInterface '+ __version__ +': Now sending answer to network. Id: '+str(sId), 4) pNetIntf.SendAnswer(answerEl, sId) pManager.manager.DebugStr('pRecommendationInterface '+ __version__ +': Finished sending answer to network. Id: '+str(sId), 4) self.iNumAnsweredRecommendations = self.iNumAnsweredRecommendations + 1 else: pManager.manager.DebugStr('pRecommendationInterface '+ __version__ +': Dont have answers for request. Id: '+str(sId), 4)
def SetAnswer(self, lEls): """Parse answer into internal representation. lEls -- list of answer elements """ answer = cAnswer.cAnswer() answer.SetElements(lEls) self.Answers.append(answer)
def SetAnswer(self, answerEl, sId): """Incoming answer for a sent request from network layer. answer -- elements with answer from other owls id -- unique id of my request """ pManager.manager.DebugStr('pRecommendationInterface '+ __version__ +': Got answer from network for my request. Id: '+str(sId), 3) answer = cAnswer.cAnswer() answer.SetElement(answerEl) # extract rules from answer lAnswerRules = answer.GetRules() # look if request is still active if self.dRules.has_key(sId): # okay, append to answerlist self.dRules[sId].append(lAnswerRules) else: pManager.manager.DebugStr('pRecommendationInterface '+ __version__ +': Throwing away answer. Request is already gone! Id: '+str(sId), 3)
def PreperateAnswer(self): """Preperate answer for request.""" answer = cAnswer.cAnswer()