mirror of https://github.com/v2ray/v2ray-core
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
71 lines
1.1 KiB
71 lines
1.1 KiB
package core
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"v2ray.com/core/features/stats"
|
|
)
|
|
|
|
type syncStatManager struct {
|
|
sync.RWMutex
|
|
stats.Manager
|
|
}
|
|
|
|
func (*syncStatManager) Type() interface{} {
|
|
return stats.ManagerType()
|
|
}
|
|
|
|
func (s *syncStatManager) Start() error {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
if s.Manager == nil {
|
|
return nil
|
|
}
|
|
|
|
return s.Manager.Start()
|
|
}
|
|
|
|
func (s *syncStatManager) Close() error {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
if s.Manager == nil {
|
|
return nil
|
|
}
|
|
return s.Manager.Close()
|
|
}
|
|
|
|
func (s *syncStatManager) RegisterCounter(name string) (stats.Counter, error) {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
if s.Manager == nil {
|
|
return nil, newError("StatManager not set.")
|
|
}
|
|
return s.Manager.RegisterCounter(name)
|
|
}
|
|
|
|
func (s *syncStatManager) GetCounter(name string) stats.Counter {
|
|
s.RLock()
|
|
defer s.RUnlock()
|
|
|
|
if s.Manager == nil {
|
|
return nil
|
|
}
|
|
return s.Manager.GetCounter(name)
|
|
}
|
|
|
|
func (s *syncStatManager) Set(m stats.Manager) {
|
|
if m == nil {
|
|
return
|
|
}
|
|
s.Lock()
|
|
defer s.Unlock()
|
|
|
|
if s.Manager != nil {
|
|
s.Manager.Close() // nolint: errcheck
|
|
}
|
|
s.Manager = m
|
|
}
|