github.com/m3db/m3@v1.5.0/src/aggregator/server/rawtcp/options.go (about) 1 // Copyright (c) 2016 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 rawtcp 22 23 import ( 24 "github.com/m3db/m3/src/metrics/encoding/protobuf" 25 "github.com/m3db/m3/src/x/clock" 26 "github.com/m3db/m3/src/x/instrument" 27 xio "github.com/m3db/m3/src/x/io" 28 "github.com/m3db/m3/src/x/server" 29 ) 30 31 const ( 32 // A default limit value of 0 means error log rate limiting is disabled. 33 defaultErrorLogLimitPerSecond = 0 34 35 // The default read buffer size for raw TCP connections. 36 defaultReadBufferSize = 65536 37 ) 38 39 // Options provide a set of server options. 40 type Options interface { 41 // SetClockOptions sets the clock options. 42 SetClockOptions(value clock.Options) Options 43 44 // ClockOptions returns the clock options. 45 ClockOptions() clock.Options 46 47 // SetInstrumentOptions sets the instrument options. 48 SetInstrumentOptions(value instrument.Options) Options 49 50 // InstrumentOptions returns the instrument options. 51 InstrumentOptions() instrument.Options 52 53 // SetServerOptions sets the server options. 54 SetServerOptions(value server.Options) Options 55 56 // ServerOptiosn returns the server options. 57 ServerOptions() server.Options 58 59 // SetProtobufUnaggregatedIteratorOptions sets the protobuf unaggregated iterator options. 60 SetProtobufUnaggregatedIteratorOptions(value protobuf.UnaggregatedOptions) Options 61 62 // ProtobufUnaggregatedIteratorOptions returns the protobuf unaggregated iterator options. 63 ProtobufUnaggregatedIteratorOptions() protobuf.UnaggregatedOptions 64 65 // SetReadBufferSize sets the read buffer size. 66 SetReadBufferSize(value int) Options 67 68 // ReadBufferSize returns the read buffer size. 69 ReadBufferSize() int 70 71 // SetErrorLogLimitPerSecond sets the error log limit per second. 72 SetErrorLogLimitPerSecond(value int64) Options 73 74 // ErrorLogLimitPerSecond returns the error log limit per second. 75 ErrorLogLimitPerSecond() int64 76 77 // SetRWOptions sets RW options. 78 SetRWOptions(value xio.Options) Options 79 80 // RWOptions returns the RW options. 81 RWOptions() xio.Options 82 } 83 84 type options struct { 85 clockOpts clock.Options 86 instrumentOpts instrument.Options 87 serverOpts server.Options 88 protobufItOpts protobuf.UnaggregatedOptions 89 readBufferSize int 90 errLogLimitPerSecond int64 91 rwOpts xio.Options 92 } 93 94 // NewOptions creates a new set of server options. 95 func NewOptions() Options { 96 return &options{ 97 clockOpts: clock.NewOptions(), 98 instrumentOpts: instrument.NewOptions(), 99 serverOpts: server.NewOptions(), 100 protobufItOpts: protobuf.NewUnaggregatedOptions(), 101 readBufferSize: defaultReadBufferSize, 102 errLogLimitPerSecond: defaultErrorLogLimitPerSecond, 103 rwOpts: xio.NewOptions(), 104 } 105 } 106 107 func (o *options) SetClockOptions(value clock.Options) Options { 108 opts := *o 109 opts.clockOpts = value 110 return &opts 111 } 112 113 func (o *options) ClockOptions() clock.Options { 114 return o.clockOpts 115 } 116 117 func (o *options) SetInstrumentOptions(value instrument.Options) Options { 118 opts := *o 119 opts.instrumentOpts = value 120 return &opts 121 } 122 123 func (o *options) InstrumentOptions() instrument.Options { 124 return o.instrumentOpts 125 } 126 127 func (o *options) SetServerOptions(value server.Options) Options { 128 opts := *o 129 opts.serverOpts = value 130 return &opts 131 } 132 133 func (o *options) ServerOptions() server.Options { 134 return o.serverOpts 135 } 136 137 func (o *options) SetProtobufUnaggregatedIteratorOptions(value protobuf.UnaggregatedOptions) Options { 138 opts := *o 139 opts.protobufItOpts = value 140 return &opts 141 } 142 143 func (o *options) ProtobufUnaggregatedIteratorOptions() protobuf.UnaggregatedOptions { 144 return o.protobufItOpts 145 } 146 147 func (o *options) SetReadBufferSize(value int) Options { 148 opts := *o 149 opts.readBufferSize = value 150 return &opts 151 } 152 153 func (o *options) ReadBufferSize() int { 154 return o.readBufferSize 155 } 156 157 func (o *options) SetErrorLogLimitPerSecond(value int64) Options { 158 opts := *o 159 opts.errLogLimitPerSecond = value 160 return &opts 161 } 162 163 func (o *options) ErrorLogLimitPerSecond() int64 { 164 return o.errLogLimitPerSecond 165 } 166 167 func (o *options) SetRWOptions(value xio.Options) Options { 168 opts := *o 169 opts.rwOpts = value 170 return &opts 171 } 172 173 func (o *options) RWOptions() xio.Options { 174 return o.rwOpts 175 }