def service_call(self, data): # if not self.svcb.is_ if self.svcb.is_error(): raise exceptions.SVInstanceErrorException( error_msg=self.svcb.error_msg) if self.svcb.is_stop(): raise exceptions.SVInstanceException( message='The Service Insetance Has been Stopped:%s' % self.svcb.id) if not self.svcb.is_ready() or self.svcb.is_suspend(): raise exceptions.SVInstanceStateException( cur_state=self.svcb.state, need_state=ServiceCtrlBlock.READY) ''' 向线程发送数据,让其处理,等待线程处理完数据,但这只有 1.向线程发送需要处理的数据 2.判断是否为后台程序 (1).是:不等待处理的数据 (2).否:等待线程返回处理的数据,如果在规定的时间内没有返回的数据,则抛出异常 3.返回结果 ''' output_queue = Queue.Queue() self.__conn_queue.put((data, output_queue)) if self.svcb.is_undaem(): data = output_queue.get(True, 4) return data
def __set_Thread(self, svthr): ''' 如果svthr为不为空,设置type为异步类型 ''' if svthr is None: return if not isinstance(svthr, threading.Thread): raise exceptions.SVInstanceException(message='ErrorThreadType:%s' % type(svthr)) self[self.SVTHREAD] = weakref.ref(svthr)
def __set_Type(self, svtype): ''' 设置服务的类型,如果服务的类型不在规定的类型里面,抛出异常 ''' svtype = str(svtype) if svtype not in self.TYPES: raise exceptions.SVInstanceException( message='Unkown Service Instance Type:%s' % svtype) self[self.TYPE] = svtype
def suspend(self): if self.svcb.is_error(): raise exceptions.SVInstanceErrorException( error_msg=self.svcb.error_msg) if self.svcb.is_stop(): raise exceptions.SVInstanceException( message='The Service Insetance Has been Stopped:%s' % self.svcb.id) self.svcb.ready_to_suspend()
def resume(self): if self.svcb.is_error(): raise exceptions.SVInstanceErrorException( error_msg=self.svcb.error_msg) if self.svcb.is_stop(): raise exceptions.SVInstanceException( message='The Service Insetance Has been Stopped:%s' % self.svcb.id) if not self.svcb.is_suspend(): return self.svcb.suspend_to_ready()
def build_svinstance(self, sv_inst_id, user_id, sv_id, svtype=ServiceCtrlBlock.UNDAEM): if self.__svinstant_dict.has_key(sv_inst_id): raise exceptions.SVInstanceException( message='The Servcie Instance is Exist:%s' % sv_inst_id) self.__svinstant_dict[sv_inst_id] = SvInstance(sv_inst_id, user_id, sv_id, svtype)
def start(self): # if self.svcb.is_asy() and self.svcb.is_ready(): if self.svcb.is_error(): raise exceptions.SVInstanceErrorException( error_msg=self.svcb.error_msg) if self.svcb.is_stop(): raise exceptions.SVInstanceException( message='The Service Insetance Has been Stopped:%s' % self.svcb.id) if not self.svcb.is_builed(): raise exceptions.SVInstanceStateException( cur_state=self.svcb.state, need_state=ServiceCtrlBlock.BUILDED) super(SvInstance, self).start()
def close(self): if self.svcb.is_error(): raise exceptions.SVInstanceErrorException( error_msg=self.svcb.error_msg) if self.svcb.is_stop(): raise exceptions.SVInstanceException( message='The Service Insetance Has been Stopped:%s' % self.svcb.id) if self.svcb.is_ready() or self.svcb.is_running( ) or self.svcb.is_suspend(): self.__conn_queue.put((None, None)) self.__conn_queue.join() self.svcb.to_stop()
def __set_State(self, svstate): ''' 设置SVCB的状态,如果状态值不在STATES中,则抛出异常 如果状态不为ERROR,那么要清空ERROR_MSG ''' if svstate not in self.STATES: raise exceptions.SVInstanceException( message='Unkown Service Instance State:%s' % svstate) self[self.STATE] = svstate if svstate != self.ERROR: self[self.ERROR_MSG] = None else: self[self.ERROR_MSG] = 'Unknown Error'
def __set_SvID(self, sv_id): if not (isinstance(sv_id, str) or isinstance(sv_id, unicode)): raise exceptions.SVInstanceException( message='ErrorSV_IDTYPE:%s,user_id=%s' % (type(sv_id), sv_id)) self[self.SV_ID] = str(sv_id)
def __set_UserID(self, user_id): if not (isinstance(user_id, str) or isinstance(user_id, unicode)): raise exceptions.SVInstanceException( message='ErrorUser_IDTYPE:%s,user_id=%s' % (type(user_id), user_id)) self[self.USER_ID] = str(user_id)
def __set_ID(self, id): if not isinstance(id, str): raise exceptions.SVInstanceException( message='ErrorIDTYPE:%s,id=%s' % (type(id), id)) self[self.ID] = str(id)