hot_plugin

package
v0.8.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 4, 2021 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const PluginSuffix = ".cbus.so"

PluginSuffix is the plugin file suffix.

Variables

View Source
var Version = semver.MustParse("0.0.1")

Version is the resolver version.

Functions

This section is empty.

Types

type FactoryCtorSet

type FactoryCtorSet = func(b bus.Bus) []controller.Factory

FactoryCtorSet is a list of factory constructors.

type HotPlugin

type HotPlugin interface {
	// UnloadHandler indicates plugin implements pre-plugin unload
	UnloadHandler

	// GetBinaryID returns the plugin binary ID.
	// Usually the go.mod package name.
	GetBinaryID() string
	// GetBinaryVersion returns the plugin binary version
	// Does not need to be semver (usually uses Go.mod versioning)
	GetBinaryVersion() string
	// NewHotResolver constructs the resolver and inits the plugin.
	// ctx is canceled when the plugin is about to be unloaded.
	NewHotResolver(ctx context.Context, bus bus.Bus) (HotResolver, error)
}

HotPlugin is the top-level type exposed in a Hot binary.

type HotResolver

type HotResolver interface {
	// FactoryResolver indicates this implements FactoryResolver.
	controller.FactoryResolver
	// UnloadHandler indicates resolver implements pre-plugin unload
	UnloadHandler
}

HotResolver resolves types included in a Hot binary.

type Resolver

type Resolver struct {
	// contains filtered or unexported fields
}

Resolver implements the controller resolver using a list of built-in controller implementations.

Does not require semantic versioning for binary versions.

func NewResolver

func NewResolver(
	ctx context.Context,
	bus bus.Bus,
	pluginBinaryID string,
	pluginBinaryVersion string,
	factories ...controller.Factory,
) *Resolver

NewResolver constructs a new resolver with a plugin binary.

func (*Resolver) GetConfigCtorByID

func (r *Resolver) GetConfigCtorByID(
	ctx context.Context, id string,
) (config.Constructor, error)

GetConfigCtorByID returns a config constructor matching the ID. If none found, return nil, nil

func (*Resolver) GetFactoryMatchingConfig

func (r *Resolver) GetFactoryMatchingConfig(
	ctx context.Context, c config.Config,
) (controller.Factory, error)

GetFactoryMatchingConfig returns the factory that matches the config. If no factory is found, return nil. If an unexpected error occurs, return it.

func (*Resolver) GetResolverID

func (r *Resolver) GetResolverID() string

GetResolverID returns the resolver identifier.

func (*Resolver) GetResolverVersion

func (r *Resolver) GetResolverVersion() semver.Version

GetResolverVersion returns the resolver version.

func (*Resolver) PrePluginUnload

func (r *Resolver) PrePluginUnload()

PrePluginUnload is called just before the plugin is unloaded.

type StaticPlugin

type StaticPlugin struct {
	// contains filtered or unexported fields
}

StaticPlugin contains a compiled set of controller factories.

func NewStaticPlugin

func NewStaticPlugin(
	binaryID string,
	binaryVersion string,
	factories FactoryCtorSet,
) *StaticPlugin

NewStaticPlugin constructs a new static plugin.

func (*StaticPlugin) GetBinaryID

func (e *StaticPlugin) GetBinaryID() string

GetBinaryID returns the plugin binary ID. Usually the go.mod package name.

func (*StaticPlugin) GetBinaryVersion

func (e *StaticPlugin) GetBinaryVersion() string

GetBinaryVersion returns the plugin binary version Does not need to be semver (usually uses Go.mod versioning)

func (*StaticPlugin) NewHotResolver

func (e *StaticPlugin) NewHotResolver(ctx context.Context, b bus.Bus) (HotResolver, error)

NewHotResolver constructs the resolver and inits the plugin. ctx is canceled when the plugin is about to be unloaded.

func (*StaticPlugin) PrePluginUnload

func (e *StaticPlugin) PrePluginUnload()

PrePluginUnload is called just before the plugin is unloaded.

type StaticPluginFactory

type StaticPluginFactory struct {
	controller.Factory
	// contains filtered or unexported fields
}

StaticPluginFactory wraps a factory with a pre-close hook.

func NewStaticPluginFactory

func NewStaticPluginFactory(
	ctx context.Context,
	ft controller.Factory,
	binaryID string,
	bus bus.Bus,
) *StaticPluginFactory

NewStaticPluginFactory constructs a new static plugin factory.

func (*StaticPluginFactory) Close

func (s *StaticPluginFactory) Close()

Close closes the static plugin factory.

func (*StaticPluginFactory) Construct

Construct constructs the associated controller given configuration.

func (*StaticPluginFactory) GetFactoryContext

func (s *StaticPluginFactory) GetFactoryContext() context.Context

GetContext returns a context that is canceled if the factory is unloaded.

type UnloadHandler

type UnloadHandler interface {
	// PrePluginUnload is called just before the plugin is unloaded.
	//
	// Unloading:
	// 1. context is canceled.
	// 2. PrePluginUnload called on all resolvers.
	// 3. PrePluginUnload called on plugin
	// 4. Unload of plugin
	PrePluginUnload()
}

UnloadHandler is called before the plugin is unloaded.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL