github.com/m3db/m3@v1.5.0/src/x/watch/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 watch 22 23 import ( 24 "time" 25 26 "github.com/m3db/m3/src/x/instrument" 27 ) 28 29 const ( 30 defaultInitWatchTimeout = 10 * time.Second 31 ) 32 33 // Options provide a set of value options. 34 type Options interface { 35 // SetInstrumentOptions sets the instrument options. 36 SetInstrumentOptions(value instrument.Options) Options 37 38 // InstrumentOptions returns the instrument options. 39 InstrumentOptions() instrument.Options 40 41 // SetInitWatchTimeout sets the initial watch timeout. 42 SetInitWatchTimeout(value time.Duration) Options 43 44 // InitWatchTimeout returns the initial watch timeout. 45 InitWatchTimeout() time.Duration 46 47 // SetNewUpdatableFn sets the new updatable function. 48 SetNewUpdatableFn(value NewUpdatableFn) Options 49 50 // NewUpdatableFn returns the new updatable function. 51 NewUpdatableFn() NewUpdatableFn 52 53 // SetGetUpdateFn sets the get function. 54 SetGetUpdateFn(value GetUpdateFn) Options 55 56 // GetUpdateFn returns the get function. 57 GetUpdateFn() GetUpdateFn 58 59 // SetProcessFn sets the process function. 60 SetProcessFn(value ProcessFn) Options 61 62 // ProcessFn returns the process function. 63 ProcessFn() ProcessFn 64 65 // Key returns the key for the watch. 66 Key() string 67 68 // SetKey sets the key for the watch. 69 SetKey(key string) Options 70 71 // InterruptedCh returns the interrupted channel. 72 InterruptedCh() <-chan struct{} 73 74 // SetInterruptedCh sets the interrupted channel. 75 SetInterruptedCh(value <-chan struct{}) Options 76 } 77 78 type options struct { 79 instrumentOpts instrument.Options 80 initWatchTimeout time.Duration 81 newUpdatableFn NewUpdatableFn 82 getUpdateFn GetUpdateFn 83 processFn ProcessFn 84 key string 85 interruptedCh <-chan struct{} 86 } 87 88 // NewOptions creates a new set of options. 89 func NewOptions() Options { 90 return &options{ 91 instrumentOpts: instrument.NewOptions(), 92 initWatchTimeout: defaultInitWatchTimeout, 93 } 94 } 95 96 func (o *options) SetInstrumentOptions(value instrument.Options) Options { 97 opts := *o 98 opts.instrumentOpts = value 99 return &opts 100 } 101 102 func (o *options) InstrumentOptions() instrument.Options { 103 return o.instrumentOpts 104 } 105 106 func (o *options) SetInitWatchTimeout(value time.Duration) Options { 107 opts := *o 108 opts.initWatchTimeout = value 109 return &opts 110 } 111 112 func (o *options) InitWatchTimeout() time.Duration { 113 return o.initWatchTimeout 114 } 115 116 func (o *options) SetNewUpdatableFn(value NewUpdatableFn) Options { 117 opts := *o 118 opts.newUpdatableFn = value 119 return &opts 120 } 121 122 func (o *options) NewUpdatableFn() NewUpdatableFn { 123 return o.newUpdatableFn 124 } 125 126 func (o *options) SetGetUpdateFn(value GetUpdateFn) Options { 127 opts := *o 128 opts.getUpdateFn = value 129 return &opts 130 } 131 132 func (o *options) GetUpdateFn() GetUpdateFn { 133 return o.getUpdateFn 134 } 135 136 func (o *options) SetProcessFn(value ProcessFn) Options { 137 opts := *o 138 opts.processFn = value 139 return &opts 140 } 141 142 func (o *options) ProcessFn() ProcessFn { 143 return o.processFn 144 } 145 146 func (o *options) Key() string { 147 return o.key 148 } 149 150 func (o *options) SetKey(key string) Options { 151 opts := *o 152 opts.key = key 153 return &opts 154 } 155 156 func (o *options) InterruptedCh() <-chan struct{} { 157 return o.interruptedCh 158 } 159 160 func (o *options) SetInterruptedCh(ch <-chan struct{}) Options { 161 o.interruptedCh = ch 162 return o 163 }