github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/msg/consumer/options.go (about) 1 // Copyright (c) 2018 Uber Technologies, Inc. 2 // 3 // Permission is hereby granted, free of charge, to any person obtaining a copy 4 // of this software and associated documentation files (the "Software"), to deal 5 // in the Software without restriction, including without limitation the rights 6 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 // copies of the Software, and to permit persons to whom the Software is 8 // furnished to do so, subject to the following conditions: 9 // 10 // The above copyright notice and this permission notice shall be included in 11 // all copies or substantial portions of the Software. 12 // 13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 // THE SOFTWARE. 20 21 package consumer 22 23 import ( 24 "time" 25 26 "github.com/m3db/m3/src/msg/protocol/proto" 27 "github.com/m3db/m3/src/x/instrument" 28 xio "github.com/m3db/m3/src/x/io" 29 "github.com/m3db/m3/src/x/pool" 30 ) 31 32 var ( 33 defaultAckBufferSize = 1048576 34 defaultAckFlushInterval = 200 * time.Millisecond 35 defaultConnectionBufferSize = 1048576 36 defaultWriteTimeout = 5 * time.Second 37 ) 38 39 type options struct { 40 encOptions proto.Options 41 decOptions proto.Options 42 messagePoolOpts MessagePoolOptions 43 ackFlushInterval time.Duration 44 ackBufferSize int 45 writeBufferSize int 46 readBufferSize int 47 writeTimeout time.Duration 48 iOpts instrument.Options 49 rwOpts xio.Options 50 } 51 52 // NewOptions creates a new options. 53 func NewOptions() Options { 54 return &options{ 55 encOptions: proto.NewOptions(), 56 decOptions: proto.NewOptions(), 57 messagePoolOpts: MessagePoolOptions{PoolOptions: pool.NewObjectPoolOptions()}, 58 ackFlushInterval: defaultAckFlushInterval, 59 ackBufferSize: defaultAckBufferSize, 60 writeBufferSize: defaultConnectionBufferSize, 61 readBufferSize: defaultConnectionBufferSize, 62 writeTimeout: defaultWriteTimeout, 63 iOpts: instrument.NewOptions(), 64 rwOpts: xio.NewOptions(), 65 } 66 } 67 68 func (opts *options) EncoderOptions() proto.Options { 69 return opts.encOptions 70 } 71 72 func (opts *options) SetEncoderOptions(value proto.Options) Options { 73 o := *opts 74 o.encOptions = value 75 return &o 76 } 77 78 func (opts *options) DecoderOptions() proto.Options { 79 return opts.decOptions 80 } 81 82 func (opts *options) SetDecoderOptions(value proto.Options) Options { 83 o := *opts 84 o.decOptions = value 85 return &o 86 } 87 88 func (opts *options) MessagePoolOptions() MessagePoolOptions { 89 return opts.messagePoolOpts 90 } 91 92 func (opts *options) SetMessagePoolOptions(value MessagePoolOptions) Options { 93 o := *opts 94 o.messagePoolOpts = value 95 return &o 96 } 97 98 func (opts *options) AckFlushInterval() time.Duration { 99 return opts.ackFlushInterval 100 } 101 102 func (opts *options) SetAckFlushInterval(value time.Duration) Options { 103 o := *opts 104 o.ackFlushInterval = value 105 return &o 106 } 107 108 func (opts *options) AckBufferSize() int { 109 return opts.ackBufferSize 110 } 111 112 func (opts *options) SetAckBufferSize(value int) Options { 113 o := *opts 114 o.ackBufferSize = value 115 return &o 116 } 117 118 func (opts *options) ConnectionWriteBufferSize() int { 119 return opts.writeBufferSize 120 } 121 122 func (opts *options) SetConnectionWriteBufferSize(value int) Options { 123 o := *opts 124 o.writeBufferSize = value 125 return &o 126 } 127 128 func (opts *options) ConnectionReadBufferSize() int { 129 return opts.readBufferSize 130 } 131 132 func (opts *options) SetConnectionReadBufferSize(value int) Options { 133 o := *opts 134 o.readBufferSize = value 135 return &o 136 } 137 138 func (opts *options) ConnectionWriteTimeout() time.Duration { 139 return opts.writeTimeout 140 } 141 142 func (opts *options) SetConnectionWriteTimeout(value time.Duration) Options { 143 o := *opts 144 o.writeTimeout = value 145 return &o 146 } 147 148 func (opts *options) InstrumentOptions() instrument.Options { 149 return opts.iOpts 150 } 151 152 func (opts *options) SetInstrumentOptions(value instrument.Options) Options { 153 o := *opts 154 o.iOpts = value 155 return &o 156 } 157 158 func (opts *options) SetRWOptions(value xio.Options) Options { 159 o := *opts 160 o.rwOpts = value 161 return &o 162 } 163 164 func (opts *options) RWOptions() xio.Options { 165 return opts.rwOpts 166 }