forked from hyperledger/fabric-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
opts.go
executable file
·64 lines (52 loc) · 1.66 KB
/
opts.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package dispatcher
import (
"time"
"github.com/hyperledger/fabric-sdk-go/pkg/common/options"
)
type params struct {
eventConsumerBufferSize uint
eventConsumerTimeout time.Duration
}
func defaultParams() *params {
return ¶ms{
eventConsumerBufferSize: 100,
eventConsumerTimeout: 500 * time.Millisecond,
}
}
// WithEventConsumerBufferSize sets the size of the registered consumer's event channel.
func WithEventConsumerBufferSize(value uint) options.Opt {
return func(p options.Params) {
if setter, ok := p.(eventConsumerBufferSizeSetter); ok {
setter.SetEventConsumerBufferSize(value)
}
}
}
// WithEventConsumerTimeout is the timeout when sending events to a registered consumer.
// If < 0, if buffer full, unblocks immediately and does not send.
// If 0, if buffer full, will block and guarantee the event will be sent out.
// If > 0, if buffer full, blocks util timeout.
func WithEventConsumerTimeout(value time.Duration) options.Opt {
return func(p options.Params) {
if setter, ok := p.(eventEventConsumerTimeoutSetter); ok {
setter.SetEventConsumerTimeout(value)
}
}
}
type eventConsumerBufferSizeSetter interface {
SetEventConsumerBufferSize(value uint)
}
type eventEventConsumerTimeoutSetter interface {
SetEventConsumerTimeout(value time.Duration)
}
func (p *params) SetEventConsumerBufferSize(value uint) {
logger.Debugf("EventConsumerBufferSize: %d", value)
p.eventConsumerBufferSize = value
}
func (p *params) SetEventConsumerTimeout(value time.Duration) {
logger.Debugf("EventConsumerTimeout: %s", value)
p.eventConsumerTimeout = value
}