forked from TrueCloudLab/frostfs-node
[#1170] pkg/morph: Add inactive mode callback
Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
parent
424cc6d495
commit
2427593da6
2 changed files with 25 additions and 3 deletions
|
@ -543,10 +543,16 @@ func (c *Client) NotificationChannel() <-chan client.Notification {
|
||||||
|
|
||||||
// inactiveMode switches Client to an inactive mode:
|
// inactiveMode switches Client to an inactive mode:
|
||||||
// - notification channel is closed;
|
// - notification channel is closed;
|
||||||
// - all the new RPC request would return ErrConnectionLost.
|
// - all the new RPC request would return ErrConnectionLost;
|
||||||
//
|
// - inactiveModeCb is called if not nil.
|
||||||
// Note: must be called only with held write switchLock.
|
|
||||||
func (c *Client) inactiveMode() {
|
func (c *Client) inactiveMode() {
|
||||||
|
c.switchLock.Lock()
|
||||||
|
defer c.switchLock.Unlock()
|
||||||
|
|
||||||
close(c.notifications)
|
close(c.notifications)
|
||||||
c.inactive = true
|
c.inactive = true
|
||||||
|
|
||||||
|
if c.cfg.inactiveModeCb != nil {
|
||||||
|
c.cfg.inactiveModeCb()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,10 @@ import (
|
||||||
// Option is a client configuration change function.
|
// Option is a client configuration change function.
|
||||||
type Option func(*cfg)
|
type Option func(*cfg)
|
||||||
|
|
||||||
|
// Callback is a function that is going to be called
|
||||||
|
// on certain Client's state.
|
||||||
|
type Callback func()
|
||||||
|
|
||||||
// groups the configurations with default values.
|
// groups the configurations with default values.
|
||||||
type cfg struct {
|
type cfg struct {
|
||||||
ctx context.Context // neo-go client context
|
ctx context.Context // neo-go client context
|
||||||
|
@ -34,6 +38,8 @@ type cfg struct {
|
||||||
extraEndpoints []string
|
extraEndpoints []string
|
||||||
|
|
||||||
singleCli *client.WSClient // neo-go client for single client mode
|
singleCli *client.WSClient // neo-go client for single client mode
|
||||||
|
|
||||||
|
inactiveModeCb Callback
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -217,3 +223,13 @@ func WithSingleClient(cli *client.WSClient) Option {
|
||||||
c.singleCli = cli
|
c.singleCli = cli
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithConnLostCallback return a client constructor option
|
||||||
|
// that specifies a callback that is called when Client
|
||||||
|
// unsuccessfully tried to connect to all the specified
|
||||||
|
// endpoints.
|
||||||
|
func WithConnLostCallback(cb Callback) Option {
|
||||||
|
return func(c *cfg) {
|
||||||
|
c.inactiveModeCb = cb
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue