def __init__(self, ubercount, service, method): self.ubercount = ubercount if ubercount: self.channel = uthread.Channel(('UberMachoRemoteServiceCall', service + '::' + method)) else: self.channel = None self.tasklet = None
def Execute(self): if self.sr.queue is not None: raise RuntimeError('already executing?') self.sr.queue = uthread.Channel() ret = self.sr.queue.receive() self.sr.queue = None return ret
def Run(self, memStream=None): self.LogInfo('Starting Voucher Cache Service') self.data = {} self.names = {} self.ReleaseVoucherSvc() self.nameQueue = uthread.Channel('voucherCache._NameFetcher') uthread.new(self._NameFetcher, self.nameQueue)
def ConfirmationRequest(self, targetID, msgName, actualTargetID): if self.HasConfirmation(targetID, msgName): return 1 item = self.michelle.GetItem(actualTargetID) targetName = 'your target' if item is not None: targetName = uix.GetSlimItemName(item) k = (targetID, msgName) if self.pendingConfirmations.has_key(k): return self.pendingConfirmations[k].receive() result = 0 self.pendingConfirmations[k] = uthread.Channel(('consider::ConfirmationRequest', k)) try: ret = eve.Message(msgName, {'target': targetName}, uiconst.YESNO, suppress=uiconst.ID_YES, default=uiconst.ID_NO) if ret != uiconst.ID_YES: result = 0 return 0 self.RememberConfirmation(targetID, msgName) result = 1 finally: if self.pendingConfirmations.has_key(k): while self.pendingConfirmations[k].queue: self.pendingConfirmations[k].send(result) del self.pendingConfirmations[k] return result
def GetVoucherName(self, voucherID): """ Get a voucher name, first looking in local cache and then if not found will call the server. Uses _NameFetcher so that multiple name requests can be batched up in a single server call rather than having multiple calls for one name at a time. """ if voucherID in self.names: return self.names[voucherID] responseChannel = uthread.Channel( ('GetVoucherNameWithWait', voucherID)) self.nameQueue.send((voucherID, responseChannel)) return responseChannel.receive()
def UberMachoRemoteServiceCall(self, nodeGroup, batchInterval, sess, service, method, *args, **keywords): if batchInterval: queue = sess.GetSessionVariable(('batchedCallQueue', batchInterval), ({}, {})) if not queue[0]: uthread.worker('GPCS::BroadcastStuff::BatchedUberMachoRemoteServiceCall', self.__BatchedUberMachoRemoteServiceCall, nodeGroup, sess, batchInterval) i = len(queue[0]) queue[0][i] = (service, method, args, keywords) queue[1][i] = uthread.Channel() return queue[1][i].receive() else: return self.__UberMachoRemoteServiceCall(sess, service, method, self.__GetNodeGroup(nodeGroup), *args, **keywords)
def GetTech3ShipFromDict(self, shipTypeID, subSystems, race=None): shipsDir = blue.paths.ResolvePathForWriting('cache:/ships/') if not os.path.exists(shipsDir): os.makedirs(shipsDir) t = subSystems.values() t.sort() uniqueComboID = '_'.join([str(id) for id in t]) cacheVersion = 'v7' blackFileCachePath = 'cache:/ships/%s_%s_%s.black' % ( cacheVersion, shipTypeID, uniqueComboID) gr2FileCachePath = 'cache:/ships/%s_%s_%s.gr2' % ( cacheVersion, shipTypeID, uniqueComboID) lockFileCachePath = 'cache:/ships/%s_%s_%s.lock' % ( cacheVersion, shipTypeID, uniqueComboID) blackFilePath = blue.paths.ResolvePathForWriting(blackFileCachePath) gr2FilePath = blue.paths.ResolvePathForWriting(gr2FileCachePath) lockFilePath = blue.paths.ResolvePathForWriting(lockFileCachePath) model = None if os.path.exists(blackFilePath) and os.path.exists(gr2FilePath): self.LogInfo('Loading existing modular ship from', blackFileCachePath) model = trinity.LoadUrgent(blackFileCachePath) trinity.WaitForUrgentResourceLoads() if model is None: self.LogInfo( 'Failed to load - black file may no longer be compatible - deleting', blackFileCachePath) try: os.remove(blackFilePath) os.remove(gr2FilePath) blue.resMan.loadObjectCache.Delete(blackFileCachePath) except OSError: self.LogError("Couldn't delete", blackFileCachePath) if model is None: if blackFileCachePath in self.buildsInProgress: self.LogInfo('Build in progress for modular ship at', blackFileCachePath) doneChannel = self.buildsInProgress[blackFileCachePath] success = doneChannel.receive() self.LogInfo('Done waiting for modular ship at', blackFileCachePath) else: keepTrying = True while keepTrying: try: self.LogInfo('Checking for lock file', lockFilePath) lockFile = os.mkdir(lockFilePath) try: self.LogInfo('Starting to build modular ship at', blackFileCachePath) doneChannel = uthread.Channel() self.buildsInProgress[ blackFileCachePath] = doneChannel builder = trinity.EveShip2Builder() builder.weldThreshold = 0.02 builder.electronic = inventorycommon.typeHelpers.GetGraphicFile( subSystems[const.groupElectronicSubSystems]) builder.defensive = inventorycommon.typeHelpers.GetGraphicFile( subSystems[const.groupDefensiveSubSystems]) builder.engineering = inventorycommon.typeHelpers.GetGraphicFile( subSystems[const.groupEngineeringSubSystems]) builder.offensive = inventorycommon.typeHelpers.GetGraphicFile( subSystems[const.groupOffensiveSubSystems]) builder.propulsion = inventorycommon.typeHelpers.GetGraphicFile( subSystems[const.groupPropulsionSubSystems]) builder.highDetailOutputName = gr2FileCachePath uthread.new(self.BuildShip, builder, blackFilePath, doneChannel) success = doneChannel.receive() self.LogInfo('Done building modular ship at', blackFileCachePath) finally: keepTrying = False os.rmdir(lockFilePath) except WindowsError: self.LogInfo( 'Build in progress by another process for modular ship at', blackFileCachePath) doneChannel = uthread.Channel() self.buildsInProgress[blackFileCachePath] = doneChannel start = blue.os.GetWallclockTime() while os.path.exists(lockFilePath): blue.synchro.Yield() timeOut = blue.os.TimeDiffInMs( start, blue.os.GetWallclockTime()) if timeOut > MAX_WAIT_FOR_OTHER_PROCESS: self.LogInfo( 'Build by another process seems to have failed for modular ship at', blackFileCachePath) try: os.rmdir(lockFilePath) except WindowsError: self.LogError( "Can't delete lock file for modular ship at", blackFileCachePath) keepTrying = False break if os.path.exists(blackFilePath) and os.path.exists( gr2FilePath): self.LogInfo( 'Other process finished building modular ship at', blackFileCachePath) keepTrying = False success = True else: success = False del self.buildsInProgress[blackFileCachePath] if not success: return if model is None: model = trinity.LoadUrgent(blackFileCachePath) trinity.WaitForUrgentResourceLoads() if model is not None and race is not None: impactEffectResPath = self.impactEffectResPaths.get(race, None) if impactEffectResPath is not None: model.impactOverlay = trinity.Load(impactEffectResPath) return model
def GetVoucherName(self, voucherID): if voucherID in self.names: return self.names[voucherID] responseChannel = uthread.Channel(('GetVoucherNameWithWait', voucherID)) self.nameQueue.send((voucherID, responseChannel)) return responseChannel.receive()