Connect creates a Pool instance for the node with the given address or returns the existing one.
(addr string, tlsClientConf *tls.Config)
| 151 | |
| 152 | // Connect creates a Pool instance for the node with the given address or returns the existing one. |
| 153 | func (p *Pools) Connect(addr string, tlsClientConf *tls.Config) *Pool { |
| 154 | existingPool, has := p.getPool(addr) |
| 155 | if has { |
| 156 | return existingPool |
| 157 | } |
| 158 | |
| 159 | pool, err := newPool(addr, tlsClientConf) |
| 160 | if err != nil { |
| 161 | glog.Errorf("CONN: Unable to connect to host: %s", addr) |
| 162 | return nil |
| 163 | } |
| 164 | |
| 165 | p.Lock() |
| 166 | defer p.Unlock() |
| 167 | existingPool, has = p.all[addr] |
| 168 | if has { |
| 169 | go pool.shutdown() // Not being used, so release the resources. |
| 170 | return existingPool |
| 171 | } |
| 172 | glog.Infof("CONN: Connecting to %s\n", addr) |
| 173 | p.all[addr] = pool |
| 174 | return pool |
| 175 | } |
| 176 | |
| 177 | // newPool creates a new "pool" with one gRPC connection, refcount 0. |
| 178 | func newPool(addr string, tlsClientConf *tls.Config) (*Pool, error) { |