IRISHUB-238: delete client manager

This commit is contained in:
HaoyangLiu 2018-08-30 17:14:10 +08:00
parent 3f83aca599
commit 5e85a5cdcd
3 changed files with 0 additions and 69 deletions

View File

@ -1,46 +0,0 @@
package context
import (
"github.com/pkg/errors"
rpcclient "github.com/tendermint/tendermint/rpc/client"
"strings"
"sync"
)
// ClientManager is a manager of a set of rpc clients to full nodes.
// This manager can do load balancing upon these rpc clients.
type ClientManager struct {
clients []rpcclient.Client
currentIndex int
mutex sync.Mutex
}
// NewClientManager create a new ClientManager
func NewClientManager(nodeURIs string) (*ClientManager, error) {
if nodeURIs != "" {
nodeURLArray := strings.Split(nodeURIs, ",")
var clients []rpcclient.Client
for _, url := range nodeURLArray {
client := rpcclient.NewHTTP(url, "/websocket")
clients = append(clients, client)
}
mgr := &ClientManager{
currentIndex: 0,
clients: clients,
}
return mgr, nil
}
return nil, errors.New("missing node URIs")
}
func (mgr *ClientManager) getClient() rpcclient.Client {
mgr.mutex.Lock()
defer mgr.mutex.Unlock()
client := mgr.clients[mgr.currentIndex]
mgr.currentIndex++
if mgr.currentIndex >= len(mgr.clients) {
mgr.currentIndex = 0
}
return client
}

View File

@ -1,16 +0,0 @@
package context
import (
"github.com/stretchr/testify/assert"
"testing"
)
func TestClientManager(t *testing.T) {
nodeURIs := "10.10.10.10:26657,20.20.20.20:26657,30.30.30.30:26657"
clientMgr, err := NewClientManager(nodeURIs)
assert.Empty(t, err)
endpoint := clientMgr.getClient()
assert.NotEqual(t, endpoint, clientMgr.getClient())
clientMgr.getClient()
assert.Equal(t, endpoint, clientMgr.getClient())
}

View File

@ -34,7 +34,6 @@ type CLIContext struct {
JSON bool
PrintResponse bool
Certifier tendermintLite.Certifier
ClientManager *ClientManager
}
// NewCLIContext returns a new initialized CLIContext with parameters from the
@ -126,9 +125,3 @@ func (ctx CLIContext) WithCertifier(certifier tendermintLite.Certifier) CLIConte
ctx.Certifier = certifier
return ctx
}
// WithClientManager - return a copy of the context with an updated ClientManager
func (ctx CLIContext) WithClientManager(clientManager *ClientManager) CLIContext {
ctx.ClientManager = clientManager
return ctx
}