def Config(clas): """ :return: A dictionary containing SocketPro pools configuration """ with SpManager._cs_: if SpManager._sp_config: SpManager._sp_config[ 'WorkingDir'] = ccl.GetClientWorkDirectory().decode( 'latin-1') return SpManager._sp_config return None
def SeekByQueue(self, queueName=''): h = None if queueName is None or len(queueName) == 0: with self._lock_: merge = ccl.GetQueueAutoMergeByPool(self._PoolId_) for cs in self._m_dicSocketHandler_.keys(): if merge and cs.ConnectionState < tagConnectionState.csSwitched: continue cq = cs.ClientQueue if not cq.Available: continue if h is None: h = self._m_dicSocketHandler_[cs] elif (cq.MessageCount < h.AttachedClientSocket.ClientQueue.MessageCount) or ( (not h.AttachedClientSocket.Connected) and cs.Connected): h = self._m_dicSocketHandler_[cs] else: if CUQueue.DEFAULT_OS == tagOperationSystem.osWin: queueName = queueName.lower() rawName = '' appName = ccl.GetClientWorkDirectory().decode('latin-1') with self._lock_: for cs in self._m_dicSocketHandler_.keys(): if not cs.ClientQueue.Available: continue if cs.ClientQueue.Secure: rawName = queueName + "_" + appName + "_1.mqc" else: rawName = queueName + "_" + appName + "_0.mqc" queueFileName = cs.ClientQueue.QueueFileName length = len(queueFileName) lenRaw = len(rawName) if lenRaw > length: continue pos = queueFileName.rfind(rawName) #queue file name with full path if pos == 0: return self._m_dicSocketHandler_[cs] #queue raw name only if pos + lenRaw == length: return self._m_dicSocketHandler_[cs] return h
def SetConfig(midTier=False, jsonConfig=None): """ Set socket pools configuration from a JSON text file :param midTier: True if calling from a middle tier; Otherwise, false :param jsonConfig: >A file path to a JSON configuration text file, which defaults to sp_config.json at current directory :return: A dictionary containing SocketPro pools configuration """ with SpManager._cs_: if SpManager._sp_config: return SpManager._sp_config if not jsonConfig: jsonConfig = 'sp_config.json' with open(jsonConfig, 'r') as jf: s = jf.read() start = s.find('{') s = s[start:] sc = json.loads(s) if 'CertStore' in sc and sc['CertStore']: ccl.SetVerifyLocation(sc['CertStore'].encode('latin-1')) if 'WorkingDir' in sc and sc['WorkingDir']: ccl.SetClientWorkDirectory( sc['WorkingDir'].encode('latin-1')) if 'QueuePassword' in sc and sc['QueuePassword']: ccl.SetMessageQueuePassword( sc['QueuePassword'].encode('latin-1')) sc['QueuePassword'] = 1 else: sc['QueuePassword'] = 0 if 'KeysAllowed' in sc: ka = [] for s in sc['KeysAllowed']: ka.append(s.lower()) sc['KeysAllowed'] = ka SpManager._CheckErrors(sc) SpManager._sp_config = sc SpManager._sp_config['WorkingDir'] = ccl.GetClientWorkDirectory( ).decode('latin-1') return SpManager._sp_config