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.
v2ray-core/features/stats/stats.go

71 lines
1.9 KiB

package stats
//go:generate errorgen
import "v2ray.com/core/features"
6 years ago
// Counter is the interface for stats counters.
6 years ago
//
// v2ray:api:stable
type Counter interface {
6 years ago
// Value is the current value of the counter.
Value() int64
6 years ago
// Set sets a new value to the counter, and returns the previous one.
Set(int64) int64
6 years ago
// Add adds a value to the current counter value, and returns the previous value.
Add(int64) int64
}
6 years ago
// Manager is the interface for stats manager.
6 years ago
//
// v2ray:api:stable
type Manager interface {
features.Feature
6 years ago
// RegisterCounter registers a new counter to the manager. The identifier string must not be emtpy, and unique among other counters.
RegisterCounter(string) (Counter, error)
6 years ago
// GetCounter returns a counter by its identifier.
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)
}
// ManagerType returns the type of Manager interface. Can be used to implement common.HasType.
6 years ago
//
// v2ray:api:stable
func ManagerType() interface{} {
return (*Manager)(nil)
}
// NoopManager is an implementation of Manager, which doesn't has actual functionalities.
type NoopManager struct{}
// Type implements common.HasType.
func (NoopManager) Type() interface{} {
return ManagerType()
}
// RegisterCounter implements Manager.
func (NoopManager) RegisterCounter(string) (Counter, error) {
return nil, newError("not implemented")
}
// GetCounter implements Manager.
func (NoopManager) GetCounter(string) Counter {
return nil
}
// Start implements common.Runnable.
func (NoopManager) Start() error { return nil }
// Close implements common.Closable.
func (NoopManager) Close() error { return nil }