GetClientFor gets the client for the specified address. If it does not exist it will make a new client at that address
(addr string)
| 92 | // GetClientFor gets the client for the specified address. If it does not exist it will make a new client |
| 93 | // at that address |
| 94 | func (p *Pool) GetClientFor(addr string) (PoolClient, error) { |
| 95 | client, ok := p.fromCache(addr) |
| 96 | if ok { |
| 97 | return client, nil |
| 98 | } |
| 99 | |
| 100 | p.Lock() |
| 101 | defer p.Unlock() |
| 102 | client, ok = p.clients[addr] |
| 103 | if ok { |
| 104 | return client, nil |
| 105 | } |
| 106 | |
| 107 | client, err := p.factory(addr) |
| 108 | if err != nil { |
| 109 | return nil, err |
| 110 | } |
| 111 | p.clients[addr] = client |
| 112 | if p.clientsMetric != nil { |
| 113 | p.clientsMetric.Add(1) |
| 114 | } |
| 115 | return client, nil |
| 116 | } |
| 117 | |
| 118 | // RemoveClientFor removes the client with the specified address |
| 119 | func (p *Pool) RemoveClientFor(addr string) { |