github.com/cyverse/go-irodsclient@v0.13.2/irods/session/config.go (about)

     1  package session
     2  
     3  import (
     4  	"time"
     5  )
     6  
     7  const (
     8  	// IRODSSessionConnectionErrorTimeoutDefault is a default value of connection error timeout
     9  	IRODSSessionConnectionErrorTimeoutDefault = 1 * time.Minute
    10  	// IRODSSessionConnectionInitNumberDefault is a default value of connection init number
    11  	IRODSSessionConnectionInitNumberDefault = 0
    12  	// IRODSSessionConnectionMaxMin is a minimum value of connection max
    13  	IRODSSessionConnectionMaxMin = 5
    14  	// IRODSSessionConnectionMaxDefault is a default value of connection max
    15  	IRODSSessionConnectionMaxDefault = 10
    16  	// IRODSSessionConnectionLifespanDefault is a default value of connection lifespan
    17  	IRODSSessionConnectionLifespanDefault = 1 * time.Hour
    18  	// IRODSSessionTimeoutDefault is a default value of timeout
    19  	IRODSSessionTimeoutDefault = 5 * time.Minute
    20  	// IRODSSessionTCPBufferSizeDefault is a default value of tcp buffer size
    21  	IRODSSessionTCPBufferSizeDefault = 4 * 1024 * 1024
    22  )
    23  
    24  // IRODSSessionConfig is for session configuration
    25  type IRODSSessionConfig struct {
    26  	ApplicationName        string
    27  	ConnectionErrorTimeout time.Duration
    28  	ConnectionLifespan     time.Duration
    29  	OperationTimeout       time.Duration
    30  	ConnectionIdleTimeout  time.Duration
    31  	ConnectionMax          int
    32  	ConnectionInitNumber   int
    33  	ConnectionMaxIdle      int
    34  	TcpBufferSize          int
    35  	StartNewTransaction    bool
    36  }
    37  
    38  // NewIRODSSessionConfig create a IRODSSessionConfig
    39  func NewIRODSSessionConfig(applicationName string, connectionErrorTimeout time.Duration, connectionInitNumber int, connectionLifespan time.Duration, operationTimeout time.Duration, idleTimeout time.Duration, connectionMax int, tcpBufferSize int, startNewTransaction bool) *IRODSSessionConfig {
    40  	if connectionMax < IRODSSessionConnectionMaxMin {
    41  		connectionMax = IRODSSessionConnectionMaxMin
    42  	}
    43  
    44  	return &IRODSSessionConfig{
    45  		ApplicationName:        applicationName,
    46  		ConnectionErrorTimeout: connectionErrorTimeout,
    47  		ConnectionLifespan:     connectionLifespan,
    48  		OperationTimeout:       operationTimeout,
    49  		ConnectionIdleTimeout:  idleTimeout,
    50  		ConnectionMax:          connectionMax,
    51  		ConnectionInitNumber:   connectionInitNumber,
    52  		ConnectionMaxIdle:      IRODSSessionConnectionMaxMin,
    53  		TcpBufferSize:          tcpBufferSize,
    54  		StartNewTransaction:    startNewTransaction,
    55  	}
    56  }
    57  
    58  // NewIRODSSessionConfigWithDefault create a IRODSSessionConfig with a default settings
    59  func NewIRODSSessionConfigWithDefault(applicationName string) *IRODSSessionConfig {
    60  	return &IRODSSessionConfig{
    61  		ApplicationName:        applicationName,
    62  		ConnectionErrorTimeout: IRODSSessionConnectionErrorTimeoutDefault,
    63  		ConnectionLifespan:     IRODSSessionConnectionLifespanDefault,
    64  		OperationTimeout:       IRODSSessionTimeoutDefault,
    65  		ConnectionIdleTimeout:  IRODSSessionTimeoutDefault,
    66  		ConnectionMax:          IRODSSessionConnectionMaxDefault,
    67  		ConnectionInitNumber:   IRODSSessionConnectionInitNumberDefault,
    68  		ConnectionMaxIdle:      IRODSSessionConnectionMaxMin,
    69  		TcpBufferSize:          IRODSSessionTCPBufferSizeDefault,
    70  		StartNewTransaction:    true,
    71  	}
    72  }