2025-01-22 16:38:46 +08:00
|
|
|
package pool
|
2025-01-21 16:35:44 +08:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
2025-08-15 16:25:48 +08:00
|
|
|
"fmt"
|
2025-01-21 16:35:44 +08:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
"modelRT/config"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
|
globalComponentChanSet = &ComponentChanSet{
|
|
|
|
|
AnchorChans: make([]chan config.AnchorParamConfig, 100),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-15 16:25:48 +08:00
|
|
|
var (
|
|
|
|
|
globalComponentChanMap sync.Map
|
|
|
|
|
globalComponentChanSet *ComponentChanSet
|
|
|
|
|
)
|
2025-01-21 16:35:44 +08:00
|
|
|
|
|
|
|
|
// ComponentChanSet defines component anchor real time data process channel set
|
|
|
|
|
type ComponentChanSet struct {
|
|
|
|
|
sync.RWMutex
|
|
|
|
|
AnchorChans []chan config.AnchorParamConfig
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-15 16:25:48 +08:00
|
|
|
func GetAnchorParamChan(ctx context.Context, componentUUID string) (chan config.AnchorParamConfig, error) {
|
|
|
|
|
paramChan, ok := globalComponentChanMap.Load(componentUUID)
|
|
|
|
|
if !ok {
|
|
|
|
|
return CreateNewAnchorParamChan(ctx, componentUUID), nil
|
2025-01-21 16:35:44 +08:00
|
|
|
}
|
2025-01-22 16:38:46 +08:00
|
|
|
|
2025-08-15 16:25:48 +08:00
|
|
|
anchorParamChan, ok := paramChan.(chan config.AnchorParamConfig)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, fmt.Errorf("conversion component anchor param chan type failed for componentUUID: %s", componentUUID)
|
2025-01-21 16:35:44 +08:00
|
|
|
}
|
2025-08-15 16:25:48 +08:00
|
|
|
return anchorParamChan, nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func CreateNewAnchorParamChan(ctx context.Context, componentUUID string) chan config.AnchorParamConfig {
|
|
|
|
|
anchorParamChan := make(chan config.AnchorParamConfig, 100)
|
|
|
|
|
globalComponentChanMap.Store(componentUUID, anchorParamChan)
|
|
|
|
|
return anchorParamChan
|
2025-01-21 16:35:44 +08:00
|
|
|
}
|