// NewPluginClient returns a databaseRPCClient with a connection to a running
// plugin. The client is wrapped in a DatabasePluginClient object to ensure the
// plugin is killed on call of Close().
17274
func NewPluginClient(ctx context.Context, sys pluginutil.RunnerUtil, pluginRunner *pluginutil.PluginRunner, logger log.Logger, isMetadataMode bool) (Database, error) {

	// pluginSets is the map of plugins we can dispense.
	pluginSets := map[int]plugin.PluginSet{
		// Version 3 used to supports both protocols. We want to keep it around
		// since it's possible old plugins built against this version will still
		// work with gRPC. There is currently no difference between version 3
		// and version 4.
		3: plugin.PluginSet{
			"database": new(GRPCDatabasePlugin),
		},
		// Version 4 only supports gRPC
		4: plugin.PluginSet{
			"database": new(GRPCDatabasePlugin),
		},
	}

	var client *plugin.Client
	var err error
	if isMetadataMode {
		client, err = pluginRunner.RunMetadataMode(ctx, sys, pluginSets, handshakeConfig, []string{}, logger)
	} else {
		client, err = pluginRunner.Run(ctx, sys, pluginSets, handshakeConfig, []string{}, logger)
	}
	if err != nil {
		return nil, err
	}

	// Connect via RPC
	rpcClient, err := client.Client()
	if err != nil {
		return nil, err
	}

	// Request the plugin
	raw, err := rpcClient.Dispense("database")
	if err != nil {
		return nil, err
	}

	// We should have a database type now. This feels like a normal interface
	// implementation but is in fact over an RPC connection.
	var db Database
	switch raw.(type) {
	case *gRPCClient:
		db = raw.(*gRPCClient)
	default:
		return nil, errors.New("unsupported client type")
	}

	// Wrap RPC implementation in DatabasePluginClient
	return &DatabasePluginClient{
		client:   client,
		Database: db,
	}, nil
}
882170
func newClient(config Config, hosts []string) *Client {

	if config.ConnectionsPerHost <= 0 {
		config.ConnectionsPerHost = 5
	}

	if config.Timeout <= 0 {
		config.Timeout = 5 * time.Second
	}

	if config.User == "" {
		config.User = "anonymous"
	}

	if config.Password == "" {
		config.Password = "anonymous"
	}

	if config.ServerLocation == nil {
		config.ServerLocation = time.UTC
	}

	if config.ActiveListenAddr == "" {
		config.ActiveListenAddr = ":0"
	}

	return &Client{
		config:          config,
		freeConnCh:      make(chan *persistentConn, len(hosts)*config.ConnectionsPerHost),
		t0:              time.Now(),
		hosts:           hosts,
		allCons:         make(map[int]*persistentConn),
		numConnsPerHost: make(map[string]int),
	}
}
1090720
func NewClient(config db.Configuration) (*Client, error) {
	once.Do(func() {
		connectionString := fmt.Sprintf("%s:%d", config.Host, config.Port)
		opts := []redis.DialOption{
			redis.DialPassword(config.Password),
			redis.DialConnectTimeout(time.Duration(config.Timeout) * time.Millisecond),
		}

		dialFunc := func() (redis.Conn, error) {
			conn, err := redis.Dial(
				"tcp", connectionString, opts...,
			)
			if err != nil {
				return nil, fmt.Errorf("Could not dial Redis: %s", err)
			}
			return conn, nil
		}

		currClient = &Client{
			Pool: &redis.Pool{
				IdleTimeout: 0,
				/* The current implementation processes nested structs using concurrent connections.
				 * With the deepest nesting level being 3, three shall be the number of maximum open
				 * idle connections in the pool, to allow reuse.
				 * TODO: Once we have a concurrent benchmark, this should be revisited.
				 * TODO: Longer term, once the objects are clean of external dependencies, the use
				 * of another serializer should make this moot.
				 */
				MaxIdle: 10,
				Dial:    dialFunc,
			},
		}
	})
	return currClient, nil
}
1357450
func NewLBClient(addr string) (*LBClient, error) {
	client, err := rpcutils.GetCachedClient(addr)
	if err != nil {
		return nil, err
	}
	s := new(LBClient)
	s.addr = addr
	s.rpcClient = client
	return s, nil
}
72511
func NewClient(w io.Writer) *Client {
	return &Client{
		buf: bufio.NewWriterSize(w, defaultBufSize),
	}
}
234571
func NewClient(addr string) *RPCClient {
	client, err := jsonrpc.Dial("tcp", addr)
	if err != nil {
		log.Fatal("dialing:", err)
	}
	return newFromRPCClient(client)
}
11791
func NewClient(l2c ble.Conn, h NotificationHandler) *Client {
	c := &Client{
		l2c:     l2c,
		rspc:    make(chan []byte),
		chTxBuf: make(chan []byte, 1),
		rxBuf:   make([]byte, ble.MaxMTU),
		chErr:   make(chan error, 1),
		handler: h,
	}
	c.chTxBuf <- make([]byte, l2c.TxMTU(), l2c.TxMTU())
	return c
}
269325
func NewCollectorGrpcClient(address string, timeout time.Duration, security GRPCSecurity) (PluginCollectorClient, error) {
	ctx := context.Background()
	p, err := newPluginGrpcClient(ctx, address, timeout, security, plugin.CollectorPluginType)
	if err != nil {
		return nil, err
	}
	return p.(PluginCollectorClient), err
}
1262683
func NewClient(conn *rpcc.Conn) *Client {
	return &Client{
		Accessibility:        accessibility.NewClient(conn),
		Animation:            animation.NewClient(conn),
		ApplicationCache:     applicationcache.NewClient(conn),
		Audits:               audits.NewClient(conn),
		BackgroundService:    backgroundservice.NewClient(conn),
		Browser:              browser.NewClient(conn),
		CSS:                  css.NewClient(conn),
		CacheStorage:         cachestorage.NewClient(conn),
		Cast:                 cast.NewClient(conn),
		Console:              console.NewClient(conn),
		DOM:                  dom.NewClient(conn),
		DOMDebugger:          domdebugger.NewClient(conn),
		DOMSnapshot:          domsnapshot.NewClient(conn),
		DOMStorage:           domstorage.NewClient(conn),
		Database:             database.NewClient(conn),
		Debugger:             debugger.NewClient(conn),
		DeviceOrientation:    deviceorientation.NewClient(conn),
		Emulation:            emulation.NewClient(conn),
		Fetch:                fetch.NewClient(conn),
		HeadlessExperimental: headlessexperimental.NewClient(conn),
		HeapProfiler:         heapprofiler.NewClient(conn),
		IO:                   io.NewClient(conn),
		IndexedDB:            indexeddb.NewClient(conn),
		Input:                input.NewClient(conn),
		Inspector:            inspector.NewClient(conn),
		LayerTree:            layertree.NewClient(conn),
		Log:                  log.NewClient(conn),
		Memory:               memory.NewClient(conn),
		Network:              network.NewClient(conn),
		Overlay:              overlay.NewClient(conn),
		Page:                 page.NewClient(conn),
		Performance:          performance.NewClient(conn),
		Profiler:             profiler.NewClient(conn),
		Runtime:              runtime.NewClient(conn),
		Schema:               schema.NewClient(conn),
		Security:             security.NewClient(conn),
		ServiceWorker:        serviceworker.NewClient(conn),
		Storage:              storage.NewClient(conn),
		SystemInfo:           systeminfo.NewClient(conn),
		Target:               target.NewClient(conn),
		Tethering:            tethering.NewClient(conn),
		Tracing:              tracing.NewClient(conn),
	}
}
1184659
func NewClient(accessKeyId, accessKeySecret string) *Client {
	client := &Client{}
	client.Init(END_POINT, VERSION, accessKeyId, accessKeySecret)
	return client
}
340994
func NewClient(opts *NewClientOptions) (*Client, error) {
	if opts == nil {
		return nil, ErrClientOptionsRequired
	}
	if opts.Cluster != nil {
		return newClientUsingCluster(opts.Cluster)
	}
	if opts.RemoteAddresses != nil {
		return newClientUsingAddresses(opts.Port, opts.RemoteAddresses)
	}
	return nil, ErrClientMissingRequiredData
}
512305
func NewClient(c ble.Conn) (*Client, error) {
	return &Client{
		conn: c.(*conn),
		id:   xpc.MakeUUID(c.RemoteAddr().String()),
	}, nil
}
1243079
func NewPublisherGrpcClient(address string, timeout time.Duration, security GRPCSecurity) (PluginPublisherClient, error) {
	ctx := context.Background()
	p, err := newPluginGrpcClient(ctx, address, timeout, security, plugin.PublisherPluginType)
	if err != nil {
		return nil, err
	}
	return p.(PluginPublisherClient), err
}
228553
func NewClient(opentsdbCfg config.OpenTSDBConfig) (Client, error) {
	opentsdbCfg.OpentsdbHost = strings.TrimSpace(opentsdbCfg.OpentsdbHost)
	if len(opentsdbCfg.OpentsdbHost) <= 0 {
		return nil, errors.New("The OpentsdbEndpoint of the given config should not be empty.")
	}
	transport := opentsdbCfg.Transport
	if transport == nil {
		transport = DefaultTransport
	}
	client := &http.Client{
		Transport: transport,
	}
	if opentsdbCfg.MaxPutPointsNum <= 0 {
		opentsdbCfg.MaxPutPointsNum = DefaultMaxPutPointsNum
	}
	if opentsdbCfg.DetectDeltaNum <= 0 {
		opentsdbCfg.DetectDeltaNum = DefaultDetectDeltaNum
	}
	if opentsdbCfg.MaxContentLength <= 0 {
		opentsdbCfg.MaxContentLength = DefaultMaxContentLength
	}
	tsdbEndpoint := fmt.Sprintf("http://%s", opentsdbCfg.OpentsdbHost)
	clientImpl := clientImpl{
		tsdbEndpoint: tsdbEndpoint,
		client:       client,
		opentsdbCfg:  opentsdbCfg,
	}
	return &clientImpl, nil
}
426237
func InitClient(storeName string, storeURLs []string) (API, error) {
	plugin := GetPlugin(storeName)
	if plugin == nil {
		log.Errorf("Invalid DB type %s", storeName)
		return nil, errors.New("unsupported DB type")
	}
	cl, err := plugin.NewClient(storeURLs)
	if err != nil {
		log.Errorf("Error creating client %s to url %v. Err: %v", storeName, storeURLs, err)
		return nil, err
	}
	return cl, nil
}
469569
func NewClient(st base.APICallCloser) *Client {
	frontend, backend := base.NewClientFacade(st, "Controller")
	return &Client{
		ClientFacade:        frontend,
		facade:              backend,
		ControllerConfigAPI: common.NewControllerConfig(backend),
		ModelStatusAPI:      common.NewModelStatusAPI(backend),
	}
}
439048
func NewClient(sockPath string) (clitypes.ContainerizedClient, error) {
	if sockPath == "" {
		sockPath = containerdSockPath
	}
	cclient, err := containerd.New(sockPath)
	if err != nil {
		return nil, err
	}
	return &baseClient{
		cclient: cclient,
	}, nil
}