예제 #1
0
 def sendDataMsgFromThreadAsync(msg):
     if Web.wsDataConn is None:
         raise StateError("ProjectInterface: FileServer not connected. Please run the fileServer.")
     callId = msg.get('callId')
     if not callId:
         callbackStruct = StructDict()
         callbackStruct.dataConn = Web.wsDataConn
         callbackStruct.numResponses = 0
         callbackStruct.responses = []
         callbackStruct.semaphore = threading.Semaphore(value=0)
         callbackStruct.timeStamp = time.time()
         callbackStruct.msg = msg.copy()
         if 'data' in callbackStruct.msg:
             del callbackStruct.msg['data']
         Web.callbackLock.acquire()
         try:
             Web.dataSequenceNum += 1
             callId = Web.dataSequenceNum
             callbackStruct.callId = callId
             msg['callId'] = callId
             Web.dataCallbacks[callId] = callbackStruct
         finally:
             Web.callbackLock.release()
         Web.ioLoopInst.add_callback(Web.sendDataMessage, msg)
     return callId
예제 #2
0
 def prepare_request(self, msg):
     """Prepate a request to be sent, including creating a callback structure and unique ID."""
     # Get data server connection the request will be sent on
     websocketState.wsConnLock.acquire()
     try:
         wsConnections = websocketState.wsConnectionLists.get(self.name)
         if wsConnections is None or len(wsConnections) == 0:
             serviceName = 'DataService'
             if self.name == 'wsSubject':
                 serviceName = 'SubjectService'
             raise StateError(
                 f"RemoteService: {serviceName} not connected. Please start the remote service."
             )
         reqConn = wsConnections[-1]  # always use most recent connection
     finally:
         websocketState.wsConnLock.release()
     callId = msg.get('callId')
     if not callId:
         callbackStruct = StructDict()
         callbackStruct.dataConn = reqConn
         callbackStruct.numResponses = 0
         callbackStruct.responses = []
         callbackStruct.semaphore = threading.Semaphore(value=0)
         callbackStruct.timeStamp = time.time()
         callbackStruct.msg = msg.copy()
         if 'data' in callbackStruct.msg:
             del callbackStruct.msg['data']
         self.callbackLock.acquire()
         try:
             self.dataSequenceNum += 1
             callId = self.dataSequenceNum
             callbackStruct.callId = callId
             msg['callId'] = callId
             self.dataCallbacks[callId] = callbackStruct
         finally:
             self.callbackLock.release()
         # self.ioLoopInst.add_callback(Web.sendDataMessage, msg)
     return callId, reqConn