Documentation ¶
Index ¶
- Variables
- func AppendBytes(inputs ...[]byte) []byte
- func CopyBytes(src []byte) []byte
- func CopyStruct(dst interface{}, src interface{}) (err error)
- func Crc32(crc uint32, value []byte, skiplen int) uint32
- func DecodeInt32(buffer []byte, offset int, ret *int32)
- func DecodeUint16(buffer []byte, offset int, ret *uint16)
- func DecodeUint32(buffer []byte, offset int, ret *uint32)
- func DecodeUint64(buffer []byte, offset int, ret *uint64)
- func DeleteDir(path string) error
- func EncodeInt32(buffer []byte, offset int, ret int32)
- func EncodeUint16(buffer []byte, offset int, ret uint16)
- func EncodeUint32(buffer []byte, offset int, ret uint32)
- func EncodeUint64(buffer []byte, offset int, ret uint64)
- func Forever(f func(), period time.Duration)
- func GetCaller() string
- func HandleCrash(additionalHandlers ...func(interface{}))
- func HandleError(err error)
- func Inet_addr(ipaddr string) uint32
- func IsDirectoryExist(path string) bool
- func IterDir(dirPath string, filePathList []string) error
- func Jitter(duration time.Duration, maxFactor float64) time.Duration
- func JitterUntil(f func(), period time.Duration, jitterFactor float64, sliding bool, ...)
- func NonSlidingUntil(f func(), period time.Duration, stopCh <-chan struct{})
- func NowTimeMs() uint64
- func Rand() int32
- func RecoverFromPanic(err *error)
- func SleepMs(ms int32)
- func StartRoutine(f func())
- func TestAssert(tb testing.TB, condition bool, msg string, v ...interface{})
- func Until(f func(), period time.Duration, stopCh <-chan struct{})
- type Deque
- func (s *Deque) Append(item interface{}) bool
- func (s *Deque) Capacity() int
- func (s *Deque) Empty() bool
- func (s *Deque) First() interface{}
- func (s *Deque) Full() bool
- func (s *Deque) Last() interface{}
- func (s *Deque) Pop() interface{}
- func (s *Deque) Prepend(item interface{}) bool
- func (s *Deque) Shift() interface{}
- func (s *Deque) Size() int
- type Queue
- func (self *Queue) Add(value interface{}) int
- func (self *Queue) Broadcast()
- func (self *Queue) Empty() bool
- func (self *Queue) Lock()
- func (self *Queue) Peek() interface{}
- func (self *Queue) PeekWithTimeout(ms int) interface{}
- func (self *Queue) Pop()
- func (self *Queue) Signal()
- func (self *Queue) Size() int
- func (self *Queue) Unlock()
- type TimeStat
- type TimeoutCond
- type Timer
- type TimerObj
- type TimerThread
- type Waitlock
Constants ¶
This section is empty.
Variables ¶
var ErrorHandlers = []func(error){ logError, (&rudimentaryErrorBackoff{ lastErrorTime: time.Now(), minPeriod: time.Millisecond, }).OnError, }
ErrorHandlers is a list of functions which will be invoked when an unreturnable error occurs. TODO(lavalamp): for testability, this and the below HandleError function should be packaged up into a testable and reusable object.
var INT32SIZE int = binary.Size(int32(0))
var INT64SIZE int = binary.Size(int64(0))
var NeverStop <-chan struct{} = make(chan struct{})
NeverStop may be passed to Until to make it never stop.
var PanicHandlers = []func(interface{}){logPanic}
PanicHandlers is a list of functions which will be invoked when a panic happens.
var ( // ReallyCrash controls the behavior of HandleCrash and now defaults // true. It's still exposed so components can optionally set to false // to restore prior behavior. ReallyCrash = true )
var UINT16SIZE int = binary.Size(uint16(0))
var UINT32SIZE int = binary.Size(uint32(0))
var UINT64SIZE int = binary.Size(uint64(0))
var Waitlock_Timeout = errors.New("waitlock timeout")
Functions ¶
func AppendBytes ¶
func CopyStruct ¶
func CopyStruct(dst interface{}, src interface{}) (err error)
dst should be a pointer to struct, src should be a struct
func DecodeInt32 ¶
func DecodeUint16 ¶
func DecodeUint32 ¶
func DecodeUint64 ¶
func EncodeInt32 ¶
func EncodeUint16 ¶
func EncodeUint32 ¶
func EncodeUint64 ¶
func GetCaller ¶
func GetCaller() string
GetCaller returns the caller of the function that calls it.
func HandleCrash ¶
func HandleCrash(additionalHandlers ...func(interface{}))
HandleCrash simply catches a crash and logs an error. Meant to be called via defer. Additional context-specific handlers can be provided, and will be called in case of panic. HandleCrash actually crashes, after calling the handlers and logging the panic message.
TODO: remove this function. We are switching to a world where it's safe for apiserver to panic, since it will be restarted by kubelet. At the beginning of the Kubernetes project, nothing was going to restart apiserver and so catching panics was important. But it's actually much simpler for montoring software if we just exit when an unexpected panic happens.
func HandleError ¶
func HandleError(err error)
HandlerError is a method to invoke when a non-user facing piece of code cannot return an error and needs to indicate it has been ignored. Invoking this method is preferable to logging the error - the default behavior is to log but the errors may be sent to a remote server for analysis.
func IsDirectoryExist ¶
func Jitter ¶
Jitter returns a time.Duration between duration and duration + maxFactor * duration.
This allows clients to avoid converging on periodic behavior. If maxFactor is 0.0, a suggested default value will be chosen.
func JitterUntil ¶
func JitterUntil(f func(), period time.Duration, jitterFactor float64, sliding bool, stopCh <-chan struct{})
JitterUntil loops until stop channel is closed, running f every period.
If jitterFactor is positive, the period is jittered before every run of f. If jitterFactor is not positive, the period is unchanged and not jittered.
If sliding is true, the period is computed after f runs. If it is false then period includes the runtime for f.
Close stopCh to stop. f may not be invoked if stop channel is already closed. Pass NeverStop to if you don't want it stop.
func NonSlidingUntil ¶
NonSlidingUntil loops until stop channel is closed, running f every period.
NonSlidingUntil is syntactic sugar on top of JitterUntil with zero jitter factor, with sliding = false (meaning the timer for period starts at the same time as the function starts).
func RecoverFromPanic ¶
func RecoverFromPanic(err *error)
RecoverFromPanic replaces the specified error with an error containing the original error, and the call tree when a panic occurs. This enables error handlers to handle errors and panics the same way.
func StartRoutine ¶
func StartRoutine(f func())
func TestAssert ¶
assert fails the test if the condition is false.
Types ¶
type Deque ¶
Deque is a head-tail linked list data structure implementation. It is based on a doubly linked list container, so that every operations time complexity is O(1).
every operations over an instiated Deque are synchronized and safe for concurrent usage.
func NewCappedDeque ¶
NewCappedDeque creates a Deque with the specified capacity limit.
func (*Deque) Append ¶
Append inserts element at the back of the Deque in a O(1) time complexity, returning true if successful or false if the deque is at capacity.
func (*Deque) First ¶
func (s *Deque) First() interface{}
First returns the first value stored in the deque in a O(1) time complexity
func (*Deque) Last ¶
func (s *Deque) Last() interface{}
Last returns the last value stored in the deque in a O(1) time complexity
func (*Deque) Pop ¶
func (s *Deque) Pop() interface{}
Pop removes the last element of the deque in a O(1) time complexity
func (*Deque) Prepend ¶
Prepend inserts element at the Deques front in a O(1) time complexity, returning true if successful or false if the deque is at capacity.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
func (*Queue) PeekWithTimeout ¶
type TimeStat ¶
type TimeStat struct {
Time uint64
}
func NewTimeStat ¶
func NewTimeStat() *TimeStat
type TimeoutCond ¶
type TimeoutCond struct {
// contains filtered or unexported fields
}
func NewTimeoutCond ¶
func NewTimeoutCond(l sync.Locker) *TimeoutCond
func (*TimeoutCond) Broadcast ¶
func (t *TimeoutCond) Broadcast()
func (*TimeoutCond) Lock ¶
func (t *TimeoutCond) Lock()
func (*TimeoutCond) Signal ¶
func (t *TimeoutCond) Signal()
func (*TimeoutCond) Unlock ¶
func (t *TimeoutCond) Unlock()
func (*TimeoutCond) Wait ¶
func (t *TimeoutCond) Wait()
func (*TimeoutCond) WaitFor ¶
func (t *TimeoutCond) WaitFor(ms int) bool
false if timeout, else return true
type TimerThread ¶
type TimerThread struct {
// contains filtered or unexported fields
}
func NewTimerThread ¶
func NewTimerThread() *TimerThread
func (*TimerThread) AddTimer ¶
func (self *TimerThread) AddTimer(timeoutMs uint32, timeType int, obj TimerObj) uint32
func (*TimerThread) DelTimer ¶
func (self *TimerThread) DelTimer(timerId uint32)
func (*TimerThread) Stop ¶
func (self *TimerThread) Stop()