sync

package
v0.1.12 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 4, 2021 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrAlreadyLocked = errors.New("already locked")

ErrAlreadyLocked is returned when the lock is already locked.

View Source
var (
	// ErrEmptyDocKeys is returned when the given keys is empty.
	ErrEmptyDocKeys = errors.New("empty doc keys")
)

Functions

This section is empty.

Types

type AgentInfo added in v0.1.5

type AgentInfo struct {
	ID        string      `json:"id"`
	Hostname  string      `json:"hostname"`
	RPCAddr   string      `json:"rpc_addr"`
	UpdatedAt gotime.Time `json:"updated_at"`
}

AgentInfo represents the information of the Agent.

type Coordinator added in v0.1.6

type Coordinator interface {
	// NewLocker creates a sync.Locker.
	NewLocker(ctx context.Context, key Key) (Locker, error)

	// Subscribe subscribes to the given documents.
	Subscribe(
		ctx context.Context,
		subscriber types.Client,
		docKeys []*key.Key,
	) (*Subscription, map[string][]types.Client, error)

	// Unsubscribe unsubscribes from the given documents.
	Unsubscribe(
		ctx context.Context,
		docKeys []*key.Key,
		sub *Subscription,
	) error

	// Publish publishes the given event.
	Publish(ctx context.Context, publisherID *time.ActorID, event DocEvent)

	// PublishToLocal publishes the given event.
	PublishToLocal(ctx context.Context, publisherID *time.ActorID, event DocEvent)

	// UpdateMetadata updates the metadata of the given client.
	UpdateMetadata(
		ctx context.Context,
		publisher *types.Client,
		keys []*key.Key,
	) (*DocEvent, error)

	// Members returns the members of this cluster.
	Members() map[string]*AgentInfo

	// Close closes all resources of this Coordinator.
	Close() error
}

Coordinator provides synchronization functions such as locks and event Pub/Sub.

type DocEvent added in v0.1.3

type DocEvent struct {
	Type         types.DocEventType
	Publisher    types.Client
	DocumentKeys []*key.Key
}

DocEvent represents events that occur related to the document.

type Key added in v0.1.3

type Key string

Key represents key of Locker.

func NewKey added in v0.1.3

func NewKey(key string) Key

NewKey creates a new instance of Key.

func (Key) String added in v0.1.3

func (k Key) String() string

String returns a string representation of this Key.

type Locker added in v0.1.3

type Locker interface {
	// Lock locks the mutex with a cancelable context
	Lock(ctx context.Context) error

	// TryLock locks the mutex if not already locked by another session.
	TryLock(ctx context.Context) error

	// Unlock unlocks the mutex.
	Unlock(ctx context.Context) error
}

A Locker represents an object that can be locked and unlocked.

type Subscription added in v0.1.3

type Subscription struct {
	// contains filtered or unexported fields
}

Subscription represents a subscription of a subscriber to documents.

func NewSubscription added in v0.1.3

func NewSubscription(subscriber types.Client) *Subscription

NewSubscription creates a new instance of Subscription.

func (*Subscription) Close added in v0.1.3

func (s *Subscription) Close()

Close closes all resources of this Subscription.

func (*Subscription) Events added in v0.1.3

func (s *Subscription) Events() chan DocEvent

Events returns the DocEvent channel of this subscription.

func (*Subscription) ID added in v0.1.3

func (s *Subscription) ID() string

ID returns the id of this subscription.

func (*Subscription) Subscriber added in v0.1.3

func (s *Subscription) Subscriber() types.Client

Subscriber returns the subscriber of this subscription.

func (*Subscription) SubscriberID added in v0.1.3

func (s *Subscription) SubscriberID() string

SubscriberID returns string representation of the subscriber.

func (*Subscription) UpdateMetadata added in v0.1.7

func (s *Subscription) UpdateMetadata(info types.MetadataInfo)

UpdateMetadata updates the metadata of the subscriber.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL