def submitQuery(self, query): self.log.debug("Submit query : {0}".format(query)) # Verify the request is not in the cache cachedValue = self.cache.getCachedResult(query) if cachedValue is not None: self.log.info("The MQ is cached, result obtained: {0} = {1}.".format(str(query), str(cachedValue))) self.log.info("The MQ is cached, result obtained: {0} = {1}.". format(str(query), str(cachedValue))) return cachedValue[len(cachedValue) - 1] # TODO : must be UPGRADED # WARNING if self.resetScript != "": self.log.info("Reseting the oracle by executing script: {0}".format(self.resetScript)) self.log.info("Reseting the oracle by executing script: {0}". format(self.resetScript)) os.system("sh " + self.resetScript) self.log.info("Submit the following query: {0}".format(str(query))) isMaster = not self.communicationChannel.isServer() # transform the query into a MMSTD mmstd = query.toMMSTD(self.dictionary, isMaster) self.cb_hypotheticalAutomaton(mmstd) time.sleep(2) self.log.info("The current experimentation has generated the following MMSTD: {0}".format(self.log.debug(mmstd.getDotCode()))) self.log.info( "The current experimentation has generated the following MMSTD: {0}". format(self.log.debug(mmstd.getDotCode()))) # create an oracle for this MMSTD oracle = NetworkOracle(self.communicationChannel, isMaster) # start the oracle with the MMSTD oracle.setMMSTD(mmstd) oracle.start() # wait it has finished self.log.info("Waiting for the oracle to finish") while oracle.isAlive(): time.sleep(0.01) self.log.info("The oracle has finished !") # stop the oracle and retrieve the query oracle.stop() self.log.info("Close (again) the server") self.communicationChannel.close() if isMaster: resultQuery = oracle.getResults() tmpResultQuery = oracle.getGeneratedOutputSymbols() else: resultQuery = oracle.getGeneratedInputSymbols() tmpResultQuery = oracle.getGeneratedInputSymbols() oracle.getGeneratedOutputSymbols() else:
def submitQuery(self, query): self.log.debug("Submit query : {0}".format(query)) # Verify the request is not in the cache cachedValue = self.cache.getCachedResult(query) if cachedValue is not None: self.log.info( "The MQ is cached, result obtained: {0} = {1}.".format( str(query), str(cachedValue))) return cachedValue[len(cachedValue) - 1] # TODO : must be UPGRADED # WARNING if self.resetScript != "": self.log.info( "Reseting the oracle by executing script: {0}".format( self.resetScript)) os.system("sh " + self.resetScript) self.log.info("Submit the following query: {0}".format(str(query))) isMaster = not self.communicationChannel.isServer() # transform the query into a MMSTD mmstd = query.toMMSTD(self.dictionary, isMaster) self.cb_hypotheticalAutomaton(mmstd) time.sleep(2) self.log.info( "The current experimentation has generated the following MMSTD: {0}" .format(self.log.debug(mmstd.getDotCode()))) # create an oracle for this MMSTD oracle = NetworkOracle(self.communicationChannel, isMaster) # start the oracle with the MMSTD oracle.setMMSTD(mmstd) oracle.start() # wait it has finished self.log.info("Waiting for the oracle to finish") while oracle.isAlive(): time.sleep(0.01) self.log.info("The oracle has finished !") # stop the oracle and retrieve the query oracle.stop() self.log.info("Close (again) the server") self.communicationChannel.close() if isMaster: resultQuery = oracle.getResults() oracle.getGeneratedOutputSymbols() else: resultQuery = oracle.getGeneratedInputSymbols() oracle.getGeneratedInputSymbols() self.log.info("---------------------------------------------") self.log.info("RESUMONS UN PETIT PEU TOUT CA:") self.log.info("---------------------------------------------") self.log.info("SUBMITED: {0}".format(str(query))) self.log.info("---------------------------------------------") self.log.info("RESULT:") self.log.info("---------------------------------------------") strResultQuery = [] for data in resultQuery: strResultQuery.append(data.getName()) self.log.info("+ getResults: {0}".format(', '.join(strResultQuery))) self.log.info("---------------------------------------------") strGeneratedInputSymbols = [] for data in oracle.getGeneratedInputSymbols(): strGeneratedInputSymbols.append(data.getName()) self.log.info("+ getGeneratedInputSymbols: {0}".format( ', '.join(strGeneratedInputSymbols))) self.log.info("---------------------------------------------") strGeneratedOutputSymbols = [] for data in oracle.getGeneratedOutputSymbols(): strGeneratedOutputSymbols.append(data.getName()) self.log.info("+ getGeneratedOutputSymbols: {0}".format( ', '.join(strGeneratedOutputSymbols))) self.log.info("---------------------------------------------") # Register this query and the associated response self.submitedQueries.append([query, resultQuery]) # return only the last result if len(resultQuery) > 0: # Execute the call back function # GObject.idle_add(self.callbackFunction, query, tmpResultQuery) result = resultQuery[len(resultQuery) - 1] self.cache.cacheResult(query, resultQuery) self.cache.dumpCache() return result else: # Execute the call back function # GObject.idle_add(self.callbackFunction, query, "OUPS") self.cache.cacheResult(query, resultQuery) return resultQuery
def submitQuery(self, query): # Verify the request is not in the cache cachedValue = self.cache.getCachedResult(query) if cachedValue != None: self.log.info("The MQ is cached, result obtained : " + str(query) + " = " + str(cachedValue) + ".") return cachedValue[len(cachedValue) - 1] # TODO : must be UPGRADED # WARNING if self.resetScript != "": self.log.info("Reseting the oracle by executing script : " + self.resetScript) os.system("sh " + self.resetScript) self.log.info("Submit the following query : " + str(query)) isMaster = not self.communicationChannel.isServer() # transform the query into a MMSTD mmstd = query.toMMSTD(self.dictionary, isMaster) self.cb_hypotheticalAutomaton(mmstd) time.sleep(10) self.log.info("The current experimentation has generated the following MMSTD :") self.log.debug(mmstd.getDotCode()) # create an oracle for this MMSTD oracle = NetworkOracle(self.communicationChannel, isMaster) # start the oracle with the MMSTD oracle.setMMSTD(mmstd) oracle.start() # wait it has finished self.log.info("Waiting for the oracle to finish") while oracle.isAlive(): time.sleep(0.01) self.log.info("The oracle has finished !") # stop the oracle and retrieve the query oracle.stop() self.log.info("Close (again) the server") self.communicationChannel.close() if isMaster: resultQuery = oracle.getResults() tmpResultQuery = oracle.getGeneratedOutputSymbols() else: resultQuery = oracle.getGeneratedInputSymbols() tmpResultQuery = oracle.getGeneratedInputSymbols() self.log.info("---------------------------------------------") self.log.info("RESUMONS UN PETIT PEU TOUT CA :") self.log.info("---------------------------------------------") self.log.info("SUBMITED : ") self.log.info(str(query)) self.log.info("---------------------------------------------") self.log.info("RESULT :") self.log.info("---------------------------------------------") self.log.info("+ getResults :") self.log.info(str(resultQuery)) self.log.info("---------------------------------------------") self.log.info("+ getGeneratedInputSymbols :") self.log.info(str(oracle.getGeneratedInputSymbols())) self.log.info("---------------------------------------------") self.log.info("+ getGeneratedOutputSymbols :") self.log.info(str(oracle.getGeneratedOutputSymbols())) self.log.info("---------------------------------------------") self.log.info("The following query has been computed : " + str(resultQuery)) # Register this query and the associated response self.submitedQueries.append([query, resultQuery]) # return only the last result if len(resultQuery) > 0: # Execute the call back function gobject.idle_add(self.callbackFunction, query, tmpResultQuery) result = resultQuery[len(resultQuery) - 1] self.cache.cacheResult(query, resultQuery) self.cache.dumpCache() return result else: # Execute the call back function gobject.idle_add(self.callbackFunction, query, "OUPS") self.cache.cacheResult(query, resultQuery) return resultQuery