github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/ibus/interface.go (about) 1 /* 2 * Copyright (c) 2022-present unTill Pro, Ltd. 3 * @author Maxim Geraskin 4 */ 5 6 package ibus 7 8 import ( 9 "context" 10 "time" 11 ) 12 13 type CLIParams struct { 14 MaxNumOfConcurrentRequests int 15 ReadWriteTimeout time.Duration 16 } 17 18 type IBus interface { 19 // panics if receivers already exists 20 // NOTE: EchoReceiver can be used for testing purposes 21 RegisterReceiver(owner string, app string, partition int, part string, r Receiver, numOfProcessors int, bufferSize int) 22 23 // ok is false if receivers were not found 24 UnregisterReceiver(owner string, app string, partition int, part string) (ok bool) 25 26 // If appropriate receivers do not exist then "BadRequestSender" should be returned 27 // "BadRequestSender" returns an StatusBadRequest(400) error for every request 28 QuerySender(owner string, app string, partition int, part string) (sender ISender, ok bool) 29 30 GetMetrics() (metrics Metrics) 31 } 32 33 type Metrics struct { 34 MaxNumOfConcurrentRequests int 35 NumOfConcurrentRequests int 36 } 37 38 type SectionsHandlerType func(section interface{}) 39 40 type SectionsWriterType interface { 41 // Result is false if client cancels the request or receiver is being unregistered 42 Write(section interface{}) bool 43 } 44 45 type ISender interface { 46 // err.Error() must have QName format: 47 // var ErrTimeoutExpired = errors.New("ibus.ErrTimeoutExpired") 48 // NullHandler can be used as a reader 49 Send(ctx context.Context, request interface{}, sectionsHandler SectionsHandlerType) (response interface{}, status Status, err error) 50 } 51 52 // Receiver must check context 53 // err.Error() must have QName format 54 type Receiver func(processorsCtx context.Context, request interface{}, sectionsWriter SectionsWriterType) (response interface{}, status Status, err error) 55 56 type Status struct { 57 // Ref. https://go.dev/src/net/http/status.go 58 // StatusBadRequest(400) if server got the request but could not process it 59 // StatusGatewayTimeout(504) if timeout expired 60 HTTPStatus int 61 ErrorMessage string 62 ErrorData string 63 }