github.com/m3db/m3@v1.5.0/src/cluster/placement/watcher_options.go (about) 1 // Copyright (c) 2021 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 placement 22 23 import ( 24 "time" 25 26 "github.com/m3db/m3/src/cluster/kv" 27 "github.com/m3db/m3/src/x/instrument" 28 ) 29 30 var _ WatcherOptions = (*watcherOptions)(nil) // enforce interface compliance 31 32 const ( 33 defaultInitWatchTimeout = 10 * time.Second 34 ) 35 36 type watcherOptions struct { 37 instrumentOpts instrument.Options 38 stagedPlacementKey string 39 stagedPlacementStore kv.Store 40 initWatchTimeout time.Duration 41 onPlacementChangedFn OnPlacementChangedFn 42 } 43 44 // NewWatcherOptions create a new set of options. 45 func NewWatcherOptions() WatcherOptions { 46 return &watcherOptions{ 47 instrumentOpts: instrument.NewOptions(), 48 initWatchTimeout: defaultInitWatchTimeout, 49 } 50 } 51 52 func (o *watcherOptions) SetInstrumentOptions(value instrument.Options) WatcherOptions { 53 opts := *o 54 opts.instrumentOpts = value 55 return &opts 56 } 57 58 func (o *watcherOptions) InstrumentOptions() instrument.Options { 59 return o.instrumentOpts 60 } 61 62 func (o *watcherOptions) SetStagedPlacementKey(value string) WatcherOptions { 63 opts := *o 64 opts.stagedPlacementKey = value 65 return &opts 66 } 67 68 func (o *watcherOptions) StagedPlacementKey() string { 69 return o.stagedPlacementKey 70 } 71 72 func (o *watcherOptions) SetStagedPlacementStore(value kv.Store) WatcherOptions { 73 opts := *o 74 opts.stagedPlacementStore = value 75 return &opts 76 } 77 78 func (o *watcherOptions) StagedPlacementStore() kv.Store { 79 return o.stagedPlacementStore 80 } 81 82 func (o *watcherOptions) SetInitWatchTimeout(value time.Duration) WatcherOptions { 83 opts := *o 84 opts.initWatchTimeout = value 85 return &opts 86 } 87 88 func (o *watcherOptions) InitWatchTimeout() time.Duration { 89 return o.initWatchTimeout 90 } 91 92 func (o *watcherOptions) SetOnPlacementChangedFn(value OnPlacementChangedFn) WatcherOptions { 93 opts := *o 94 opts.onPlacementChangedFn = value 95 return &opts 96 } 97 98 func (o *watcherOptions) OnPlacementChangedFn() OnPlacementChangedFn { 99 return o.onPlacementChangedFn 100 }