client

package
v0.0.0-...-7aac46a Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 5 Imported by: 0

README

client

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TODO
	// . add individual error messages for each option
	CLBUserInvalid  error = errors.New("CLBUser: invalid.")
	EDENYCONNECT    error = errors.New("CLBUser: deny connecting to already connected instance.")
	EDENYDISCONNECT error = errors.New("CLBUser: deny disconnecting the already disconnected instance.")
)

Error messages

Functions

This section is empty.

Types

type CLBOptions

type CLBOptions struct {
	// TODO:
	// . check padding
	ClientDelegate  func() protobase.ClientInterface
	StorageDelegate protobase.MessageBox
	Conn            protobase.ProtoClientConnection
	CFCallback      func(*CLBUser)
	Addr            string
	MaxRetry        int
	HeartBeat       int
	MinSecMRS       int // minimum retry delay ( number in Milliseconds)
	SecMRS          int // maximum sleep duration
}

CLBOptions contains values for setting up client-broker connection.

type CLBUser

type CLBUser struct {
	// TODO:
	// . check padding
	sync.RWMutex

	Conn    protobase.ProtoClientConnection // connection handler
	Cl      protobase.ClientInterface       // associated client
	Storage protobase.MessageBox            // message storage
	Exch    chan struct{}                   // exit channel

	CFCallback func(*CLBUser)
	Addr       string
	SecMRS     int
	MinSecMRS  int
	MaxRetry   int
	HeartBeat  int

	Running   bool
	Connected bool
	// contains filtered or unexported fields
}

CLBUser implements client to broker connection. It uses 'protobase.ClientInterface' as interface responsible for high level interactions.

func NewCLBUser

func NewCLBUser(opts CLBOptions) (clbu *CLBUser, ok bool)

NewCLBUser validates 'opts' and constructs a new 'CLBUser' and returns a pointer to it with boolean value indicating validity of 'opts'. NOTE: discard boolean iff valid pointer is non-nil.

func (*CLBUser) Connect

func (u *CLBUser) Connect() (err error)

Connect establishes connection to the destination and handles reconnecting and retrying to the root destination based on setup options.

func (*CLBUser) Disconnect

func (u *CLBUser) Disconnect() (err error)

Disconnect terminates the connection of the running instance and invokes 'Disconnected' receiver method on the associated client. NOTE: do not call this method manually.

func (*CLBUser) GetExitCh

func (u *CLBUser) GetExitCh() chan struct{}

GetExitCh returns exit channel.

func (*CLBUser) IsConnected

func (u *CLBUser) IsConnected() (ok bool)

IsConnected returns whether instance is connected.

func (*CLBUser) IsRunning

func (u *CLBUser) IsRunning() (ok bool)

IsRunning returns whether current instance is active.

func (*CLBUser) SetConnected

func (u *CLBUser) SetConnected(b bool)

SetConnected sets 'b' indicating connection status.

func (*CLBUser) SetRunning

func (u *CLBUser) SetRunning(b bool)

SetRunning sets running status to 'b'.

func (*CLBUser) Setup

func (u *CLBUser) Setup() error

Setup performs initialization and construction of available options and its assignment to internal struct variables. It returns error when unsuccessful.

type Client

type Client struct {
	*sync.RWMutex

	User        interface{}
	ClientId    string
	Username    string
	Password    string
	WillMessage string
	WillQos     string
	WillRetain  string
	Server      protobase.ServerInterface
	Topics      []string
	// contains filtered or unexported fields
}

Client implements basic high-level functionality based on 'protobase.ClientInterface'.

func NewClient

func NewClient(username string, password string, cid string) *Client

func (*Client) AddTopic

func (c *Client) AddTopic(topic string)

func (*Client) Connected

func (c *Client) Connected(opts protobase.OptionInterface) bool

func (*Client) Disconnected

func (c *Client) Disconnected(opts protobase.OptCode)

func (*Client) GetCreds

func (c *Client) GetCreds() protobase.CredentialsInterface

func (*Client) GetIdentifier

func (c *Client) GetIdentifier() string

func (*Client) GetTopics

func (c *Client) GetTopics() []string

func (*Client) GetUser

func (c *Client) GetUser() interface{}

func (*Client) Publish

func (c *Client) Publish(msg protobase.MsgInterface)

func (*Client) SetAuthMechanism

func (c *Client) SetAuthMechanism()

func (*Client) SetCreds

func (c *Client) SetCreds(creds protobase.CredentialsInterface)

func (*Client) SetServer

func (c *Client) SetServer(server protobase.ServerInterface)

func (*Client) SetUser

func (c *Client) SetUser(user interface{})

func (*Client) Setup

func (c *Client) Setup() error

func (*Client) Subscribe

func (c *Client) Subscribe(msg protobase.MsgInterface)

type ClientErrorHandlerFunc

type ClientErrorHandlerFunc func(client *protobase.ClientInterface)

ClientErrorHandlerFunc is error callback function.

Jump to

Keyboard shortcuts

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