2018-10-11 19:14:53 +00:00
|
|
|
package stats
|
|
|
|
|
|
|
|
import "v2ray.com/core/features"
|
|
|
|
|
|
|
|
type Counter interface {
|
|
|
|
Value() int64
|
|
|
|
Set(int64) int64
|
|
|
|
Add(int64) int64
|
|
|
|
}
|
|
|
|
|
|
|
|
type Manager interface {
|
|
|
|
features.Feature
|
|
|
|
|
|
|
|
RegisterCounter(string) (Counter, error)
|
|
|
|
GetCounter(string) Counter
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetOrRegisterCounter tries to get the StatCounter first. If not exist, it then tries to create a new counter.
|
|
|
|
func GetOrRegisterCounter(m Manager, name string) (Counter, error) {
|
|
|
|
counter := m.GetCounter(name)
|
|
|
|
if counter != nil {
|
|
|
|
return counter, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return m.RegisterCounter(name)
|
|
|
|
}
|
2018-10-12 21:57:56 +00:00
|
|
|
|
2018-10-13 13:15:49 +00:00
|
|
|
// ManagerType returns the type of Manager interface. Can be used to implement common.HasType.
|
2018-10-12 21:57:56 +00:00
|
|
|
func ManagerType() interface{} {
|
|
|
|
return (*Manager)(nil)
|
|
|
|
}
|