github.com/m3db/m3@v1.5.0/src/dbnode/network/server/tchannelthrift/node/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 node 22 23 import ( 24 "github.com/m3db/m3/src/dbnode/generated/thrift/rpc" 25 "github.com/m3db/m3/src/x/instrument" 26 27 "github.com/uber/tchannel-go" 28 "github.com/uber/tchannel-go/thrift" 29 ) 30 31 // NewTChanChannelFn creates a tchan channel. 32 type NewTChanChannelFn func( 33 service Service, 34 channelName string, 35 opts *tchannel.ChannelOptions, 36 ) (*tchannel.Channel, error) 37 38 func defaultTChanChannelFn( 39 service Service, 40 channelName string, 41 opts *tchannel.ChannelOptions, 42 ) (*tchannel.Channel, error) { 43 return tchannel.NewChannel(channelName, opts) 44 } 45 46 // NewTChanNodeServerFn creates a tchan node server. 47 type NewTChanNodeServerFn func( 48 service Service, 49 iOpts instrument.Options, 50 ) thrift.TChanServer 51 52 func defaultTChanNodeServerFn( 53 service Service, 54 _ instrument.Options, 55 ) thrift.TChanServer { 56 return rpc.NewTChanNodeServer(service) 57 } 58 59 // Options are thrift options. 60 type Options interface { 61 // SetChannelOptions sets a tchan channel options. 62 SetChannelOptions(value *tchannel.ChannelOptions) Options 63 64 // ChannelOptions returns the tchan channel options. 65 ChannelOptions() *tchannel.ChannelOptions 66 67 // SetTChanChannelFn sets a tchan node channel registration. 68 SetTChanChannelFn(value NewTChanChannelFn) Options 69 70 // TChanChannelFn returns a tchan node channel registration. 71 TChanChannelFn() NewTChanChannelFn 72 73 // SetTChanNodeServerFn sets a tchan node server builder. 74 SetTChanNodeServerFn(value NewTChanNodeServerFn) Options 75 76 // TChanNodeServerFn returns a tchan node server builder. 77 TChanNodeServerFn() NewTChanNodeServerFn 78 79 // SetInstrumentOptions sets the instrumentation options. 80 SetInstrumentOptions(value instrument.Options) Options 81 82 // InstrumentOptions returns the instrumentation options. 83 InstrumentOptions() instrument.Options 84 } 85 86 type options struct { 87 channelOptions *tchannel.ChannelOptions 88 instrumentOpts instrument.Options 89 tchanChannelFn NewTChanChannelFn 90 tchanNodeServerFn NewTChanNodeServerFn 91 } 92 93 // NewOptions creates a new options. 94 func NewOptions(chanOpts *tchannel.ChannelOptions) Options { 95 return &options{ 96 channelOptions: chanOpts, 97 tchanChannelFn: defaultTChanChannelFn, 98 tchanNodeServerFn: defaultTChanNodeServerFn, 99 } 100 } 101 func (o *options) SetChannelOptions(value *tchannel.ChannelOptions) Options { 102 opts := *o 103 opts.channelOptions = value 104 return &opts 105 } 106 107 func (o *options) ChannelOptions() *tchannel.ChannelOptions { 108 return o.channelOptions 109 } 110 111 func (o *options) SetTChanChannelFn(value NewTChanChannelFn) Options { 112 opts := *o 113 opts.tchanChannelFn = value 114 return &opts 115 } 116 117 func (o *options) TChanChannelFn() NewTChanChannelFn { 118 return o.tchanChannelFn 119 } 120 121 func (o *options) SetTChanNodeServerFn(value NewTChanNodeServerFn) Options { 122 opts := *o 123 opts.tchanNodeServerFn = value 124 return &opts 125 } 126 127 func (o *options) TChanNodeServerFn() NewTChanNodeServerFn { 128 return o.tchanNodeServerFn 129 } 130 131 func (o *options) SetInstrumentOptions(value instrument.Options) Options { 132 opts := *o 133 opts.instrumentOpts = value 134 return &opts 135 } 136 137 func (o *options) InstrumentOptions() instrument.Options { 138 return o.instrumentOpts 139 }