github.com/m3db/m3@v1.5.1-0.20231129193456-75a402aa583b/src/aggregator/server/m3msg/options.go (about) 1 // Copyright (c) 2020 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 m3msg 22 23 import ( 24 "errors" 25 26 "github.com/m3db/m3/src/msg/consumer" 27 "github.com/m3db/m3/src/x/instrument" 28 xserver "github.com/m3db/m3/src/x/server" 29 ) 30 31 var ( 32 errNoInstrumentOptions = errors.New("no instrument options") 33 errNoServerOptions = errors.New("no server options") 34 errNoConsumerOptions = errors.New("no consumer options") 35 ) 36 37 // Options is a set of M3Msg options. 38 type Options interface { 39 // Validate validates the options. 40 Validate() error 41 42 // SetInstrumentOptions sets the instrument options. 43 SetInstrumentOptions(value instrument.Options) Options 44 45 // InstrumentOptions returns the instrument options. 46 InstrumentOptions() instrument.Options 47 48 // SetServerOptions sets the server options. 49 SetServerOptions(value xserver.Options) Options 50 51 // ServerOptions returns the server options. 52 ServerOptions() xserver.Options 53 54 // SetConsumerOptions sets the consumer options. 55 SetConsumerOptions(value consumer.Options) Options 56 57 // ConsumerOptions returns the consumer options. 58 ConsumerOptions() consumer.Options 59 } 60 61 type options struct { 62 instrumentOpts instrument.Options 63 serverOpts xserver.Options 64 consumerOpts consumer.Options 65 } 66 67 // NewOptions returns a set of M3Msg options. 68 func NewOptions() Options { 69 return &options{} 70 } 71 72 func (o *options) Validate() error { 73 if o.instrumentOpts == nil { 74 return errNoInstrumentOptions 75 } 76 if o.serverOpts == nil { 77 return errNoServerOptions 78 } 79 if o.consumerOpts == nil { 80 return errNoConsumerOptions 81 } 82 return nil 83 } 84 85 func (o *options) SetInstrumentOptions(value instrument.Options) Options { 86 opts := *o 87 opts.instrumentOpts = value 88 return &opts 89 } 90 91 func (o *options) InstrumentOptions() instrument.Options { 92 return o.instrumentOpts 93 } 94 95 func (o *options) SetServerOptions(value xserver.Options) Options { 96 opts := *o 97 opts.serverOpts = value 98 return &opts 99 } 100 101 func (o *options) ServerOptions() xserver.Options { 102 return o.serverOpts 103 } 104 105 func (o *options) SetConsumerOptions(value consumer.Options) Options { 106 opts := *o 107 opts.consumerOpts = value 108 return &opts 109 } 110 111 func (o *options) ConsumerOptions() consumer.Options { 112 return o.consumerOpts 113 }