server

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2018 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package server is not for public use.

The API for packages in the 'private' directory have no stability guarantee.

The packages within the 'private' directory would normally be put into an 'internal' directory to prohibit their use outside the 'mongo' directory. However, some MongoDB tools require very low-level access to the building blocks of a driver, so we have placed them under 'private' to allow these packages to be imported by projects that need them.

These package APIs may be modified in backwards-incompatible ways at any time.

You are strongly discouraged from directly using any packages under 'private'.

Index

Constants

This section is empty.

Variables

View Source
var ErrServerClosed = errors.New("server is closed")

ErrServerClosed occurs when an attempt to get a connection is made after the server has been closed.

Functions

This section is empty.

Types

type Monitor

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

Monitor holds a channel that delivers updates to a server.

func StartMonitor

func StartMonitor(addr model.Addr, opts ...Option) (*Monitor, error)

StartMonitor returns a new Monitor.

func (*Monitor) Addr

func (m *Monitor) Addr() model.Addr

Addr returns the address this monitor is monitoring.

func (*Monitor) RequestImmediateCheck

func (m *Monitor) RequestImmediateCheck()

RequestImmediateCheck will cause the Monitor to send a heartbeat to the server right away, instead of waiting for the heartbeat timeout.

func (*Monitor) Stop

func (m *Monitor) Stop()

Stop turns off the monitor.

func (*Monitor) Subscribe

func (m *Monitor) Subscribe() (<-chan *model.Server, func(), error)

Subscribe returns a channel on which all updated server descriptions will be sent. The channel will have a buffer size of one, and will be pre-populated with the current description. Subscribe also returns a function that, when called, will close the subscription channel and remove it from the list of subscriptions.

type Option

type Option func(*config) error

Option configures a server.

func WithConnectionOpener

func WithConnectionOpener(opener conn.Opener) Option

WithConnectionOpener configures the opener to use to create a new connection.

func WithConnectionOptions

func WithConnectionOptions(opts ...conn.Option) Option

WithConnectionOptions configures server's connections. The options provided overwrite all previously configured options.

func WithHeartbeatInterval

func WithHeartbeatInterval(interval time.Duration) Option

WithHeartbeatInterval configures a server's heartbeat interval. This option will be ignored when creating a Server with a pre-existing monitor.

func WithHeartbeatTimeout

func WithHeartbeatTimeout(timeout time.Duration) Option

WithHeartbeatTimeout configures how long to wait for a heartbeat socket to connect.

func WithMaxConnections

func WithMaxConnections(max uint16) Option

WithMaxConnections configures maximum number of connections to allow for a given server. If max is 0, then there is no upper limit on the number of connections.

func WithMaxIdleConnections

func WithMaxIdleConnections(size uint16) Option

WithMaxIdleConnections configures the maximum number of idle connections allowed for the server.

func WithMoreConnectionOptions

func WithMoreConnectionOptions(opts ...conn.Option) Option

WithMoreConnectionOptions configures server's connections with additional options. The options provided are appended to any current options and may override previously configured options.

func WithWrappedConnectionOpener

func WithWrappedConnectionOpener(wrapper func(conn.Opener) conn.Opener) Option

WithWrappedConnectionOpener configures a new opener to be used which wraps the current opener.

type Server

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

Server is a logical connection to a server.

func New

func New(addr model.Addr, opts ...Option) (*Server, error)

New creates a new server. Internally, it creates a new Monitor with which to monitor the state of the server. When the Server is closed, the monitor will be stopped.

func NewWithMonitor

func NewWithMonitor(monitor *Monitor, opts ...Option) (*Server, error)

NewWithMonitor creates a new Server from an existing monitor. When the server is closed, the monitor will not be stopped. Any unspecified options will have their default value pulled from the monitor. Any monitor specific options will be ignored.

func (*Server) Close

func (s *Server) Close() error

Close closes the server.

func (*Server) Connection

func (s *Server) Connection(ctx context.Context) (conn.Connection, error)

Connection gets a connection to the server.

func (*Server) Model

func (s *Server) Model() *model.Server

Model gets a description of the server as of the last heartbeat.

Jump to

Keyboard shortcuts

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