binder

package
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2016 License: MIT Imports: 8 Imported by: 6

Documentation

Overview

Package binder - Defines the binder type, used for managing multiple clients of a single document, ensuring that operational transforms received are ordered and dispatched across all other clients. Also manages message broadcasting and session management for all client connections, as well as periodic flushing of changes to a document storage solution.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrReadOnlyPortal = errors.New("attempting to send transforms through a READ ONLY portal")
)

Errors for the binder portal type.

View Source
var (
	ErrTimeout = errors.New("timed out")
)

Errors used throughout the package.

Functions

This section is empty.

Types

type ClientInfo

type ClientInfo struct {
	UserID    string `json:"user_id"`
	SessionID string `json:"session_id"`
}

ClientInfo - Contains user session credentials (user id and session id).

type ClientUpdate

type ClientUpdate struct {
	ClientInfo ClientInfo `json:"client"`
	Message    Message    `json:"message"`
}

ClientUpdate - A struct broadcast to all clients containing an update/message.

type Config

type Config struct {
	FlushPeriod           int64               `json:"flush_period_ms" yaml:"flush_period_ms"`
	RetentionPeriod       int64               `json:"retention_period_s" yaml:"retention_period_s"`
	ClientKickPeriod      int64               `json:"kick_period_ms" yaml:"kick_period_ms"`
	CloseInactivityPeriod int64               `json:"close_inactivity_period_s" yaml:"close_inactivity_period_s"`
	OTBufferConfig        text.OTBufferConfig `json:"transform_buffer" yaml:"transform_buffer"`
}

Config - Holds configuration options for a binder.

func NewConfig

func NewConfig() Config

NewConfig - Returns a fully defined Binder configuration with the default values for each field.

type Error

type Error struct {
	ID  string
	Err error
}

Error - A binder has encountered a problem and needs to close. In order for this to happen it needs to inform its owner that it should be shut down. Error is a structure used to carry our error message and our ID over an error channel. A Error with the Err set to nil can be used as a graceful shutdown request.

type Message

type Message struct {
	Content  string `json:"content,omitempty"`
	Position *int64 `json:"position,omitempty"`
	Active   bool   `json:"active"`
}

Message - Content, optional cursor position and a flag representing whether the client is active.

type Portal

type Portal interface {
	// UserID - Returns the user identifier associated with this binder session.
	UserID() string

	// SessionID - Returns the unique session identifier associated with this binder session.
	SessionID() string

	// BaseVersion - Returns the version of the binder as it was when this session opened.
	BaseVersion() int

	// Document - Returns the document contents as it was when this session opened.
	Document() store.Document

	// ReleaseDocument - Releases the cached document.
	ReleaseDocument()

	// TransformReadChan - Get the channel for reading transforms from other binder clients.
	TransformReadChan() <-chan text.OTransform

	// UpdateReadChan - Get the channel for reading meta updates from other binder clients.
	UpdateReadChan() <-chan ClientUpdate

	// SendTransform - Submits an operational transform to the document, this call adds the
	// transform to the stack of pending changes and broadcasts it to all other connected clients.
	// The transform must be submitted with the target version (the version that the client believed
	// it was, at the time it was made), and the actual version is returned.
	SendTransform(ot text.OTransform, timeout time.Duration) (int, error)

	// SendMessage - Broadcasts a message out to all other connected clients.
	SendMessage(message Message)

	// Exit - Inform the binder that this client is shutting down, this call will block until
	// acknowledged by the binder. Therefore, you may specify a timeout.
	Exit(timeout time.Duration)
}

Portal - An interface used by clients to contact a connected binder type.

type Type

type Type interface {
	// ID - Returns the ID of this binder.
	ID() string

	// GetUsers - Returns a list of connected users.
	GetUsers(timeout time.Duration) ([]string, error)

	// KickUser - Kick a connected user from this binder.
	KickUser(userID string, timeout time.Duration) error

	// Subscribe - Register a new client as an editor of this binder document.
	Subscribe(userID string, timeout time.Duration) (Portal, error)

	// SubscribeReadOnly - Register a new client as a read only viewer of this binder document.
	SubscribeReadOnly(userID string, timeout time.Duration) (Portal, error)

	// Close - Close the binder and shut down all clients, also flushes and cleans up the document.
	Close()
}

Type - Provides thread safe implementations of binder and session creation.

func New

func New(
	id string,
	block store.Type,
	config Config,
	errorChan chan<- Error,
	log log.Modular,
	stats metrics.Aggregator,
) (Type, error)

New - Creates a binder targeting an existing document determined via an ID. Must provide a store.Type to acquire the document and apply future updates to.

Jump to

Keyboard shortcuts

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