mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-13 07:04:44 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d1935b1bbc | ||
|
|
90d54bf3e2 |
@@ -8,6 +8,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"github.com/duanhf2012/origin/v2/event"
|
"github.com/duanhf2012/origin/v2/event"
|
||||||
|
"errors"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
var configDir = "./config/"
|
var configDir = "./config/"
|
||||||
@@ -433,6 +435,25 @@ func (cls *Cluster) GetGlobalCfg() interface{} {
|
|||||||
return cls.globalCfg
|
return cls.globalCfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (cls *Cluster) ParseGlobalCfg(cfg interface{}) error{
|
||||||
|
if cls.globalCfg == nil {
|
||||||
|
return errors.New("no service configuration found")
|
||||||
|
}
|
||||||
|
|
||||||
|
rv := reflect.ValueOf(cls.globalCfg)
|
||||||
|
if rv.Kind() == reflect.Ptr && rv.IsNil() {
|
||||||
|
return errors.New("no service configuration found")
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes,err := json.Marshal(cls.globalCfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Unmarshal(bytes,cfg)
|
||||||
|
}
|
||||||
|
|
||||||
func (cls *Cluster) GetNodeInfo(nodeId string) (NodeInfo,bool) {
|
func (cls *Cluster) GetNodeInfo(nodeId string) (NodeInfo,bool) {
|
||||||
cls.locker.RLock()
|
cls.locker.RLock()
|
||||||
defer cls.locker.RUnlock()
|
defer cls.locker.RUnlock()
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"github.com/duanhf2012/origin/v2/concurrent"
|
"github.com/duanhf2012/origin/v2/concurrent"
|
||||||
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
var timerDispatcherLen = 100000
|
var timerDispatcherLen = 100000
|
||||||
@@ -295,6 +296,24 @@ func (s *Service) GetServiceCfg()interface{}{
|
|||||||
return s.serviceCfg
|
return s.serviceCfg
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *Service) ParseServiceCfg(cfg interface{}) error{
|
||||||
|
if s.serviceCfg == nil {
|
||||||
|
return errors.New("no service configuration found")
|
||||||
|
}
|
||||||
|
|
||||||
|
rv := reflect.ValueOf(s.serviceCfg)
|
||||||
|
if rv.Kind() == reflect.Ptr && rv.IsNil() {
|
||||||
|
return errors.New("no service configuration found")
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes,err := json.Marshal(s.serviceCfg)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return json.Unmarshal(bytes,cfg)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *Service) GetProfiler() *profiler.Profiler{
|
func (s *Service) GetProfiler() *profiler.Profiler{
|
||||||
return s.profiler
|
return s.profiler
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ func Init() {
|
|||||||
for _,s := range setupServiceList {
|
for _,s := range setupServiceList {
|
||||||
err := s.OnInit()
|
err := s.OnInit()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.SError("Failed to initialize "+s.GetName()+" service:"+err.Error())
|
log.Error("Failed to initialize "+s.GetName()+" service",log.ErrorAttr("err",err))
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ func (slf *WSClient) Run() {
|
|||||||
for{
|
for{
|
||||||
bytes,err := slf.wsConn.ReadMsg()
|
bytes,err := slf.wsConn.ReadMsg()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debug("read client id %d is error:%+v",slf.id,err)
|
log.Debug("read client id %s is error:%+v",slf.id,err)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
data,err:=slf.wsService.process.Unmarshal(slf.id,bytes)
|
data,err:=slf.wsService.process.Unmarshal(slf.id,bytes)
|
||||||
@@ -153,7 +153,7 @@ func (ws *WSService) SendMsg(clientid string,msg interface{}) error{
|
|||||||
client,ok := ws.mapClient[clientid]
|
client,ok := ws.mapClient[clientid]
|
||||||
if ok == false{
|
if ok == false{
|
||||||
ws.mapClientLocker.Unlock()
|
ws.mapClientLocker.Unlock()
|
||||||
return fmt.Errorf("client %d is disconnect!",clientid)
|
return fmt.Errorf("client %s is disconnect!",clientid)
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.mapClientLocker.Unlock()
|
ws.mapClientLocker.Unlock()
|
||||||
|
|||||||
Reference in New Issue
Block a user