MCPcopy
hub / github.com/lonng/nano / localProcess

Method localProcess

cluster/handler.go:440–508  ·  view source on GitHub ↗
(handler *component.Handler, lastMid uint64, session *session.Session, msg *message.Message)

Source from the content-addressed store, hash-verified

438}
439
440func (h *LocalHandler) localProcess(handler *component.Handler, lastMid uint64, session *session.Session, msg *message.Message) {
441 if pipe := h.pipeline; pipe != nil {
442 err := pipe.Inbound().Process(session, msg)
443 if err != nil {
444 log.Println("Pipeline process failed: " + err.Error())
445 return
446 }
447 }
448
449 var payload = msg.Data
450 var data interface{}
451 if handler.IsRawArg {
452 data = payload
453 } else {
454 data = reflect.New(handler.Type.Elem()).Interface()
455 err := env.Serializer.Unmarshal(payload, data)
456 if err != nil {
457 log.Println(fmt.Sprintf("Deserialize to %T failed: %+v (%v)", data, err, payload))
458 return
459 }
460 }
461
462 if env.Debug {
463 log.Println(fmt.Sprintf("UID=%d, Message={%s}, Data=%+v", session.UID(), msg.String(), data))
464 }
465
466 args := []reflect.Value{handler.Receiver, reflect.ValueOf(session), reflect.ValueOf(data)}
467 task := func() {
468 switch v := session.NetworkEntity().(type) {
469 case *agent:
470 v.lastMid = lastMid
471 case *acceptor:
472 v.lastMid = lastMid
473 }
474
475 result := handler.Method.Func.Call(args)
476 if len(result) > 0 {
477 if err := result[0].Interface(); err != nil {
478 log.Println(fmt.Sprintf("Service %s error: %+v", msg.Route, err))
479 }
480 }
481 }
482
483 index := strings.LastIndex(msg.Route, ".")
484 if index < 0 {
485 log.Println(fmt.Sprintf("nano/handler: invalid route %s", msg.Route))
486 return
487 }
488
489 // A message can be dispatch to global thread or a user customized thread
490 service := msg.Route[:index]
491 if s, found := h.localServices[service]; found && s.SchedName != "" {
492 sched := session.Value(s.SchedName)
493 if sched == nil {
494 log.Println(fmt.Sprintf("nanl/handler: cannot found `schedular.LocalScheduler` by %s", s.SchedName))
495 return
496 }
497

Callers 3

processMessageMethod · 0.95
HandleRequestMethod · 0.80
HandleNotifyMethod · 0.80

Calls 10

NetworkEntityInterface · 0.92
PushTaskFunction · 0.92
PrintlnMethod · 0.80
UIDMethod · 0.80
ValueMethod · 0.80
ScheduleMethod · 0.80
ProcessMethod · 0.65
InboundMethod · 0.65
UnmarshalMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected