|
@@ -4,7 +4,6 @@ import (
|
|
"github.com/gogf/gf/container/gqueue"
|
|
"github.com/gogf/gf/container/gqueue"
|
|
"sparrow/pkg/protocol"
|
|
"sparrow/pkg/protocol"
|
|
"sparrow/pkg/server"
|
|
"sparrow/pkg/server"
|
|
- "sync"
|
|
|
|
"sync/atomic"
|
|
"sync/atomic"
|
|
)
|
|
)
|
|
|
|
|
|
@@ -19,8 +18,6 @@ type MailBox struct {
|
|
busyState int32
|
|
busyState int32
|
|
readySate int32
|
|
readySate int32
|
|
throughPut int // 处理的吞吐量
|
|
throughPut int // 处理的吞吐量
|
|
- closed bool
|
|
|
|
- mu sync.Mutex
|
|
|
|
}
|
|
}
|
|
|
|
|
|
const (
|
|
const (
|
|
@@ -69,15 +66,13 @@ func (m *MailBox) setBusyStat(stat int32) {
|
|
}
|
|
}
|
|
|
|
|
|
func (m *MailBox) tryInit(attempt int) {
|
|
func (m *MailBox) tryInit(attempt int) {
|
|
- server.Log.Errorf("Try to init actor, attempt %d", attempt)
|
|
|
|
|
|
+ server.Log.Debugf("Try to init actor, attempt %d", attempt)
|
|
err := m.actor.Init(m)
|
|
err := m.actor.Init(m)
|
|
if err != nil {
|
|
if err != nil {
|
|
server.Log.Errorf("failed to init actor, err :%s, attempt %d", err.Error(), attempt)
|
|
server.Log.Errorf("failed to init actor, err :%s, attempt %d", err.Error(), attempt)
|
|
attempt += 1
|
|
attempt += 1
|
|
if attempt > 10 {
|
|
if attempt > 10 {
|
|
_ = m.system.StopActorById(m.id)
|
|
_ = m.system.StopActorById(m.id)
|
|
- server.Log.Errorf("StopActorById:%s", m.id)
|
|
|
|
- return
|
|
|
|
}
|
|
}
|
|
_ = m.dispatcher.Submit(func() {
|
|
_ = m.dispatcher.Submit(func() {
|
|
m.tryInit(attempt)
|
|
m.tryInit(attempt)
|
|
@@ -170,9 +165,6 @@ func (m *MailBox) Tell(msg protocol.ActorMsg) {
|
|
|
|
|
|
// push a message to queue
|
|
// push a message to queue
|
|
func (m *MailBox) enqueue(msg protocol.ActorMsg, isHighPriority bool) {
|
|
func (m *MailBox) enqueue(msg protocol.ActorMsg, isHighPriority bool) {
|
|
- if m.getBusyStat() != READY {
|
|
|
|
- return
|
|
|
|
- }
|
|
|
|
if isHighPriority {
|
|
if isHighPriority {
|
|
m.highPriorityMessages.Push(msg)
|
|
m.highPriorityMessages.Push(msg)
|
|
} else {
|
|
} else {
|
|
@@ -214,12 +206,12 @@ func (m *MailBox) BroadcastChildren(msg protocol.ActorMsg) error {
|
|
}
|
|
}
|
|
|
|
|
|
func (m *MailBox) destroy() error {
|
|
func (m *MailBox) destroy() error {
|
|
- server.Log.Debugf("Destroying mailbox:%s", m.id)
|
|
|
|
- m.highPriorityMessages.Close()
|
|
|
|
- m.normalPriorityMessages.Close()
|
|
|
|
- m.setReadyStat(NOTREADY)
|
|
|
|
- if err := m.actor.Destroy(); err != nil {
|
|
|
|
- server.Log.Warnf("Failed to destroy actor :%s, err :%s", m.id, err.Error())
|
|
|
|
- }
|
|
|
|
- return nil
|
|
|
|
|
|
+ return m.dispatcher.Submit(func() {
|
|
|
|
+ m.highPriorityMessages.Close()
|
|
|
|
+ m.normalPriorityMessages.Close()
|
|
|
|
+ m.setReadyStat(NOTREADY)
|
|
|
|
+ if err := m.actor.Destroy(); err != nil {
|
|
|
|
+ server.Log.Warnf("Failed to destroy actor :%s, err :%s", m.id, err.Error())
|
|
|
|
+ }
|
|
|
|
+ })
|
|
}
|
|
}
|