Exemple #1
0
func (ap *availablePlugins) getOrCreatePool(key string) (strategy.Pool, error) {
	var err error
	pool, ok := ap.table[key]
	if ok {
		return pool, nil
	}
	pool, err = strategy.NewPool(key)
	if err != nil {
		return nil, err
	}
	ap.table[key] = pool
	return pool, nil
}
Exemple #2
0
func (ap *availablePlugins) insert(pl *availablePlugin) error {
	if pl.pluginType != plugin.CollectorPluginType && pl.pluginType != plugin.ProcessorPluginType && pl.pluginType != plugin.PublisherPluginType {
		return strategy.ErrBadType
	}

	ap.Lock()
	defer ap.Unlock()

	key := fmt.Sprintf("%s:%s:%d", pl.TypeName(), pl.name, pl.version)
	_, exists := ap.table[key]
	if !exists {
		p, err := strategy.NewPool(key, pl)
		if err != nil {
			return serror.New(ErrBadKey, map[string]interface{}{
				"key": key,
			})
		}
		ap.table[key] = p
		return nil
	}
	ap.table[key].Insert(pl)
	return nil
}