github.com/voedger/voedger@v0.0.0-20240520144910-273e84102129/pkg/iprocbusmem/provide.go (about)

     1  /*
     2   * Copyright (c) 2021-present unTill Pro, Ltd.
     3   */
     4  
     5  package iprocbusmem
     6  
     7  import (
     8  	"github.com/voedger/voedger/pkg/iprocbus"
     9  )
    10  
    11  type ChannelGroup struct {
    12  	NumChannels       int
    13  	ChannelBufferSize int
    14  }
    15  
    16  // Usage:
    17  //   - Create IProcBus
    18  //   - CommandProcessorsGroup: group0:{NumChannels:10, ChannelBufferSize: 10}
    19  //   - One command processor - one channel
    20  //   - QueryProcessorsGroup: group1:{NumChannels:1, ChannelBufferSize: 0}
    21  //   - Wire IProcBus.ServiceChannel(...) to services
    22  //   - Use Submit() to deliver messages to services
    23  func Provide(groups []ChannelGroup) (bus iprocbus.IProcBus) {
    24  	res := &implIProcBus{make([][]iprocbus.ServiceChannel, len(groups))}
    25  	for i, group := range groups {
    26  		res.chans[i] = make([]iprocbus.ServiceChannel, group.NumChannels)
    27  		for j := 0; j < group.NumChannels; j++ {
    28  			res.chans[i][j] = make(iprocbus.ServiceChannel, group.ChannelBufferSize)
    29  		}
    30  	}
    31  	return res
    32  }