/**
 * @desc		TCP框架
 * ********************************************
 * @author		unphp <unphp@qq.com>
 * @date		2021-12-17
 * @copyright	ants 0.1
 * ********************************************
 */

package ants

//NewSession ...
func NewSession(client *ClientConn, pool ClientPool) *NodeSession {
	return &NodeSession{
		connPool: pool,
		client:   client,
	}
}

//NodeSession ...
type NodeSession struct {
	connPool ClientPool
	client   *ClientConn
}

func (that *NodeSession) Ping() error {
	return that.client.Ping()
}

func (that *NodeSession) GetWorkerID() string {
	return that.client.GetworkerID()
}

func (that *NodeSession) LeaderCheck() (bool, error) {
	return that.client.LeaderCheck()
}

func (that *NodeSession) Leader() (string, error) {
	return that.client.Leader()
}

func (that *NodeSession) NewRequest(path string, data []byte) (int64, []byte, error) {
	return that.client.NewRequest(path, data)
}

func (that *NodeSession) Close() {
	if that.client.Closed() {
		return
	}
	go that.connPool.RecycleConn(that.client)
}
