github.com/cloudwego/kitex@v0.9.0/pkg/remote/connpool.go (about)

     1  /*
     2   * Copyright 2021 CloudWeGo Authors
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  package remote
    18  
    19  import (
    20  	"context"
    21  	"net"
    22  	"time"
    23  )
    24  
    25  // ConnOption contains configurations for connection pool.
    26  type ConnOption struct {
    27  	Dialer         Dialer
    28  	ConnectTimeout time.Duration
    29  }
    30  
    31  // ConnPool is used to get connections.
    32  type ConnPool interface {
    33  	// Get returns a connection to the given address.
    34  	Get(ctx context.Context, network, address string, opt ConnOption) (net.Conn, error)
    35  
    36  	// Put puts the connection back to pool.
    37  	// Note that the Close method of conn may already be invoked.
    38  	Put(conn net.Conn) error
    39  
    40  	// Discard discards the connection rather than putting it to the pool.
    41  	Discard(conn net.Conn) error
    42  
    43  	// Close is to release resource of ConnPool, it is executed when client is closed.
    44  	Close() error
    45  }
    46  
    47  // LongConnPool supports Clean connections to a desired address.
    48  type LongConnPool interface {
    49  	ConnPool
    50  
    51  	// Clean the state maintained in the poor for this address
    52  	Clean(network, address string)
    53  }
    54  
    55  // ConnPoolReporter is used to enable reporter.
    56  type ConnPoolReporter interface {
    57  	EnableReporter()
    58  }
    59  
    60  // RawConn is used to get the raw connection.
    61  type RawConn interface {
    62  	RawConn() net.Conn
    63  }
    64  
    65  // IsActive is used to check if the connection is active.
    66  type IsActive interface {
    67  	IsActive() bool
    68  }