Documentation ¶
Index ¶
- type Conn
- type ConnAdapter
- func (c ConnAdapter) ChildrenW(path string) ([]string, *zk.Stat, <-chan zk.Event, error)
- func (c ConnAdapter) Create(path string, data []byte, flags int32, acl []zk.ACL) (string, error)
- func (c ConnAdapter) CreateProtectedEphemeralSequential(path string, data []byte, acl []zk.ACL) (string, error)
- func (c ConnAdapter) Exists(path string) (bool, *zk.Stat, error)
- func (c ConnAdapter) Get(path string) ([]byte, *zk.Stat, error)
- type ConnectionOpts
- type Connector
- type Elector
- type Event
- type IElector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn interface { Get(path string) ([]byte, *zk.Stat, error) Exists(path string) (bool, *zk.Stat, error) Create(path string, data []byte, flags int32, acl []zk.ACL) (string, error) CreateProtectedEphemeralSequential(path string, data []byte, acl []zk.ACL) (string, error) ChildrenW(path string) ([]string, *zk.Stat, <-chan zk.Event, error) }
Conn represents a connection to ZK.
type ConnAdapter ¶
type ConnAdapter struct { GetF func(path string) ([]byte, *zk.Stat, error) ExistsF func(path string) (bool, *zk.Stat, error) CreateF func(path string, data []byte, flags int32, acl []zk.ACL) (string, error) CreateProtectedEphemeralSequentialF func(path string, data []byte, acl []zk.ACL) (string, error) ChildrenWF func(path string) ([]string, *zk.Stat, <-chan zk.Event, error) }
ConnAdapter represents a connection to ZK.
func (ConnAdapter) CreateProtectedEphemeralSequential ¶
func (c ConnAdapter) CreateProtectedEphemeralSequential(path string, data []byte, acl []zk.ACL) (string, error)
CreateProtectedEphemeralSequential implements Conn.
type ConnectionOpts ¶
type ConnectionOpts struct { // ConnectTimeout is the timeout to make the initial connection to ZK. ConnectTimeout time.Duration // InitialSessionTimeout is how long to wait for a valid session to // be established once the connection happens. InitialSessionTimeout time.Duration // Auth represents authentication details. If left alone, no auth will // be performed Auth struct { Schema string Secret []byte } }
ConnectionOpts are used when creating a new Zk connection
type Connector ¶
type Connector interface { // Connect returns a ZK connection and events channel Connect() (Conn, <-chan zk.Event, error) // Close should ensure the ZK connection is closed. Close() error }
Connector specifies a way to connect to ZK.
func ExistingConnection ¶
ExistingConnection returns an existing connection. Since it consumes from the zk.Event channel, it might be necessary for the client to fan out incoming events on the original channel to a new one so that events are not lost.
The existing connection should have already established a session before calling this method
func NewConnection ¶
func NewConnection(addrs []string, opts ConnectionOpts) Connector
NewConnection returns a Connector that creates a new ZK connection
type Elector ¶
type Elector struct {
// contains filtered or unexported fields
}
Elector handles leadership elections
func Start ¶
Start builds a new elector and runs it in the background.
The 'ident' parameter is the content that the elector will store inside of it's znode data. This will typically be the IP address of the client of the elector.
The 'basePath' parameter is the znode under which the leader election will happen.
The 'acl' will be set on any nodes that must be created
func (*Elector) Close ¶
Close closes the underlying ZK connection. Clients should call Close() when abandoning elector efforts in order to quickly delete any ephemeral nodes that were created as a part of the election process.
func (*Elector) LeaderIdent ¶
LeaderIdent returns the current leader, or "" if no current leader is known yet.
type Event ¶
type Event struct { // Leader is true if the elector that produced it is the leader Leader bool // Err represents an error event. If this is non-nil, the other fields // in the event must be ignored, and most clients will want to // shut down if Err is non-nil, since leadership cannot be guaranteed // in that case. // // When an err is sent, the Elector should no longer be considered // usable. Err error }
Event is sent on the Elector's Events() channel.
type IElector ¶
type IElector interface { // LeaderIdent returns the current leader of the cluster, or "" if // the current leader is not known. LeaderIdent() string // Events returns a channel from which the client should consume events // from the elector. The channel will be closed after an error event // is sent, as the elector is no longer usable from that point on. Events() <-chan Event // Close tidies up any applicable connection details to ZK. Clients // should call then when the elector is no longer needed Close() error }
IElector is the interface to which the Elector must adhere. Clients may choose to use this, but the Start() method will return a concrete type, keeping in line with 'return concrete types, accept interfaces'.