struct Client
pub struct Client {
pub host string
pub port int
}Purpose
Zookeeper Client session maintaining connection and operations.
Public fields
hoststring- host
portint- port
#github.com/xulang-org/packages/zookeeperApache ZooKeeper Distributed Coordination Driver for Xu Communicates via 4LW (Four-Letter Words) and native TCP commands.
github.com/xulang-org/packages · 1.17.2 · Install and use
These sources come from the official examples repository and can be copied or downloaded. Run them with a local Xu SDK in the complete project; network, database, and desktop examples require the corresponding services or assets.
45_standalone_zookeeper/main.xu@main
zookeeper #github.com/xulang-org/packages/zookeeper
#errors
#strings
fn verify_zookeeper_pool() {
println("--- 1. Testing ZooKeeper Connection Pool ---")
$p := zookeeper.open_pool("127.0.0.1:2181", 5)
// 1. Connection Reuse
fd1 := p.get_conn()
println(" Borrow 1 fd: " + str(fd1))
p.put_conn(fd1)
fd2 := p.get_conn()
println(" Borrow 2 (after return) fd: " + str(fd2))
if fd1 == fd2 {
println(" [PASS] Connection reused successfully (fd " + str(fd1) + " == " + str(fd2) + ")")
} else {
println(" [WARN] Different fd allocated: " + str(fd1) + " vs " + str(fd2))
}
// 2. Multi-connection concurrent borrow
fd3 := p.get_conn()
println(" Borrow 3 (concurrently) fd: " + str(fd3))
if fd2 != fd3 {
println(" [PASS] Concurrently allocated distinct fds (" + str(fd2) + " != " + str(fd3) + ")")
} else {
println(" [FAIL] Expected distinct fds for concurrent connections!")
}
p.put_conn(fd2)
p.put_conn(fd3)
p.close()
println(" [PASS] ZooKeeper Pool closed cleanly.")
}
fn verify_zookeeper_4lw() {
println("\n--- 2. Testing ZooKeeper 4LW Commands ---")
$p := zookeeper.open_pool("127.0.0.1:2181", 5)
// 1. ruok
ok := p.ruok()
if ok {
println(" [PASS] ZooKeeper health check ruok -> imok")
} else {
println(" [NOTE] ZooKeeper 2181 not responding or not in standalone mode")
}
p.close()
}
fn main() {
println("=== Xu ZooKeeper Native Driver Verification ===\n")
verify_zookeeper_pool()
verify_zookeeper_4lw()
println("\n[ZOOKEEPER VERIFICATION 100% COMPLETED]")
}struct Clientpub struct Client {
pub host string
pub port int
}Zookeeper Client session maintaining connection and operations.
host stringport intnew_clientpub fn new_client(endpoint string) ClientConstruct client.
endpoint stringClient — a value of this type
(Client) exec_4lwpub fn (c Client) exec_4lw(cmd string) stringOperation on Client: exec 4lw. Throws on failure; handle the error or propagate it to the caller.
c ClientClient instance used by this call (value receiver).cmd stringstring — result string
(Client) ruokpub fn (c Client) ruok() boolExecute ruok on Client.
c ClientClient instance used by this call (value receiver).bool — true or false
(Client) statpub fn (c Client) stat() stringOperation on Client: read metadata. Throws on failure; handle the error or propagate it to the caller.
c ClientClient instance used by this call (value receiver).string — result string
(Client) mntrpub fn (c Client) mntr() stringExecute mntr on Client. Throws on failure; handle the error or propagate it to the caller.
c ClientClient instance used by this call (value receiver).string — result string
struct Poolpub struct Pool {
pub client Client
pub idle chan int
pub max_idle int
}Zookeeper Connection pool manager scheduling reusable socket connections.
client Clientidle chan intmax_idle intnew_poolpub fn new_pool(endpoint string, max_idle int) PoolConstruct pool.
endpoint stringmax_idle intPool — a value of this type
open_poolpub fn open_pool(endpoint string, max_idle int) PoolOpen pool.
endpoint stringmax_idle intPool — a value of this type
(&Pool) get_connpub fn (p &Pool) get_conn() intOperation on &Pool: read conn.
p &PoolPool instance used by this call (borrow).int — a value of this type
(&Pool) put_connpub fn (p &Pool) put_conn(fd int)Operation on &Pool: put connection.
p &PoolPool instance used by this call (borrow).fd intThis call does not return a value.
(&Pool) ruokpub fn (p &Pool) ruok() boolExecute ruok on &Pool.
p &PoolPool instance used by this call (borrow).bool — true or false
(&Pool) statpub fn (p &Pool) stat() stringOperation on &Pool: read metadata. Throws on failure; handle the error or propagate it to the caller.
p &PoolPool instance used by this call (borrow).string — result string
(&Pool) mntrpub fn (p &Pool) mntr() stringExecute mntr on &Pool. Throws on failure; handle the error or propagate it to the caller.
p &PoolPool instance used by this call (borrow).string — result string
(&Pool) closepub fn (p &Pool) close()Operation on &Pool: close the resource.
p &PoolPool instance used by this call (borrow).This call does not return a value.
struct TlsClientpub struct TlsClient {
pub conn transport.Conn
pub host string
pub port int
}Zookeeper Client session maintaining connection and operations.
conn transport.Connhost stringport inttls_connectpub fn tls_connect(endpoint string, default_port int) TlsClientTls connect. Throws on failure; handle the error or propagate it to the caller.
endpoint stringdefault_port intTlsClient — a value of this type
tls_connect_configpub fn tls_connect_config(endpoint string, default_port int, cfg tls.Config) TlsClientTls connect config. Throws on failure; handle the error or propagate it to the caller.
endpoint stringdefault_port intcfg tls.ConfigTlsClient — a value of this type
($&TlsClient) write_allpub fn (c $&TlsClient) write_all(data string) intOperation on $&TlsClient: write all. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).data stringint — a value of this type
($&TlsClient) readpub fn (c $&TlsClient) read(max int) stringOperation on $&TlsClient: read up to max bytes. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).max intstring — result string
($&TlsClient) read_exactpub fn (c $&TlsClient) read_exact(need int) stringOperation on $&TlsClient: read exact. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).need intstring — result string
($&TlsClient) closepub fn (c $&TlsClient) close() intOperation on $&TlsClient: close the resource. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).int — a value of this type
($&TlsClient) set_deadlinepub fn (c $&TlsClient) set_deadline(t_ns int) intOperation on $&TlsClient: set deadline. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).t_ns intint — a value of this type
($&TlsClient) set_read_deadlinepub fn (c $&TlsClient) set_read_deadline(t_ns int) intOperation on $&TlsClient: set read deadline. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).t_ns intint — a value of this type
($&TlsClient) set_write_deadlinepub fn (c $&TlsClient) set_write_deadline(t_ns int) intOperation on $&TlsClient: set write deadline. Throws on failure; handle the error or propagate it to the caller.
c $&TlsClientTlsClient instance used by this call (exclusive borrow).t_ns intint — a value of this type