Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var AMemoryLocker = NewMemoryLocker()
Functions ¶
This section is empty.
Types ¶
type HttpLocker ¶
type HttpLocker struct {
// contains filtered or unexported fields
}
HttpLocker represents a locker that uses HTTP requests to interact with an Oracle service.
func NewHttpLocker ¶
func NewHttpLocker(oracleURL string) *HttpLocker
NewHttpLocker creates a new instance of HttpLocker with the specified oracleURL. The oracleURL parameter is the URL of the Oracle server used for locking.
func (*HttpLocker) Lock ¶
Lock locks the specified key with the given ID for the specified duration. It sends an HTTP GET request to the oracleURL with the key, ID, and duration as query parameters. If the lock request fails, it returns an error indicating the failure.
func (*HttpLocker) Unlock ¶
func (l *HttpLocker) Unlock(key string, id string) error
Unlock unlocks the specified key with the given ID using HTTP. It sends a GET request to the oracleURL with the key and ID as query parameters. If the request is successful, it returns nil. Otherwise, it returns an error.
type Locker ¶
type Locker interface { // Lock locks the specified resource with the given key and ID for the specified duration. // It returns an error if the resource cannot be locked. Lock(key string, id string, holdDuration time.Duration) error // Unlock unlocks the specified resource with the given key and ID. // It returns an error if the resource cannot be unlocked. Unlock(key string, id string) error }
Locker is an interface that defines the methods for locking and unlocking a resource.
type MemoryLocker ¶
type MemoryLocker struct {
// contains filtered or unexported fields
}
func NewMemoryLocker ¶
func NewMemoryLocker() *MemoryLocker
NewMemoryLocker creates a new instance of MemoryLocker. MemoryLocker is a type that provides a mechanism for locking and unlocking memory resources. It initializes the locks and timers maps and returns a pointer to the newly created MemoryLocker.
func (*MemoryLocker) Lock ¶
Lock locks the memory locker for the given key and ID for a specified duration. If the memory locker is already locked by someone else, the function will block until it is unlocked. Once locked, the memory locker will automatically unlock after the specified hold duration. If the lock is released before the hold duration expires, the timer will be stopped. After the hold duration expires, the lock will be released and the corresponding timer will be removed. The function is thread-safe.
func (*MemoryLocker) Unlock ¶
func (ml *MemoryLocker) Unlock(key string, id string) error
Unlock releases the lock for the given key and ID. If the ID does not match the one that holds the lock, an error is returned. It also stops the timer associated with the key, if any. After releasing the lock, it broadcasts a signal to wake up any goroutines waiting on the lock.