gxetcd

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2018 License: Apache-2.0 Imports: 6 Imported by: 1

Documentation

Overview

Copyright 2016 ~ 2018 AlexStocks(https://github.com/AlexStocks). All rights reserved. Use of this source code is governed by Apache License 2.0.

gxetcd encapsulate a etcd lease client

Copyright 2016 ~ 2018 AlexStocks(https://github.com/AlexStocks). All rights reserved. Use of this source code is governed by Apache License 2.0.

gxetcd encapsulate a etcd lease client

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Client represents a lease kept alive for the lifetime of a client. Fault-tolerant applications may use sessions to reason about liveness.

func NewClient

func NewClient(client *ecv3.Client, options ...ClientOption) (*Client, error)

NewClient gets the leased session for a client.

func (*Client) Close

func (c *Client) Close() error

Close orphans the session and revokes the session lease.

func (*Client) Done

func (c *Client) Done() <-chan struct{}

Done returns a channel that closes when the lease is orphaned, expires, or is otherwise no longer being refreshed.

func (*Client) EtcdClient

func (c *Client) EtcdClient() *ecv3.Client

Client is the etcd client that is attached to the session.

func (*Client) IsClosed

func (c *Client) IsClosed() bool

check whether the session has been closed.

func (*Client) KeepAlive

func (c *Client) KeepAlive() (<-chan *ecv3.LeaseKeepAliveResponse, error)

func (*Client) Lease

func (c *Client) Lease() ecv3.LeaseID

Lease is the lease ID for keys bound to the session.

func (*Client) Stop

func (c *Client) Stop()

Stop ends the refresh for the session lease. This is useful in case the state of the client connection is indeterminate (revoke would fail) or when transferring lease ownership.

func (*Client) TTL

func (c *Client) TTL() int64

TTL return the ttl of Client's lease

type ClientOption

type ClientOption func(*clientOptions)

ClientOption configures Client.

func WithContext

func WithContext(ctx context.Context) ClientOption

WithContext assigns a context to the session instead of defaulting to using the client context. This is useful for canceling NewClient and Close operations immediately without having to close the client. If the context is canceled before Close() completes, the session's lease will be abandoned and left to expire instead of being revoked.

func WithLease

func WithLease(leaseID ecv3.LeaseID) ClientOption

WithLease specifies the existing leaseID to be used for the session. This is useful in process restart scenario, for example, to reclaim leadership from an election prior to restart.

func WithTTL

func WithTTL(ttl time.Duration) ClientOption

WithTTL configures the session's TTL in seconds. If TTL is <= 0, the default 60 seconds TTL will be used.

Jump to

Keyboard shortcuts

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