1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- package region
- import (
- "context"
- "fmt"
- "net"
- "time"
- "github.com/tsuna/gohbase/hrpc"
- )
- func NewClient(ctx context.Context, addr string, ctype ClientType,
- queueSize int, flushInterval time.Duration, effectiveUser string,
- readTimeout time.Duration) (hrpc.RegionClient, error) {
- var d net.Dialer
- conn, err := d.DialContext(ctx, "tcp", addr)
- if err != nil {
- return nil, fmt.Errorf("failed to connect to the RegionServer at %s: %s", addr, err)
- }
- c := &client{
- addr: addr,
- conn: conn,
- rpcs: make(chan hrpc.Call),
- done: make(chan struct{}),
- sent: make(map[uint32]hrpc.Call),
- rpcQueueSize: queueSize,
- flushInterval: flushInterval,
- effectiveUser: effectiveUser,
- readTimeout: readTimeout,
- }
-
-
- if deadline, ok := ctx.Deadline(); ok {
- conn.SetWriteDeadline(deadline)
- }
- if err := c.sendHello(ctype); err != nil {
- conn.Close()
- return nil, fmt.Errorf("failed to send hello to the RegionServer at %s: %s", addr, err)
- }
-
- conn.SetWriteDeadline(time.Time{})
- if ctype == RegionClient {
- go c.processRPCs()
- }
- go c.receiveRPCs()
- return c, nil
- }
|