func ProcRecordResult( handler *coreprocessing.Handler, inIns *coreprocessing.CoreInstruction, outIns *coreprocessing.CoreInstruction) []*coreprocessing.CoreInstruction { // var result []*coreprocessing.CoreInstruction if answer, _ := outIns.GetAnswer(); (*answer).Error.Code == 0 { if srcCmd, hasCmd := inIns.GetCommand(); hasCmd { rpcManager := coreprocessing.NewRpcServerManager() taskId := (*srcCmd).Params.Task if targetCidPtr := rpcManager.ResultDirectionDict.Get(taskId); targetCidPtr != nil { // check client group if handler.StateCheker.ClientInGroup(*targetCidPtr, connectionsupport.GroupConnectionWsClient) { cmd := transport.NewCommandWithParams( 0, "result", transport.MethodParams{ Cid: *targetCidPtr, Task: taskId, Json: (*srcCmd).Params.Json}) clientIns := coreprocessing.NewCoreInstruction(coreprocessing.TypeInstructionSetResult) clientIns.SetCommand(cmd) result = make([]*coreprocessing.CoreInstruction, 1) result[0] = clientIns } else { rpcManager.ResultBufferDict.Set(taskId, (*srcCmd).Params.Json) } } else { rllogger.Outputf(rllogger.LogError, "Processing pass for: %s", srcCmd) } } } return result }
func ProcCallServerMethod( handler *coreprocessing.Handler, inIns *coreprocessing.CoreInstruction, outIns *coreprocessing.CoreInstruction) []*coreprocessing.CoreInstruction { // var result []*coreprocessing.CoreInstruction if answer, exists := outIns.GetAnswer(); exists { if (*answer).Error.Code == 0 { if srcCmd, hasCmd := inIns.GetCommand(); hasCmd { rpcData := RpcAnswerData{} // little overhead - parse JSON if loadErr := json.Unmarshal([]byte((*answer).Result), &rpcData); loadErr == nil { srcParams := (*srcCmd).Params srcParams.Task = rpcData.Task // replace cid srcParams.Cid = rpcData.Cid newCmd := transport.NewCommandWithParams(0, (*srcCmd).Method, srcParams) resultIns := coreprocessing.NewCoreInstruction(coreprocessing.TypeInstructionExecute) resultIns.SetCommand(newCmd) result = []*coreprocessing.CoreInstruction{resultIns} } else { rllogger.Outputf( rllogger.LogError, "Answer from ProcRouteRpc has incorrect data format, from: %s", inIns.Cid) } } else { rllogger.Outputf(rllogger.LogError, "Answer lost in ProcRouteRpc! from: %s", inIns.Cid) } } } else { rllogger.Outputf(rllogger.LogError, "Answer lost in ProcRouteRpc! from: %s", inIns.Cid) } return result }
// answer worker func connectionWriteProcessing( connection net.Conn, backChannel *chan coreprocessing.CoreInstruction, dataManager *connectionsupport.ConnectionDataManager, stat statistic.StatisticUpdater, label string) { // wait := true msgSize := 0 var newInstruction coreprocessing.CoreInstruction var statGroupName string for wait { newInstruction = <-*backChannel if newInstruction.IsEmpty() { rllogger.Outputf(rllogger.LogWarn, "Closed write process for %s empty instruction!", label) wait = false } else { // write msgSize = 0 if answer, exists := newInstruction.GetAnswer(); exists { data := answer.DataDump() if data != nil { line := append(*data, byte('\n')) if writen, err := connection.Write(line); err == nil { msgSize += writen } else { rllogger.Outputf(rllogger.LogWarn, "Can't wite answer to %s: %s", label, err) stat.AddOneMsg("lost_connection_count") // wtf ? wait = false } } } // and / or command for client if answerCmd, exists := newInstruction.GetCommand(); exists && wait { data := answerCmd.DataDump() if data != nil { line := append(*data, byte('\n')) if writen, err := connection.Write(line); err == nil { msgSize += writen } else { rllogger.Outputf(rllogger.LogWarn, "Can't wite answer to %s: %s", label, err) stat.AddOneMsg("lost_connection_count") // wtf ? wait = false } } } if msgSize > 0 { stat.SendMsg("outcome_data_size", msgSize) // update state data if newInstruction.StateChanges != nil { // so simple.. without some visitor for statistic if newInstruction.StateChanges.ChangeType == connectionsupport.StateChangesTypeGroup { switch newInstruction.StateChanges.ConnectionClientGroup { case connectionsupport.GroupConnectionClient: statGroupName = "count_connection_client" case connectionsupport.GroupConnectionServer: statGroupName = "count_connection_server" case connectionsupport.GroupConnectionWsClient: statGroupName = "count_connection_web" } stat.AddOneMsg(statGroupName) } // update data in manager dataManager.UpdateState(newInstruction.Cid, newInstruction.StateChanges) } } else { rllogger.Outputf(rllogger.LogWarn, "Empty answer to %s?", label) } if newInstruction.NeedExit() { wait = false rllogger.Outputf(rllogger.LogDebug, "Closed write process for %s from instruction.", label) err := connection.Close() if err != nil { // wait = true ?? rllogger.Outputf(rllogger.LogError, "Close connection %s problem: %s", label, err) } } } } stat.DelOneMsg(statGroupName) close(*backChannel) }