client

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2021 License: Apache-2.0 Imports: 14 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrClientNotActivated occurs when an inactive client executes a function
	// that can only be executed when activated.
	ErrClientNotActivated = errors.New("client is not activated")

	// ErrDocumentNotAttached occurs when the given document is not attached to
	// this client.
	ErrDocumentNotAttached = errors.New("document is not attached")
)

Functions

This section is empty.

Types

type Attachment added in v0.1.6

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

Attachment represents the document attached and peers.

type AuthInterceptor added in v0.1.5

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

AuthInterceptor is a interceptor for authentication.

func NewAuthInterceptor added in v0.1.5

func NewAuthInterceptor(token string) *AuthInterceptor

NewAuthInterceptor creates a new instance of AuthInterceptor.

func (*AuthInterceptor) Stream added in v0.1.5

Stream creates a stream server interceptor for authorization.

func (*AuthInterceptor) Unary added in v0.1.5

Unary creates a unary server interceptor for authorization.

type Client

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

Client is a normal client that can communicate with the agent. It has documents and sends changes of the document in local to the agent to synchronize with other replicas in remote.

func Dial added in v0.1.2

func Dial(rpcAddr string, opts ...Option) (*Client, error)

Dial creates an instance of Client and dials the given rpcAddr.

func NewClient

func NewClient(opts ...Option) (*Client, error)

NewClient creates an instance of Client.

func (*Client) Activate

func (c *Client) Activate(ctx context.Context) error

Activate activates this client. That is, it register itself to the agent and receives a unique ID from the agent. The given ID is used to distinguish different clients.

func (*Client) Attach

func (c *Client) Attach(ctx context.Context, doc *document.Document) error

Attach attaches the given document to this client. It tells the agent that this client will synchronize the given document.

func (*Client) Close

func (c *Client) Close() error

Close closes all resources of this client.

func (*Client) Deactivate

func (c *Client) Deactivate(ctx context.Context) error

Deactivate deactivates this client.

func (*Client) Detach

func (c *Client) Detach(ctx context.Context, doc *document.Document) error

Detach detaches the given document from this client. It tells the agent that this client will no longer synchronize the given document.

To collect garbage things like CRDT tombstones left on the document, all the changes should be applied to other replicas before GC time. For this, if the document is no longer used by this client, it should be detached.

func (*Client) Dial added in v0.1.2

func (c *Client) Dial(rpcAddr string) error

Dial dials the given rpcAddr.

func (*Client) ID added in v0.1.6

func (c *Client) ID() *time.ActorID

ID returns the ID of this client.

func (*Client) IsActive

func (c *Client) IsActive() bool

IsActive returns whether this client is active or not.

func (*Client) Key added in v0.1.6

func (c *Client) Key() string

Key returns the key of this client.

func (*Client) Metadata added in v0.1.2

func (c *Client) Metadata() Metadata

Metadata returns the metadata of this client.

func (*Client) PeersMapByDoc added in v0.1.6

func (c *Client) PeersMapByDoc() map[string]map[string]Metadata

PeersMapByDoc returns the peersMap.

func (*Client) Sync

func (c *Client) Sync(ctx context.Context, keys ...*key.Key) error

Sync pushes local changes of the attached documents to the Agent and receives changes of the remote replica from the agent then apply them to local documents.

func (*Client) Watch

func (c *Client) Watch(
	ctx context.Context,
	docs ...*document.Document,
) (<-chan WatchResponse, error)

Watch subscribes to events on a given document. If an error occurs before stream initialization, the second response, error, is returned. If the context "ctx" is canceled or timed out, returned channel is closed, and "WatchResponse" from this closed channel has zero events and nil "Err()".

type Metadata added in v0.1.6

type Metadata map[string]string

Metadata represents custom metadata that can be defined in the client.

type Option

type Option struct {
	Key      string
	Metadata Metadata
	Token    string

	CertFile           string
	ServerNameOverride string
}

Option configures how we set up the client.

type WatchResponse

type WatchResponse struct {
	Type          WatchResponseType
	Keys          []*key.Key
	PeersMapByDoc map[string]map[string]Metadata
	Err           error
}

WatchResponse is a structure representing response of Watch.

type WatchResponseType added in v0.1.6

type WatchResponseType string

WatchResponseType is type of watch response.

const (
	DocumentsChanged WatchResponseType = "documents-changed"
	PeersChanged     WatchResponseType = "peers-changed"
)

The values below are types of WatchResponseType.

Jump to

Keyboard shortcuts

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