// Creates a connection.
// A connection indicates from which data source the data should be taken.
//
// Parameters:
//
// ◾ connection   -   Information about the connection.
//
513549
func (obj *Doc) CreateConnection(ctx context.Context, connection *Connection) (string, error) {
	result := &struct {
		ConnectionId string	`json:"qConnectionId"`
	} {}
	err := obj.rpc(ctx, "CreateConnection", result, connection)
	return result.ConnectionId, err 
}
866586
func (s Session) AddConnectionData(data ConnectionData) Session {
	v := make([]byte, 0, 512)
	v = append(v, data.getNetworkType()...)
	v = appendSpace(v)
	v = append(v, data.getAddressType()...)
	v = appendSpace(v)
	v = data.appendAddress(v)
	return s.append(TypeConnectionData, v)
}
763768
func NewConnection(config ConnectionConfig) (driver.Connection, error) {
	c, err := cluster.NewConnection(config.ConnectionConfig, func(endpoint string) (driver.Connection, error) {
		conn, err := newVSTConnection(endpoint, config)
		if err != nil {
			return nil, driver.WithStack(err)
		}
		return conn, nil
	}, config.Endpoints)
	if err != nil {
		return nil, driver.WithStack(err)
	}
	return c, nil
}
415646
func (p *ParserFactory) Create(connection *proxylib.Connection) proxylib.Parser {
	log.Debugf("ParserFactory: Create: %v", connection)
	return &Parser{
		connection: connection,
	}
}
1343846
func Create(ctx context.Context, client client.APIClient, name string, ops ...func(*types.NetworkCreate)) (string, error) {
	return createNetwork(ctx, client, name, ops...)
}
473791
func NewConnection(address string, port int,
	timeout time.Duration) (*Connection, error) {

	url := "http://" + address + ":" + strconv.Itoa(port)
	return createConnection(url, timeout)
}
78830
func (c *Conn) Connect() error {
	ret := C.rados_connect(c.cluster)
	if ret != 0 {
		return RadosError(int(ret))
	}
	c.connected = true
	return nil
}
514285
func (repo *repo) Create(user service.Entity) bool {
	if dbconn.DB.NewRecord(user) {
		dbconn.DB.Create(&user)
	}
	return !dbconn.DB.NewRecord(user)
}
615413
func (conn *Connection) Connect(ctx context.Context) (err error) {
	obs := prometheus.NewTimer(connInitialConnectTime)
	defer obs.ObserveDuration()

	conn.conMu.Lock()
	defer conn.conMu.Unlock()

	var tlsc *tls.Config

	if !conn.choria.Config.DisableTLS {
		tlsc, err = conn.choria.TLSConfig()
		if err != nil {
			err = fmt.Errorf("Could not create TLS Config: %s", err)
			return err
		}
	}

	urls := []string{}
	var url *url.URL

	servers, err := conn.servers()
	if err != nil {
		err = fmt.Errorf("Could not resolve servers during initial connect: %s", err)
	}

	for _, server := range servers {
		url, err = server.URL()
		if err != nil {
			err = fmt.Errorf("Could not determine URL for server %#v", server)
			return
		}

		urls = append(urls, url.String())
	}

	options := []nats.Option{
		nats.MaxReconnects(-1),
		nats.Name(conn.name),

		// This is specifically set quite small, just about enough to handle short
		// reconnects rather than the 8MB long buffer that's default.  30 000 nodes
		// each sending several MB after reconnect is not what anyone wants
		nats.ReconnectBufSize(10 * 1024),

		// nats.SetPend
		nats.DisconnectHandler(func(nc *nats.Conn) {
			err = nc.LastError()

			if err != nil {
				conn.logger.Warnf("NATS client connection got disconnected: %s", nc.LastError())
			}
		}),

		nats.ReconnectHandler(func(nc *nats.Conn) {
			conn.logger.Warnf("NATS client reconnected after a previous disconnection, connected to %s", nc.ConnectedUrl())
			connReconnectCtr.Inc()
		}),

		nats.ClosedHandler(func(nc *nats.Conn) {
			err = nc.LastError()
			if err != nil {
				conn.logger.Warnf("NATS client connection closed: %s", nc.LastError())
			}
			connClosedCtr.Inc()
		}),

		nats.ErrorHandler(func(nc *nats.Conn, sub *nats.Subscription, err error) {
			conn.logger.Errorf("NATS client on %s encountered an error: %s", nc.ConnectedUrl(), err)
			connErrorCtr.Inc()
		}),
	}

	if !conn.choria.Config.DisableTLS {
		options = append(options, nats.Secure(tlsc))
	}

	if !conn.choria.Config.Choria.RandomizeMiddlewareHosts {
		options = append(options, nats.DontRandomize())
	}

	try := 0

	for {
		try++

		conn.nats, err = nats.Connect(strings.Join(urls, ", "), options...)
		if err != nil {
			connInitialConnectCtr.Inc()

			conn.logger.Warnf("Initial connection to the NATS broker cluster failed: %s", err)

			if ctx.Err() != nil {
				err = fmt.Errorf("Initial connection cancelled due to shut down")
				return
			}

			s := backoff.FiveSec.Duration(try)
			conn.logger.Infof("Sleeping %s after failed connection attempt %d", s, try)
			time.Sleep(s)

			continue
		}

		conn.logger.Debugf("Connected to %s", conn.nats.ConnectedUrl())

		break
	}

	return
}
169315
func (c *Client) connect() byte {
	DEBUG.Println(NET, "connect started")

	ca, err := packets.ReadPacket(c.conn)
	if err != nil {
		ERROR.Println(NET, "connect got error", err)
		return packets.ErrNetworkError
	}
	if ca == nil {
		ERROR.Println(NET, "received nil packet")
		return packets.ErrNetworkError
	}

	msg, ok := ca.(*packets.ConnackPacket)
	if !ok {
		ERROR.Println(NET, "received msg that was not CONNACK")
		return packets.ErrNetworkError
	}

	DEBUG.Println(NET, "received connack")
	return msg.ReturnCode
}
846299
func (s *Simulator) NewConnection() *Connection {
	addr := s.LocalAddr()
	return &Connection{
		Hostname:  addr.IP.String(),
		Port:      addr.Port,
		Interface: "lan",
	}
}
1137902
func (p *Plugin) NewProtoConnection(name string) mux.Connection {
	return p.mux.NewProtoConnection(name, &keyval.SerializerJSON{})
}
623408
func (c *Conn) Connect() error {
	// Make sure the existing connection is closed
	if c.NetConn != nil {
		c.NetConn.Close()
	}

	conn, err := net.Dial("tcp", c.gateway)
	if err != nil {
		return err
	}

	tlsConn := tls.Client(conn, c.Conf)
	err = tlsConn.Handshake()
	if err != nil {
		return err
	}

	c.NetConn = tlsConn
	return nil
}
476194
func (s *Service) createConnection(w http.ResponseWriter, r *http.Request) {
	opts := store.ConnectionOptions{
		IdleTimeout: s.ConnIdleTimeout,
		TxTimeout:   s.ConnTxTimeout,
	}

	d, b, err := txTimeout(r)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return
	}
	if b {
		opts.TxTimeout = d
	}

	d, b, err = idleTimeout(r)
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return
	}
	if b {
		opts.IdleTimeout = d
	}

	conn, err := s.store.Connect(&opts)
	if err != nil {
		http.Error(w, err.Error(), http.StatusServiceUnavailable)
		return
	}
	w.Header().Set("Location", s.FormConnectionURL(r, conn.ID))
	w.WriteHeader(http.StatusCreated)
}
177739
func (obj *Doc) CreateConnectionRaw(ctx context.Context, connection interface{}) (string, error) {
	result := &struct {
		ConnectionId string	`json:"qConnectionId"`
	} {}
	err := obj.rpc(ctx, "CreateConnection", result, ensureEncodable(connection))
	return result.ConnectionId, err 
}
54998
func (c *ConnectionsService) Make() (*gorm.DB, error) {
	// Check if we already have a reference to a connection
	if c.CurrentConnection != nil {
		return c.CurrentConnection, nil
	}

	var db gorm.DB
	var err error

	// Setup Gorm with the specified driver
	switch c.Config.GetString("database.driver") {
	case "sqlite":
		db, err = gorm.Open("sqlite3", c.Config.GetString("database.file"))
		break
	case "mysql":
		pretty.Println(c.Config.GetString("database.host"))
		uri := fmt.Sprintf(
			"%s:%s@tcp(%s:%d)/%s?charset=utf8&parseTime=True&loc=Local",
			c.Config.GetString("database.username"),
			c.Config.GetString("database.password"),
			c.Config.GetString("database.host"),
			c.Config.GetInt("database.port"),
			c.Config.GetString("database.name"),
		)

		db, err = gorm.Open("mysql", uri)
	default:
		err = errors.New("Invalid or no driver provided")
	}

	// Check if we got nay errors while setting up the connection
	if err != nil {
		return nil, err
	}

	// Keep a reference to the connection so that we can access it later
	c.CurrentConnection = &db

	return &db, nil
}
857598
func NewConnection(host string, port string) *Connection {
	return &Connection{host, port, http.DefaultClient}
}